From 14431b4087125e247c1e2322e0cd043b78974ce2 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 6 Jul 2017 12:30:25 +0200 Subject: gpush: modernize syntax for specifying source and target initially, git-gpush was just a glorified git-push, and hence it started out accepting the same command line. however, one of the main motivations for the script's existence was _avoiding_ the need to specify things we already know, and therefore the regular push syntax actually isn't very useful here in the common case. to that effect, we deprecated the bare remote syntax over two years ago, in favor of the (very rarely used) --remote option. this allows us now to interpret a bare word as something more useful: the source of the push, avoiding the need to always use a colon. following the same logic, we now introduce the --branch option for specifying the target branch, expecting that it will not be used much. these two together allow us to deprecate the old way of specifying both source and target. Change-Id: I0964252d911b6e9fe32458cf309c6b5ee4f646ae Reviewed-by: Edward Welbourne --- bin/git-gpush | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/bin/git-gpush b/bin/git-gpush index 0e24c6f..d2db42d 100755 --- a/bin/git-gpush +++ b/bin/git-gpush @@ -23,7 +23,7 @@ sub usage { print << "EOM"; Usage: - git gpush [opts] [[sha1/ref-from]:[ref-to]] [+] [=] + git gpush [opts] [sha1/ref-from] [+] [=] Pushes Changes to Gerrit and adds reviewers and CC to the PatchSets. @@ -36,9 +36,6 @@ Description: If no sha1 or ref-from is specified, 'HEAD' is used. - If no ref-to is specified, the upstream branch for 'ref-from' is - used as the target branch. - Note that this program can be used in the middle of an interactive rebase, to push out the amended commits instantly. @@ -55,6 +52,10 @@ Options: -r, --remote Specify the git remote to push to. + -b, --branch + Specify the git branch to push for. If not specified, the + upstream branch for 'ref-from' is used as the target branch. + --aliases Report all registered aliases and quit. @@ -300,6 +301,9 @@ sub parse_arguments(@) } elsif ($arg eq "-r" || $arg eq "--remote") { die("--remote needs an argument.\n") if (!@_ || ($_[0] =~ /^-/)); $remote = shift @_; + } elsif ($arg eq "-b" || $arg eq "--branch") { + die("--branch needs an argument.\n") if (!@_ || ($_[0] =~ /^-/)); + $ref_to = shift @_; } elsif ($arg eq "--aliases") { foreach my $key (sort(keys %aliases)) { print "$key = $aliases{$key}\n"; @@ -314,12 +318,18 @@ sub parse_arguments(@) push @CCs, split(/,/, lookup_alias($1)); } elsif ($arg !~ /^\-/) { if ($arg =~ /(.*):(.*)/) { - $ref_from = $1 if (defined $1 && $1 ne ""); - $ref_to = $2 if (defined $2 && $2 ne ""); + if (length($1)) { + $ref_from = $1; + print STDERR "Warning: Specifying : is deprecated.". + " Use just instead.\n"; + } + if (length($2)) { + $ref_to = $2; + print STDERR "Warning: Specifying : is deprecated.". + " Use --branch instead.\n"; + } } else { - print STDERR "Warning: Specifying a bare remote is deprecated.". - " Use --remote instead.\n"; - $remote = $arg; + $ref_from = $arg; } } else { die("Unrecognized option '$arg'.\n"); -- cgit v1.2.3