From d3c8282d15ec79f22a4f5c29145e56d288161f86 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 14 Oct 2022 14:14:23 -0700 Subject: git-push-all: add dry run option --- bin/git-push-all | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'bin/git-push-all') 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?) -- cgit v1.2.3