push: Allow @ shortcut with git-push
PATCH 1/1 push: Allow @ shortcut with git-push
Until now, HEAD could be used with git-push to push the current branch. Now @ is a shortcut to HEAD, but it didn't work when pushing branches. It fails with:
fatal: remote part of refspec is not a valid name in @
Reinterpret all branch names from argv in order for @ to be used when pushing branches.
--- builtin/push.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
builtin/push.c +14 -1
@@ -494,7 +494,20 @@ int cmd_push(int argc, const char **argv, const char *prefix)if (argc >0 ) { repo = argv[0 ]; -set_refspecs (argv +1 , argc -1 ); + +char *refs[argc -1 ]; +int i; +for (i =1 ; i < argc; i++) { + refs[i -1 ] = argv[i]; + +struct strbuf buf =STRBUF_INIT ; +interpret_branch_name (argv[i],strlen (argv[i]), &buf); + +if (buf.buf &&strlen (buf.buf) >0 ) + refs[i -1 ] = buf.buf; + } + +set_refspecs (refs, argc -1 ); } rc =do_push (repo, flags);
Signature · 1 line
1.8.5
Quoted 31 lines · Tomo Krajina
Until now, HEAD could be used with git-push to push the current branch. Now @ is a shortcut to HEAD, but it didn't work when pushing branches. It fails with:
fatal: remote part of refspec is not a valid name in @
Reinterpret all branch names from argv in order for @ to be used when pushing branches.
Signed-off-by Tomo Krajina <[email protected]>--- builtin/push.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)builtin/push.c +7
-1@@ -494,7 +494,20 @@ int cmd_push(int argc, const char **argv, const char *prefix)if (argc >0 ) { repo = argv[0 ]; -set_refspecs (argv +1 , argc -1 ); + +char *refs[argc -1 ]; +int i; +for (i =1 ; i < argc; i++) { + refs[i -1 ] = argv[i]; + +struct strbuf buf =STRBUF_INIT ;
builtin/push.c int cmd_push(int argc, const char **argv, const char *prefix) · line 513
Quoted 10 lines
builtin/push.c +7
-0+interpret_branch_name (argv[i],strlen (argv[i]), &buf); + +if (buf.buf &&strlen (buf.buf) >0 ) + refs[i -1 ] = buf.buf; + } + +set_refspecs (refs, argc -1 ); } rc =do_push (repo, flags);
I don't think this is the right way to go. There are many places where HEAD cannot be replaced with @, or @{u}, or any of such syntaxes.
We might want to do this kind of replacement in many other places, but we would need to make sure it makes sense.
Moreover, in order for this patch to be considered you need to add tests.
Cheers.
Signature · 1 line
Felipe Contreras