summaryrefslogtreecommitdiff
path: root/bin/git-push-all
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-10-14 14:14:23 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-14 14:14:56 -0700
commitd3c8282d15ec79f22a4f5c29145e56d288161f86 (patch)
tree6f10ab2a7605f008a56c4229f8a6391e503c7839 /bin/git-push-all
parent9fb82af4adc0cd7169eeb0358ff8b2f6018f55dd (diff)
downloaddotfiles-d3c8282d15ec79f22a4f5c29145e56d288161f86.tar.gz
git-push-all: add dry run option
Diffstat (limited to 'bin/git-push-all')
-rwxr-xr-xbin/git-push-all13
1 files changed, 10 insertions, 3 deletions
diff --git a/bin/git-push-all b/bin/git-push-all
index 8178ea70..cdab5bf0 100755
--- a/bin/git-push-all
+++ b/bin/git-push-all
@@ -53,6 +53,8 @@ my ($pushDefault)
my %pushes;
+my $dry_run = grep $_ eq "-n", @ARGV;
+
foreach my $branch (@local_branches) {
(my $short_branch = $branch) =~ s#^refs/heads/##;
my ($pushRemote) = $git->config(qw|--local --get --default|,
@@ -68,17 +70,20 @@ foreach my $branch (@local_branches) {
# push unless the branch already exists on the remote: this script
# avoids creating new branches
if ($pushRemote) {
- # say "I: pushing $short_branch to $pushRemote (its pushRemote)";
+ say "I: would push $short_branch to $pushRemote (its pushRemote)"
+ if $dry_run;
push $pushes{$pushRemote}->@*, $branch;
} elsif ($pushDefault
and exists $remote_branches{"refs/remotes/$pushDefault/$short_branch"})
{
- # say "I: pushing $short_branch to $pushDefault (the remote.pushDefault)";
+ say "I: would push $short_branch to $pushDefault (the remote.pushDefault)"
+ if $dry_run;
push $pushes{$pushDefault}->@*, $branch;
} elsif (!$pushDefault
and $tracking and !$need_pull_tracking
and exists $remote_branches{$tracking}) {
- # say "I: pushing $short_branch to its tracking branch, $tracking";
+ say "I: would push $short_branch to its tracking branch, $tracking"
+ if $dry_run;
push $pushes{$tracking_remote}->@*, $branch;
} elsif (!$need_pull_tracking) {
say "W: couldn't find anywhere to push $branch";
@@ -86,6 +91,8 @@ foreach my $branch (@local_branches) {
}
}
+$dry_run and exit;
+
foreach my $remote (keys %pushes) {
# TODO if $remote eq $pushDefault, consider s/follow-// below (and
# pushRemote of master branch, if that exists?)