Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

git-re-edit will now edit all files changed in a given commit

  • Loading branch information...
commit 4aa547671c224d834109990027f632bcaa87a0d9 1 parent 18a481b
Mark Dominus authored
Showing with 21 additions and 13 deletions.
  1. +21 −13 git-re-edit
View
34 git-re-edit
@@ -7,33 +7,41 @@
# dirty. Useful following a "git reset HEAD^" to continue work on the
# stuff you were working on before. Useful following a failed merge.
#
-# I would like this to accept a command-line argument that names a
-# commit; it should then edit all the files touched by the commit.
-#
# There should also be an option to tell it not to suppress ?? files.
+use strict;
use Getopt::Std;
my %opt = ( e => $ENV{VISUAL} || $ENV{EDITOR} || "emacs",
c => 0
);
getopts('e:c', \%opt) or usage();
+my $commit = shift;
+my @changed;
+
+if ($commit) {
+ chomp(@changed = grep /\S/, qx{git show --pretty="format:" --name-only $commit});
+} else {
+ chomp(@changed = grep !/^\?\? /, qx{git status --porcelain});
+ exit 1 unless $? == 0;
+ s/^.. // or die "<$_>???\n" for @changed;
+ die "Fucking shell, how does it work?\n"
+ if grep / /, @changed;
-chomp(my @changed = grep !/^\?\? /, qx{git status --porcelain});
-exit 1 unless $? == 0;
-s/^.. // or die "<$_>???\n" for @changed;
-die "Fucking shell, how does it work?\n"
- if grep / /, @changed;
+ unless (@changed) {
+ warn "No files to edit\n";
+ exit;
+ }
+ chomp(@changed = qx{find @changed -type f });
+ exit 1 unless $? == 0;
+}
-@changed = qw(.) unless @changed;
-chomp(my @lines = qx{find @changed -type f });
-exit 1 unless $? == 0;
if ($opt{c}) {
- print join "\n", @lines, "";
+ print join "\n", @changed, "";
exit 0;
}
# maybe should use output of "git var GIT_EDITOR" here?
# But then I have to involve the !@&*!@*(&!@ shell
my $ed = $opt{e};
-exec $ed, @lines;
+exec $ed, @changed;
die "exec $ed: $!\n";
Please sign in to comment.
Something went wrong with that request. Please try again.