Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 96 lines (78 sloc) 2.305 kb
#!/usr/bin/perl
#
# Run the editor on all the files that have been modified from the
# current index. Useful to resume work when you left the working tree
# dirty. Useful following a "git reset HEAD^" to continue work on the
# stuff you were working on before. Useful following a failed merge.
use strict;
use Getopt::Std;
my $EDITOR = $ENV{VISUAL} || $ENV{EDITOR} || "emacs";
my %opt = ( e => $EDITOR,
c => 0,
'q' => 0,
d => 0,
);
getopts('e:cqd', \%opt) or usage();
run(@ARGV);
sub which_files {
my ($commit) = @_;
my @dirtyfiles_cmd = (qw(git dirtyfiles),
($opt{q} ? ('-q') : ()),
(defined($commit) ? ($commit) : ()),
);
my @files;
{
local $ENV{GIT_DIRTYFILES_NULSEP} = 1;
open my ($f), "-|", @dirtyfiles_cmd
or die "Couldn't run @dirtyfiles_cmd: $!";
local $/ = "\0";
chomp(@files = <$f>);
close $f
or die sprintf "git-dirtyfiles failed with exit status %d\n", $? >> 8;
}
return @files;
}
sub uniq {
my %seen;
my @f;
! $seen{$_}++ && push @f, $_ for @_;
return @f;
}
sub run {
my (@commits) = @_;
my @files;
if (@commits) {
@files = uniq(map which_files($_), @commits);
} else {
@files = which_files();
unless (@files || $opt{d}) {
@files = which_files("HEAD");
}
}
if ($opt{c}) {
print join("\n", @files, "");
exit 0;
}
if (@files == 0) {
warn "No files to edit\n";
exit;
}
# maybe should use output of "git var GIT_EDITOR" here?
# But then I have to involve the !@&*!@*(&!@ shell
my $ed = $opt{e};
exec $ed, @files;
die "exec $ed: $!\n";
}
sub usage {
print STDERR "git re-edit [-cqd] [-e editor] [commits...]
edit the dirty files in the working tree.
If there are no dirty files, edit the files that changed in the
last commit, unless -d was given.
With -q, also edit files that are unknown to Git.
With -c, print what would be edited but don't run the editor. (Deprecated, use git-dirtyfiles instead.)
With one or more commits, edit the files that were changed in those commits.
-d is ignored in this mode.
The default editor is $EDITOR; override with \$VISUAL, \$EDITOR, or with -e.
";
exit 2;
}
Jump to Line
Something went wrong with that request. Please try again.