git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] add -p: skip conflicted paths

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 28, 2012, 21:39 UTC
Message-ID
<7viphotng8.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1332966017-6100-1-git-send-email-kusmabite@gmail.com>
Erik Faye-Lund <kusmabite@gmail.com> writes:
Show 19 quoted lines
> 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@gmail.com>
> ---
>
> On Wed, Mar 28, 2012 at 9:28 PM, Junio C Hamano <gitster@pobox.com> 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;
 
Previous: Erik Faye-LundNext: Junio C Hamano
Message 4 of 16 in “add -p: skip conflicted paths”
  1. add -p: skip conflicted pathsErik Faye-Lund, Mar 28, 2012
  2. Junio C HamanoMar 28, 2012
  3. add -p: skip conflicted pathsErik Faye-Lund, Mar 28, 2012
  4. Junio C HamanoMar 28, 2012
  5. Junio C HamanoMar 28, 2012
  6. Junio C HamanoMar 28, 2012
  7. Jeff KingMar 29, 2012
  8. Erik Faye-LundApr 2, 2012
  9. Junio C HamanoApr 2, 2012
  10. Jeff KingApr 4, 2012
  11. Tay Ray ChuanApr 4, 2012
  12. Junio C HamanoApr 4, 2012
  13. Junio C HamanoApr 4, 2012
  14. Jeff KingApr 4, 2012
  15. Junio C HamanoApr 4, 2012
  16. Jeff KingApr 5, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.