{"thread":{"id":"47585","subject":"[PATCH/RFC] add--interactive: ignore all internal submodule changes","startedAt":"2018-01-10T11:07:57Z","lastAt":"2018-01-13T12:11:00Z","messageCount":4,"participants":["Nguyễn Thái Ngọc Duy","Stefan Beller","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"336375","messageId":"20180110110643.21465-1-pclouds@gmail.com","threadId":"47585","inReplyTo":null,"subject":"[PATCH/RFC] add--interactive: ignore all internal submodule changes","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-01-10T11:06:43Z","receivedAt":"2018-01-10T11:07:57Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"For 'add -i' and 'add -p' the only action we can take on a dirty\nsubmodule entry (from the superproject perspective) is its SHA-1. The\ncontent changes inside do not matter, at least until interactive add has\n--recurse-submodules or something.\n\nIgnore all dirty changes to reduce the questions 'add -i' and 'add -p'\nthrow at the user when submodules are dirty.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n $DAYJOB started to use submodules and this annoys me so much when I\n use 'git add -p'. I'm neither very familiar with add--interactive nor\n submodules code but this seems to work. Hopefully it's a correct\n change.\n\n git-add--interactive.perl | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 28b325d754..964c3a7542 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -262,7 +262,7 @@ sub list_modified {\n \t\t}\n \t}\n \n-\tfor (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {\n+\tfor (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {\n \t\tif (($add, $del, $file) =\n \t\t    /^([-\\d]+)\t([-\\d]+)\t(.*)/) {\n \t\t\t$file = unquote_path($file);\n-- \n2.15.1.600.g899a5f85c6\n\n"},{"id":"336413","messageId":"CAGZ79kbUL6UBBB-wL+BxBdbomt+sxa66VVSYBxxBt6JVfPVfKA@mail.gmail.com","threadId":"47585","inReplyTo":"20180110110643.21465-1-pclouds@gmail.com","subject":"Re: [PATCH/RFC] add--interactive: ignore all internal submodule changes","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-01-10T19:47:31Z","receivedAt":"2018-01-10T19:47:39Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Jan 10, 2018 at 3:06 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> For 'add -i' and 'add -p' the only action we can take on a dirty\n> submodule entry (from the superproject perspective) is its SHA-1. The\n> content changes inside do not matter, at least until interactive add has\n> --recurse-submodules or something.\n>\n> Ignore all dirty changes to reduce the questions 'add -i' and 'add -p'\n> throw at the user when submodules are dirty.\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  $DAYJOB started to use submodules and this annoys me so much when I\n>  use 'git add -p'. I'm neither very familiar with add--interactive nor\n>  submodules code but this seems to work. Hopefully it's a correct\n>  change.\n\nI would think this fixes your problem and it looks correct.\n\nHowever I wonder about some subtle detail:\nthe \"dirty\" setting will ignore anything inside the submodule, and\nonly pay attention to the delta in gitlinks between HEAD and index.\n\nMaybe we'd want to have a mode \"dirty-except-submodule-HEAD\",\nwhich would ignore all submodule worktree changes, but if its HEAD\nis different than the gitlink in the superproject index or HEAD, such that\nchecking out a different revision inside the submodule is not lost\nwhen staging things in the superproject for a new commit?\n\n>\n>  git-add--interactive.perl | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/git-add--interactive.perl b/git-add--interactive.perl\n> index 28b325d754..964c3a7542 100755\n> --- a/git-add--interactive.perl\n> +++ b/git-add--interactive.perl\n> @@ -262,7 +262,7 @@ sub list_modified {\n>                 }\n>         }\n>\n> -       for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {\n> +       for (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {\n>                 if (($add, $del, $file) =\n>                     /^([-\\d]+)  ([-\\d]+)        (.*)/) {\n>                         $file = unquote_path($file);\n> --\n> 2.15.1.600.g899a5f85c6\n>\n"},{"id":"336453","messageId":"CACsJy8CgzrSu7bZYQAPOK=P+CWK2vjTS3=biBBP6uZGe5ZoSMw@mail.gmail.com","threadId":"47585","inReplyTo":"CAGZ79kbUL6UBBB-wL+BxBdbomt+sxa66VVSYBxxBt6JVfPVfKA@mail.gmail.com","subject":"Re: [PATCH/RFC] add--interactive: ignore all internal submodule changes","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-01-11T11:06:11Z","receivedAt":"2018-01-11T11:06:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Jan 11, 2018 at 2:47 AM, Stefan Beller <sbeller@google.com> wrote:\n> On Wed, Jan 10, 2018 at 3:06 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>> For 'add -i' and 'add -p' the only action we can take on a dirty\n>> submodule entry (from the superproject perspective) is its SHA-1. The\n>> content changes inside do not matter, at least until interactive add has\n>> --recurse-submodules or something.\n>>\n>> Ignore all dirty changes to reduce the questions 'add -i' and 'add -p'\n>> throw at the user when submodules are dirty.\n>>\n>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>> ---\n>>  $DAYJOB started to use submodules and this annoys me so much when I\n>>  use 'git add -p'. I'm neither very familiar with add--interactive nor\n>>  submodules code but this seems to work. Hopefully it's a correct\n>>  change.\n>\n> I would think this fixes your problem and it looks correct.\n>\n> However I wonder about some subtle detail:\n> the \"dirty\" setting will ignore anything inside the submodule, and\n> only pay attention to the delta in gitlinks between HEAD and index.\n\nWait, why does diff-files, the command about worktree and index, look\nat HEAD? Testing, testing... no I think it still works as expected\n\n> ~/w/git/temp/z $ git ls-files  --stage foo\n160000 41521690bee4b76ad108a403b79415f8591a5592 0       foo\n> ~/w/git/temp/z $ git -C foo rev-parse HEAD\n3bc15b2e78ec3a5c5ea27715f20adaa2669446b1\n> ~/w/git/temp/z $ ../git diff --ignore-submodules=dirty foo\ndiff --git a/foo b/foo\nindex 4152169..3bc15b2 160000\n--- a/foo\n+++ b/foo\n@@ -1 +1 @@\n-Subproject commit 41521690bee4b76ad108a403b79415f8591a5592\n+Subproject commit 3bc15b2e78ec3a5c5ea27715f20adaa2669446b1\n> ~/w/git/temp/z $ ../git diff-files --ignore-submodules=dirty foo\n:160000 160000 41521690bee4b76ad108a403b79415f8591a5592\n0000000000000000000000000000000000000000 M      foo\n\nIf I reset foo/.git/HEAD back to 4152169... then diff-files\n--ignore..=dirty returns empty. So I think it does check submodule's\nHEAD.\n\n> Maybe we'd want to have a mode \"dirty-except-submodule-HEAD\",\n> which would ignore all submodule worktree changes, but if its HEAD\n> is different than the gitlink in the superproject index or HEAD, such that\n> checking out a different revision inside the submodule is not lost\n> when staging things in the superproject for a new commit?\n-- \nDuy\n"},{"id":"336556","messageId":"20180113121038.26984-1-pclouds@gmail.com","threadId":"47585","inReplyTo":"20180110110643.21465-1-pclouds@gmail.com","subject":"[PATCH v2] add--interactive: ignore submodule changes except HEAD","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-01-13T12:10:38Z","receivedAt":"2018-01-13T12:11:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"For 'add -i' and 'add -p', the only action we can take on a dirty\nsubmodule entry is update the index with a new value from its HEAD. The\ncontent changes inside (from its own index, untracked files...) do not\nmatter, at least until 'git add -i' learns about launching a new\ninteractive add session inside a submodule.\n\nIgnore all other submodules changes except HEAD. This reduces the number\nof entries the user has to check through in 'git add -i', and the number\nof 'no' they have to answer to 'git add -p' when dirty submodules are\npresent.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n v2 now has some tests. The commit message is rephrased a bit.\n\n git-add--interactive.perl  |  2 +-\n t/t3701-add-interactive.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 49 insertions(+), 1 deletion(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 28b325d754..964c3a7542 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -262,7 +262,7 @@ sub list_modified {\n \t\t}\n \t}\n \n-\tfor (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {\n+\tfor (run_cmd_pipe(qw(git diff-files --ignore-submodules=dirty --numstat --summary --raw --), @ARGV)) {\n \t\tif (($add, $del, $file) =\n \t\t    /^([-\\d]+)\t([-\\d]+)\t(.*)/) {\n \t\t\t$file = unquote_path($file);\ndiff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh\nindex a49c12c79b..058698df6a 100755\n--- a/t/t3701-add-interactive.sh\n+++ b/t/t3701-add-interactive.sh\n@@ -493,4 +493,52 @@ test_expect_success 'add -p works even with color.ui=always' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'setup different kinds of dirty submodules' '\n+\ttest_create_repo for-submodules &&\n+\t(\n+\t\tcd for-submodules &&\n+\t\ttest_commit initial &&\n+\t\ttest_create_repo dirty-head &&\n+\t\t(\n+\t\t\tcd dirty-head &&\n+\t\t\ttest_commit initial\n+\t\t) &&\n+\t\tcp -R dirty-head dirty-otherwise &&\n+\t\tcp -R dirty-head dirty-both-ways &&\n+\t\tgit add dirty-head &&\n+\t\tgit add dirty-otherwise dirty-both-ways &&\n+\t\tgit commit -m initial &&\n+\n+\t\tcd dirty-head &&\n+\t\ttest_commit updated &&\n+\t\tcd ../dirty-both-ways &&\n+\t\ttest_commit updated &&\n+\t\techo dirty >>initial &&\n+\t\t: >untracked &&\n+\t\tcd ../dirty-otherwise &&\n+\t\techo dirty >>initial &&\n+\t\t: >untracked\n+\t) &&\n+\tgit -C for-submodules diff-files --name-only >actual &&\n+\tcat >expected <<-\\EOF &&\n+\tdirty-both-ways\n+\tdirty-head\n+\tdirty-otherwise\n+\tEOF\n+\ttest_cmp expected actual &&\n+\tgit -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&\n+\tcat >expected <<-\\EOF &&\n+\tdirty-both-ways\n+\tdirty-head\n+\tEOF\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'status ignores dirty submodules (except HEAD)' '\n+\tgit -C for-submodules add -i </dev/null >output &&\n+\tgrep dirty-head output &&\n+\tgrep dirty-both-ways output &&\n+\t! grep dirty-otherwise output\n+'\n+\n test_done\n-- \n2.15.1.600.g899a5f85c6\n\n"}]}