mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 13:04:42 +00:00
Checkout: Don't assert if treeish is NULL
In git_checkout_tree, the first check tests if either repo or treeish is NULL and says that eithor of them has to have a valid value. But there is no code to handle the treeish == NULL case. So, do something meaningful in that case: use HEAD instead.
This commit is contained in:
parent
10749f6ca2
commit
352214416c
@ -280,7 +280,7 @@ GIT_EXTERN(int) git_checkout_index(
|
|||||||
*
|
*
|
||||||
* @param repo repository to check out (must be non-bare)
|
* @param repo repository to check out (must be non-bare)
|
||||||
* @param treeish a commit, tag or tree which content will be used to update
|
* @param treeish a commit, tag or tree which content will be used to update
|
||||||
* the working directory
|
* the working directory (or NULL to use HEAD)
|
||||||
* @param opts specifies checkout options (may be NULL)
|
* @param opts specifies checkout options (may be NULL)
|
||||||
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
|
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
|
||||||
* about the error)
|
* about the error)
|
||||||
|
@ -2073,10 +2073,21 @@ int git_checkout_tree(
|
|||||||
if (!repo)
|
if (!repo)
|
||||||
repo = git_object_owner(treeish);
|
repo = git_object_owner(treeish);
|
||||||
|
|
||||||
if (git_object_peel((git_object **)&tree, treeish, GIT_OBJ_TREE) < 0) {
|
if (treeish) {
|
||||||
giterr_set(
|
if (git_object_peel((git_object **)&tree, treeish, GIT_OBJ_TREE) < 0) {
|
||||||
GITERR_CHECKOUT, "Provided object cannot be peeled to a tree");
|
giterr_set(
|
||||||
return -1;
|
GITERR_CHECKOUT, "Provided object cannot be peeled to a tree");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ((error = checkout_lookup_head_tree(&tree, repo)) < 0) {
|
||||||
|
if (error != GIT_EUNBORNBRANCH)
|
||||||
|
giterr_set(
|
||||||
|
GITERR_CHECKOUT,
|
||||||
|
"HEAD could not be peeled to a tree and no treeish given");
|
||||||
|
return error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(error = git_iterator_for_tree(&tree_i, tree, 0, NULL, NULL)))
|
if (!(error = git_iterator_for_tree(&tree_i, tree, 0, NULL, NULL)))
|
||||||
|
Loading…
Reference in New Issue
Block a user