diff options
author | Vicent Martà <vicent@github.com> | 2013-11-04 20:09:58 +0400 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2013-11-04 20:09:58 +0400 |
commit | 44acdd1f9a7bb97b5a5fe724065fd86c63696aed (patch) | |
tree | 26af60abf7d2f56461dc6b4e1c541e676d615fde /src/checkout.c | |
parent | 5a0b88036f612ce7e9cdc24517c9b9eb6100a3d7 (diff) | |
parent | 7b3959b22784d63dd6f21bc250602b886d726294 (diff) |
Merge pull request #1937 from scunz/checkout_assert
Don't assert in git_checkout_tree
Diffstat (limited to 'src/checkout.c')
-rw-r--r-- | src/checkout.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/checkout.c b/src/checkout.c index dce9afdf4..a4f326637 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -2018,7 +2018,7 @@ cleanup: int git_checkout_index( git_repository *repo, git_index *index, - git_checkout_opts *opts) + const git_checkout_opts *opts) { int error; git_iterator *index_i; @@ -2053,7 +2053,7 @@ int git_checkout_index( int git_checkout_tree( git_repository *repo, const git_object *treeish, - git_checkout_opts *opts) + const git_checkout_opts *opts) { int error; git_tree *tree = NULL; @@ -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))) @@ -2092,18 +2103,6 @@ int git_checkout_head( git_repository *repo, const git_checkout_opts *opts) { - int error; - git_tree *head = NULL; - git_iterator *head_i = NULL; - assert(repo); - - if (!(error = checkout_lookup_head_tree(&head, repo)) && - !(error = git_iterator_for_tree(&head_i, head, 0, NULL, NULL))) - error = git_checkout_iterator(head_i, opts); - - git_iterator_free(head_i); - git_tree_free(head); - - return error; + return git_checkout_tree(repo, NULL, opts); } |