Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a15e8d

Browse files
committed
Loosen ensure_not_bare rules in checkout
With the new target directory option to checkout, the non-bareness of the repository should be checked much later in the parameter validation process - actually that check was already in place, but I was doing it redundantly in the checkout APIs. This removes the now unnecessary early check for bare repos. It also adds some other parameter validation and makes it so that implied parameters can actually be passed as NULL (i.e. if you pass a git_index, you don't have to pass the git_repository - we can get it from index).
1 parent 9094ae5 commit 6a15e8d

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/checkout.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,19 @@ int git_checkout_index(
13691369
int error;
13701370
git_iterator *index_i;
13711371

1372-
if ((error = git_repository__ensure_not_bare(repo, "checkout index")) < 0)
1373-
return error;
1372+
if (!index && !repo) {
1373+
giterr_set(GITERR_CHECKOUT,
1374+
"Must provide either repository or index to checkout");
1375+
return -1;
1376+
}
1377+
if (index && repo && git_index_owner(index) != repo) {
1378+
giterr_set(GITERR_CHECKOUT,
1379+
"Index to checkout does not match repository");
1380+
return -1;
1381+
}
1382+
1383+
if (!repo)
1384+
repo = git_index_owner(index);
13741385

13751386
if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0)
13761387
return error;
@@ -1394,8 +1405,19 @@ int git_checkout_tree(
13941405
git_tree *tree = NULL;
13951406
git_iterator *tree_i = NULL;
13961407

1397-
if ((error = git_repository__ensure_not_bare(repo, "checkout tree")) < 0)
1398-
return error;
1408+
if (!treeish && !repo) {
1409+
giterr_set(GITERR_CHECKOUT,
1410+
"Must provide either repository or tree to checkout");
1411+
return -1;
1412+
}
1413+
if (treeish && repo && git_object_owner(treeish) != repo) {
1414+
giterr_set(GITERR_CHECKOUT,
1415+
"Object to checkout does not match repository");
1416+
return -1;
1417+
}
1418+
1419+
if (!repo)
1420+
repo = git_object_owner(treeish);
13991421

14001422
if (git_object_peel((git_object **)&tree, treeish, GIT_OBJ_TREE) < 0) {
14011423
giterr_set(
@@ -1420,8 +1442,7 @@ int git_checkout_head(
14201442
git_tree *head = NULL;
14211443
git_iterator *head_i = NULL;
14221444

1423-
if ((error = git_repository__ensure_not_bare(repo, "checkout head")) < 0)
1424-
return error;
1445+
assert(repo);
14251446

14261447
if (!(error = checkout_lookup_head_tree(&head, repo)) &&
14271448
!(error = git_iterator_for_tree(&head_i, head, 0, NULL, NULL)))

0 commit comments

Comments
 (0)