summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-01-26 14:42:53 +0100
committerOswald Buddenhagen <oswald.buddenhagen@gmx.de>2021-01-29 21:46:18 +0000
commita829867f0873227451099d77597706b5efb5ed10 (patch)
treeea01be01cc4879b51d08aec656f1ecff3727b8f0
parent7efc56e59dfd7cc300f92e3c3e7744202fd7b021 (diff)
gpush: allow configuring branch-specific remotes
Change-Id: I2723e0d4a2e26b9de6a1d1895d6b9e2f11f58f20 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rwxr-xr-xbin/git-gpush34
-rw-r--r--bin/git_gpush.pm56
2 files changed, 64 insertions, 26 deletions
diff --git a/bin/git-gpush b/bin/git-gpush
index 2215b02..a0884af 100755
--- a/bin/git-gpush
+++ b/bin/git-gpush
@@ -207,14 +207,10 @@ Options:
Print debug information.
Configuration:
- This program uses options from the git configuration. All its keys
- use the 'gpush.' prefix. Consequently, to configure any option, you
- can use a command like this:
- git config --global gpush.<the option> <the value>
- If you want it to be local to the current repository, just drop the
- --global option. The following options are supported:
-
- alias.<alias>
+ This program uses options from the git configuration. The following
+ options are supported:
+
+ gpush.alias.<alias>
An alias definition. The value is a comma-separated list of Gerrit
login names and/or email addresses, so it's possible to map, for
example, IRC nicknames or entire teams. Note that git config keys
@@ -222,25 +218,31 @@ Configuration:
to map some IRC nicks via git configuration; see below for an
alternative.
- minimal
+ gpush.minimal
Whether to use minimal push mode by default.
Defaults to true if not configured.
- remote
+ branch.<branch>.gpushremote
+ The git remote to use for pushing to Gerrit for branch <branch>.
+ When not configured, the default remote is used as described below.
+
+ gpush.remote
The default git remote to use for pushing to Gerrit.
- When not configured, 'gerrit' is used if present, otherwise the
- pushed branch's upstream remote is used.
+ When not configured, 'gerrit' is used if present, falling back to
+ git's branch.<branch>.pushremote and remote.pushdefault configs
+ if present, or the pushed branch's upstream remote as a last resort.
- upstream
+ gpush.upstream
The git remote to assume to be the upstream if the pushed branch
does not have a remote-tracking branch configured.
Defaults to 'origin' or the only present remote if not configured.
In addition to the git configuration (which takes precedence), the file
.git-gpush-aliases located next to this program is also read. It may
- contain two sections: 'config' where you can use the options specified
- above, and 'aliases'. The latter works just like alias definitions via
- the git configuration, except that:
+ contain two sections: 'config' where you can use the options in the
+ 'gpush.' namespace specified above (but without the prefix), as well
+ as 'aliases'. The latter works just like alias definitions via the git
+ configuration, except that:
- The alias name itself may also be a comma-separated list, thus
supporting users with multiple handles.
- Most characters are permitted in the alias names.
diff --git a/bin/git_gpush.pm b/bin/git_gpush.pm
index a94465e..b4133a2 100644
--- a/bin/git_gpush.pm
+++ b/bin/git_gpush.pm
@@ -474,6 +474,51 @@ sub update_excludes()
@upstream_excludes = map { "^$_" } keys %heads;
}
+sub find_gerrit_remote($)
+{
+ my ($remotes) = @_;
+
+ if (defined($local_branch)) {
+ # If a branch-specific Gerrit remote is configured, use exactly that one.
+ $remote = git_config("branch.$local_branch.gpushremote");
+ if (defined($remote)) {
+ fail("Remote '$remote' configured in branch.$local_branch.gpushremote is invalid.\n")
+ if (!defined($$remotes{$remote}));
+ return;
+ }
+ }
+ # Otherwise, if a global Gerrit remote is configured, use exactly that one.
+ $remote = git_config("gpush.remote");
+ if (defined($remote)) {
+ fail("Remote '$remote' configured in gpush.remote is invalid.\n")
+ if (!defined($$remotes{$remote}));
+ return;
+ }
+ # Otherwise use 'gerrit' if present.
+ if (defined($$remotes{'gerrit'})) {
+ $remote = 'gerrit';
+ return;
+ }
+ if (defined($local_branch)) {
+ # Otherwise, if a branch-specific push remote is configured, use that one.
+ $remote = git_config("branch.$local_branch.pushremote");
+ if (defined($remote)) {
+ fail("Remote '$remote' configured in branch.$local_branch.pushremote is invalid.\n")
+ if (!defined($$remotes{$remote}));
+ return;
+ }
+ }
+ # Otherwise, if a global push remote is configured, use that one.
+ $remote = git_config("remote.pushdefault");
+ if (defined($remote)) {
+ fail("Remote '$remote' configured in remote.pushdefault is invalid.\n")
+ if (!defined($$remotes{$remote}));
+ return;
+ }
+ # Otherwise fall back to the upstream remote.
+ $remote = $upstream_remote;
+}
+
sub setup_remotes($)
{
my ($source) = @_;
@@ -512,16 +557,7 @@ sub setup_remotes($)
fail("Specified Gerrit remote '$remote' is invalid.\n")
if (!defined($remotes{$remote}));
} else {
- $remote = git_config('gpush.remote');
- # If a remote is configured, use exactly that one.
- if (defined($remote)) {
- fail("Remote '$remote' configured in gpush.remote is invalid.\n")
- if (!defined($remotes{$remote}));
- } else {
- # Otherwise try 'gerrit', and fall back to the upstream remote.
- $remote = 'gerrit';
- $remote = $upstream_remote if (!defined($remotes{$remote}));
- }
+ find_gerrit_remote(\%remotes);
}
update_excludes();
}