summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/checkout.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 20b964b54..d818a44bf 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -2073,10 +2073,21 @@ int git_checkout_tree(
if (!repo)
repo = git_object_owner(treeish);
- if (git_object_peel((git_object **)&tree, treeish, GIT_OBJ_TREE) < 0) {
- giterr_set(
- GITERR_CHECKOUT, "Provided object cannot be peeled to a tree");
- return -1;
+ if (treeish) {
+ if (git_object_peel((git_object **)&tree, treeish, GIT_OBJ_TREE) < 0) {
+ giterr_set(
+ 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)))