Skip to content

Commit

Permalink
git-dirtyfiles no longer dies when it encounters deleted files
Browse files Browse the repository at this point in the history
It also omits them from the output, unless `-d` was given.

`git-addq` _does_ supply `-d` so you can tell it whether you want to
commit the deletion.
  • Loading branch information
mjdominus committed Nov 27, 2023
1 parent cb682d9 commit 0060bd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bin/git-addq
@@ -1,3 +1,3 @@
#!/bin/sh

git add $(git dirtyfiles "$@" | menupick -1)
git add $(git dirtyfiles -d "$@" | menupick -1)
16 changes: 13 additions & 3 deletions bin/git-dirtyfiles
Expand Up @@ -10,13 +10,14 @@ use strict;
use Getopt::Std;
my %opt = ( q => 0,
u => 0,
d => 0,
0 => $ENV{GIT_DIRTYFILES_NULSEP} ? 1 : 0,
);


getopts('qu0', \%opt) or usage();
getopts('qud0', \%opt) or usage();
my $commit = shift;
my @changed;
my (@changed, @deleted);

sub cdup {
my $names = shift;
Expand All @@ -33,6 +34,8 @@ if ($commit) {
exit 1 unless $? == 0;
@changed = grep !/^\?\? /, @changed unless $opt{q};
@changed = grep /^[UD]U /, @changed if $opt{u};
@deleted = grep /^(D | D) /, @changed;
@changed = grep ! /^(D | D) /, @changed;
s/^.. // or die "<$_>???\n" for @changed;
s/.* -> // for @changed;
die "Fucking shell, how does it work?\n"
Expand All @@ -45,18 +48,25 @@ if ($commit) {
}

my $sep = $opt{0} ? "\0" : "\n";
if ($opt{d}) {
s/^.. // for @deleted;
push @changed, @deleted;
}
print join $sep, @changed, "";
exit 0;

sub usage {
print STDERR "git dirtyfiles [-q] [-u] [-0] [commit]
print STDERR "git dirtyfiles [-q] [-u] [-d] [-0] [commit]
list the names of files that have been changed since the last commit,
one per line (or separated by NUL if -0 is given)
With -q, include files that are unknown to Git
With -u, include only files with merge conflicts
With -d, include even the names of files that have been deleted
and are no longer in the working tree. Normally these are omitted.
With a commit, list the names of the files that were changed in that commit
";
exit 2;
Expand Down

0 comments on commit 0060bd1

Please sign in to comment.