add--interactive: ignore submodule changes except HEAD

For 'add -i' and 'add -p', the only action we can take on a dirty submodule entry is update the index with a new value from its HEAD. The content changes inside (from its own index, untracked files...) do not matter, at least until 'git add -i' learns about launching a new interactive add session inside a submodule. Ignore all other submodules changes except HEAD. This reduces the number of entries the user has to check through in 'git add -i', and the number of 'no' they have to answer to 'git add -p' when dirty submodules are present. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 13, 2018 at 19:10 UTC 12434efc1d4a83d768e8b60bfdb711780677a308
2 files changed +49 -1
git-add--interactive.perl
+1 -1
@@ -262,7 +262,7 @@ sub list_modified {
262 }
263 }
264
265 - for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {
265 + for (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {
266 if (($add, $del, $file) =
267 /^([-\d]+) ([-\d]+) (.*)/) {
268 $file = unquote_path($file);
t/t3701-add-interactive.sh
+48
@@ -493,4 +493,52 @@ test_expect_success 'add -p works even with color.ui=always' '
493 test_cmp expect actual
494 '
495
496 +test_expect_success 'setup different kinds of dirty submodules' '
497 + test_create_repo for-submodules &&
498 + (
499 + cd for-submodules &&
500 + test_commit initial &&
501 + test_create_repo dirty-head &&
502 + (
503 + cd dirty-head &&
504 + test_commit initial
505 + ) &&
506 + cp -R dirty-head dirty-otherwise &&
507 + cp -R dirty-head dirty-both-ways &&
508 + git add dirty-head &&
509 + git add dirty-otherwise dirty-both-ways &&
510 + git commit -m initial &&
511 +
512 + cd dirty-head &&
513 + test_commit updated &&
514 + cd ../dirty-both-ways &&
515 + test_commit updated &&
516 + echo dirty >>initial &&
517 + : >untracked &&
518 + cd ../dirty-otherwise &&
519 + echo dirty >>initial &&
520 + : >untracked
521 + ) &&
522 + git -C for-submodules diff-files --name-only >actual &&
523 + cat >expected <<-\EOF &&
524 + dirty-both-ways
525 + dirty-head
526 + dirty-otherwise
527 + EOF
528 + test_cmp expected actual &&
529 + git -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&
530 + cat >expected <<-\EOF &&
531 + dirty-both-ways
532 + dirty-head
533 + EOF
534 + test_cmp expected actual
535 +'
536 +
537 +test_expect_success 'status ignores dirty submodules (except HEAD)' '
538 + git -C for-submodules add -i </dev/null >output &&
539 + grep dirty-head output &&
540 + grep dirty-both-ways output &&
541 + ! grep dirty-otherwise output
542 +'
543 +
544 test_done