push: support pushing HEAD to real branch name
This teaches "push <remote> HEAD" to resolve HEAD on the local side to its real branch name, e.g. master, and then act as if the real branch name was specified. So we have a shorthand for pushing the current branch. Besides HEAD, no other symbolic ref is resolved. Thanks to Daniel Barkalow <barkalow@iabervon.org> for suggesting this implementation, which is much simpler than the implementation proposed before. 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:35 UTC
47d996a20c3347bb9efbb44e8ed2d615cfdffba3
2 files changed
+26
builtin-push.c
+9
@@ -44,6 +44,15 @@ static void set_refspecs(const char **refs, int nr)
44
strcat(tag, refs[i]);
45
ref = tag;
46
}
47
+ if (!strcmp("HEAD", ref)) {
48
+ unsigned char sha1_dummy[20];
49
+ ref = resolve_ref(ref, sha1_dummy, 1, NULL);
50
+ if (!ref)
51
+ die("HEAD cannot be resolved.");
52
+ if (prefixcmp(ref, "refs/heads/"))
53
+ die("HEAD cannot be resolved to branch.");
54
+ ref = xstrdup(ref + 11);
55
+ }
56
add_refspec(ref);
57
}
58
}
t/t5516-fetch-push.sh
+17
@@ -244,6 +244,23 @@ test_expect_success 'push with colon-less refspec (4)' '
244
245
'
246
247
+test_expect_success 'push with HEAD' '
248
+
249
+ mk_test heads/master &&
250
+ git checkout master &&
251
+ git push testrepo HEAD &&
252
+ check_push_result $the_commit heads/master
253
+
254
+'
255
+
256
+test_expect_success 'push with HEAD nonexisting at remote' '
257
+
258
+ mk_test heads/master &&
259
+ git checkout -b local master &&
260
+ git push testrepo HEAD &&
261
+ check_push_result $the_commit heads/local
262
+'
263
+
264
test_expect_success 'push with dry-run' '
265
266
mk_test heads/master &&