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

[PATCH] add -p: skip conflicted paths

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Mar 28, 2012, 20:20 UTC
Message-ID
<1332966017-6100-1-git-send-email-kusmabite@gmail.com>
In-Reply-To
<7viphov839.fsf@alter.siamese.dyndns.org>

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.
 git-add--interactive.perl |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 8f0839d..4913203 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -270,7 +270,7 @@ sub get_empty_tree {
 # FILE_ADDDEL:	is it add/delete between index and file?
 
 sub list_modified {
-	my ($only) = @_;
+	my ($only, $omit_unmerged) = @_;
 	my (%data, @return);
 	my ($add, $del, $adddel, $file);
 	my @tracked = ();
@@ -359,6 +359,10 @@ sub list_modified {
 				next if ($it->{FILE} eq 'nothing');
 			}
 		}
+		if ($omit_unmerged && run_cmd_pipe(qw(git ls-files -u --), $_)) {
+			print colored $error_color, "Warning: $_ is in conflicted state, skipping.\n" if @ARGV;
+			next;
+		}
 		push @return, +{
 			VALUE => $_,
 			%$it,
@@ -1189,7 +1193,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}, 1);
 	my @mods = grep { !($_->{BINARY}) } @all_mods;
 	my @them;
 
-- 
1.7.9
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 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.