Skip to content

Commit c59b73b

Browse files
committed
Merge branch 'fc/atmark-in-refspec'
"@" sometimes worked (e.g. "git push origin @:there") as a part of a refspec element, but "git push origin @" did not work, which has been corrected. * fc/atmark-in-refspec: refspec: make @ a synonym of HEAD tests: push: trivial cleanup tests: push: improve cleanup of HEAD tests
2 parents 78abcff + 374fbae commit c59b73b

File tree

3 files changed

+62
-51
lines changed

3 files changed

+62
-51
lines changed

refspec.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
7171
}
7272

7373
item->pattern = is_glob;
74-
item->src = xstrndup(lhs, llen);
74+
if (llen == 1 && *lhs == '@')
75+
item->src = xstrdup("HEAD");
76+
else
77+
item->src = xstrndup(lhs, llen);
7578
flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
7679

7780
if (item->negative) {

t/t5511-refspec.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ test_refspec fetch 'HEAD~4:refs/remotes/frotz/new' invalid
5858

5959
test_refspec push 'HEAD'
6060
test_refspec fetch 'HEAD'
61+
test_refspec push '@'
62+
test_refspec fetch '@'
6163
test_refspec push 'refs/heads/ nitfol' invalid
6264
test_refspec fetch 'refs/heads/ nitfol' invalid
6365

t/t5516-fetch-push.sh

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -436,70 +436,76 @@ test_expect_success 'push ref expression with non-existent, incomplete dest' '
436436
437437
'
438438

439-
test_expect_success 'push with HEAD' '
439+
for head in HEAD @
440+
do
440441

441-
mk_test testrepo heads/master &&
442-
git checkout master &&
443-
git push testrepo HEAD &&
444-
check_push_result testrepo $the_commit heads/master
442+
test_expect_success "push with $head" '
445443
446-
'
444+
mk_test testrepo heads/master &&
445+
git checkout master &&
446+
git push testrepo $head &&
447+
check_push_result testrepo $the_commit heads/master
447448
448-
test_expect_success 'push with HEAD nonexisting at remote' '
449+
'
449450

450-
mk_test testrepo heads/master &&
451-
git checkout -b local master &&
452-
git push testrepo HEAD &&
453-
check_push_result testrepo $the_commit heads/local
454-
'
451+
test_expect_success "push with $head nonexisting at remote" '
455452
456-
test_expect_success 'push with +HEAD' '
453+
mk_test testrepo heads/master &&
454+
git checkout -b local master &&
455+
test_when_finished "git checkout master; git branch -D local" &&
456+
git push testrepo $head &&
457+
check_push_result testrepo $the_commit heads/local
458+
'
457459

458-
mk_test testrepo heads/master &&
459-
git checkout master &&
460-
git branch -D local &&
461-
git checkout -b local &&
462-
git push testrepo master local &&
463-
check_push_result testrepo $the_commit heads/master &&
464-
check_push_result testrepo $the_commit heads/local &&
460+
test_expect_success "push with +$head" '
465461
466-
# Without force rewinding should fail
467-
git reset --hard HEAD^ &&
468-
test_must_fail git push testrepo HEAD &&
469-
check_push_result testrepo $the_commit heads/local &&
462+
mk_test testrepo heads/master &&
463+
git checkout -b local master &&
464+
test_when_finished "git checkout master; git branch -D local" &&
465+
git push testrepo master local &&
466+
check_push_result testrepo $the_commit heads/master &&
467+
check_push_result testrepo $the_commit heads/local &&
470468
471-
# With force rewinding should succeed
472-
git push testrepo +HEAD &&
473-
check_push_result testrepo $the_first_commit heads/local
469+
# Without force rewinding should fail
470+
git reset --hard $head^ &&
471+
test_must_fail git push testrepo $head &&
472+
check_push_result testrepo $the_commit heads/local &&
474473
475-
'
474+
# With force rewinding should succeed
475+
git push testrepo +$head &&
476+
check_push_result testrepo $the_first_commit heads/local
476477
477-
test_expect_success 'push HEAD with non-existent, incomplete dest' '
478+
'
478479

479-
mk_test testrepo &&
480-
git checkout master &&
481-
git push testrepo HEAD:branch &&
482-
check_push_result testrepo $the_commit heads/branch
480+
test_expect_success "push $head with non-existent, incomplete dest" '
483481
484-
'
482+
mk_test testrepo &&
483+
git checkout master &&
484+
git push testrepo $head:branch &&
485+
check_push_result testrepo $the_commit heads/branch
485486
486-
test_expect_success 'push with config remote.*.push = HEAD' '
487+
'
487488

488-
mk_test testrepo heads/local &&
489-
git checkout master &&
490-
git branch -f local $the_commit &&
491-
(
492-
cd testrepo &&
493-
git checkout local &&
494-
git reset --hard $the_first_commit
495-
) &&
496-
test_config remote.there.url testrepo &&
497-
test_config remote.there.push HEAD &&
498-
test_config branch.master.remote there &&
499-
git push &&
500-
check_push_result testrepo $the_commit heads/master &&
501-
check_push_result testrepo $the_first_commit heads/local
502-
'
489+
test_expect_success "push with config remote.*.push = $head" '
490+
491+
mk_test testrepo heads/local &&
492+
git checkout master &&
493+
git branch -f local $the_commit &&
494+
test_when_finished "git branch -D local" &&
495+
(
496+
cd testrepo &&
497+
git checkout local &&
498+
git reset --hard $the_first_commit
499+
) &&
500+
test_config remote.there.url testrepo &&
501+
test_config remote.there.push $head &&
502+
test_config branch.master.remote there &&
503+
git push &&
504+
check_push_result testrepo $the_commit heads/master &&
505+
check_push_result testrepo $the_first_commit heads/local
506+
'
507+
508+
done
503509

504510
test_expect_success 'push with remote.pushdefault' '
505511
mk_test up_repo heads/master &&

0 commit comments

Comments
 (0)