Erik Faye-Lund <kusmabite@xxxxxxxxx> writes: > When performing "git add -p" on a file in a conflicted state, we > currently spew the diff and terminate the process. > > This is not very helpful to the user. Change the behaviour to > skipping the file, while outputting a warning. > > Signed-off-by: Erik Faye-Lund <kusmabite@xxxxxxxxx> > --- > > On Wed, Mar 28, 2012 at 9:28 PM, Junio C Hamano <gitster@xxxxxxxxx> wrote: >> Perhaps teach list_modified(), which currently takes 'file-only' and >> 'index-only', to also take an option to omit (and warn if it is >> appropriate) unmerged paths? > > Good idea. This way, the path doesn't even get listed when using > git add -i, and no warning is spewed on "git add -p" without specifying > the path. It seems like the right thing to do. > > Again, I'm no Perl-guru, so apologies if the code isn't idiomatic. I personally don't worry about Perly-ness in the early rounds of the review. I was hoping that we could somehow do this with a single invocation of ls-files, instead of doing it over and over inside a loop. Totally untested, but something along this line... git-add--interactive.perl | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 8f0839d..8bf1835 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -270,16 +270,35 @@ sub get_empty_tree { # FILE_ADDDEL: is it add/delete between index and file? sub list_modified { - my ($only) = @_; + my ($only, $filter_unmerged) = @_; my (%data, @return); my ($add, $del, $adddel, $file); my @tracked = (); - if (@ARGV) { - @tracked = map { + if (@ARGV || $filter_unmerged) { + my %unmerged = (); + for (run_cmd_pipe(qw(git ls-files -s --), @ARGV)) { chomp $_; - unquote_path($_); - } run_cmd_pipe(qw(git ls-files --), @ARGV); + if (/^[0-7]+ [0-9a-f]{40} ([0-3]) (.*)/) { + my ($stage, $path) = ($1, unquote_path($2)); + if ($stage eq '0') { + push @tracked, $path; + } else { + $unmerged{$path} = 1; + } + } else { + die "Oops: $_"; + } + } + if (%unmerged) { + if ($filter_unmerged) { + for (sort keys %unmerged) { + warn "unmerged: $_"; + } + } else { + @tracked = sort (@tracked, keys %unmerged); + } + } return if (!@tracked); } @@ -1189,7 +1208,7 @@ sub apply_patch_for_checkout_commit { } sub patch_update_cmd { - my @all_mods = list_modified($patch_mode_flavour{FILTER}); + my @all_mods = list_modified($patch_mode_flavour{FILTER}, 'filter-unmerged'); my @mods = grep { !($_->{BINARY}) } @all_mods; my @them; -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html