@matheusbsbs / matheus-bagliano / commits / ae36bdcf51
Fork 0

push: use same rules as git-rev-parse to resolve refspecs

This commit changes the rules for resolving refspecs to match the rules for resolving refs in rev-parse. git-rev-parse uses clear rules to resolve a short ref to its full name, which are well documented. The rules for resolving refspecs documented in git-send-pack were less strict and harder to understand. This commit replaces them by the rules of git-rev-parse. The unified rules are easier to understand and better resolve ambiguous cases. You can now push from a repository containing several branches ending on the same short name. Note, this may break existing setups. For example, "master" will no longer resolve to "origin/master" even when there is no other "master" elsewhere. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Steffen Prohaska committed Nov 11, 2007 at 15:01 UTC ae36bdcf5147b1b54de852eda111ad76a3040726
3 files changed +15 -6
Documentation/git-send-pack.txt
+3 -1
@@ -85,7 +85,9 @@ Each pattern pair consists of the source side (before the colon)
85 and the destination side (after the colon). The ref to be
86 pushed is determined by finding a match that matches the source
87 side, and where it is pushed is determined by using the
88 -destination side.
88 +destination side. The rules used to match a ref are the same
89 +rules used by gitlink:git-rev-parse[1] to resolve a symbolic ref
90 +name.
91
92 - It is an error if <src> does not match exactly one of the
93 local refs.
remote.c
+1 -4
@@ -519,10 +519,7 @@ static int count_refspec_match(const char *pattern,
519 char *name = refs->name;
520 int namelen = strlen(name);
521
522 - if (namelen < patlen ||
523 - memcmp(name + namelen - patlen, pattern, patlen))
524 - continue;
525 - if (namelen != patlen && name[namelen - patlen - 1] != '/')
522 + if (!refname_match(pattern, name, ref_rev_parse_rules))
523 continue;
524
525 /* A match is "weak" if it is with refs outside
t/t5516-fetch-push.sh
+11 -1
@@ -145,11 +145,21 @@ test_expect_success 'push with no ambiguity (1)' '
145 test_expect_success 'push with no ambiguity (2)' '
146
147 mk_test remotes/origin/master &&
148 - git push testrepo master:master &&
148 + git push testrepo master:origin/master &&
149 check_push_result $the_commit remotes/origin/master
150
151 '
152
153 +test_expect_success 'push with colon-less refspec, no ambiguity' '
154 +
155 + mk_test heads/master heads/t/master &&
156 + git branch -f t/master master &&
157 + git push testrepo master &&
158 + check_push_result $the_commit heads/master &&
159 + check_push_result $the_first_commit heads/t/master
160 +
161 +'
162 +
163 test_expect_success 'push with weak ambiguity (1)' '
164
165 mk_test heads/master remotes/origin/master &&