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

Re: [PATCH v2 4/6] tests: use `git submodule add` and fix expected status

From
Glen Choo <chooglen@google.com>
Date
Mar 7, 2023, 00:15 UTC
Message-ID
<kl6lpm9lifhz.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<20230228185642.2357806-4-calvinwan@google.com>
Calvin Wan <calvinwan@google.com> writes:
Show 38 quoted lines
> @@ -122,25 +123,30 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)'
>  '
>  
>  test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
> +	git branch pristine-gitmodules &&
>  	git config diff.ignoreSubmodules dirty &&
>  	git diff HEAD >actual &&
>  	test_must_be_empty actual &&
>  	git config --add -f .gitmodules submodule.subname.ignore none &&
>  	git config --add -f .gitmodules submodule.subname.path sub &&
> +	git commit -m "Update .gitmodules" .gitmodules &&
>  	git diff HEAD >actual &&
>  	sed -e "1,/^@@/d" actual >actual.body &&
>  	expect_from_to >expect.body $subprev $subprev-dirty &&
>  	test_cmp expect.body actual.body &&
>  	git config -f .gitmodules submodule.subname.ignore all &&
>  	git config -f .gitmodules submodule.subname.path sub &&
> +	git commit -m "Update .gitmodules" .gitmodules &&
>  	git diff HEAD >actual2 &&
>  	test_must_be_empty actual2 &&
>  	git config -f .gitmodules submodule.subname.ignore untracked &&
> +	git commit -m "Update .gitmodules" .gitmodules &&
>  	git diff HEAD >actual3 &&
>  	sed -e "1,/^@@/d" actual3 >actual3.body &&
>  	expect_from_to >expect.body $subprev $subprev-dirty &&
>  	test_cmp expect.body actual3.body &&
>  	git config -f .gitmodules submodule.subname.ignore dirty &&
> +	git commit -m "Update .gitmodules" .gitmodules &&
>  	git diff HEAD >actual4 &&
>  	test_must_be_empty actual4 &&
>  	git config submodule.subname.ignore none &&
> @@ -152,7 +158,7 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)
>  	git config --remove-section submodule.subname &&
>  	git config --remove-section -f .gitmodules submodule.subname &&
>  	git config --unset diff.ignoreSubmodules &&
> -	rm .gitmodules
> +	git reset --hard pristine-gitmodules
>  '
This looks like the perfect use case for test_when_finished :)
Show 16 quoted lines
> @@ -190,12 +196,15 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)'
>  test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
>  	git config --add -f .gitmodules submodule.subname.ignore all &&
>  	git config --add -f .gitmodules submodule.subname.path sub &&
> +	git commit -m "Update .gitmodules" .gitmodules &&
>  	git diff HEAD >actual2 &&
>  	test_must_be_empty actual2 &&
>  	git config -f .gitmodules submodule.subname.ignore untracked &&
> +	git commit -m "Update .gitmodules" .gitmodules &&
>  	git diff HEAD >actual3 &&
>  	test_must_be_empty actual3 &&
>  	git config -f .gitmodules submodule.subname.ignore dirty &&
> +	git commit -m "Update .gitmodules" .gitmodules &&
>  	git diff HEAD >actual4 &&
>  	test_must_be_empty actual4 &&
>  	git config submodule.subname.ignore none &&

Like the previous patch, I wonder a little whether we should be diffing with :!.gitmodules, but at least here we are focused on diffing with submodules in general (and not the specific "git diff --submodule=" behavior), so I thnk this is okay to keep.

Show 6 quoted lines
> @@ -206,7 +215,7 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)
>  	test_cmp expect.body actual.body &&
>  	git config --remove-section submodule.subname &&
>  	git config --remove-section -f .gitmodules submodule.subname &&
> -	rm .gitmodules
> +	git reset --hard pristine-gitmodules
Ditto about test_when_finished.
Show 11 quoted lines
>  '
>  
>  test_expect_success 'git diff between submodule commits' '
> @@ -243,7 +252,7 @@ test_expect_success 'git diff between submodule commits [.gitmodules]' '
>  	expect_from_to >expect.body $subtip $subprev &&
>  	git config --remove-section submodule.subname &&
>  	git config --remove-section -f .gitmodules submodule.subname &&
> -	rm .gitmodules
> +	git reset --hard pristine-gitmodules
>  '
>  
Ditto
Show 38 quoted lines
> @@ -1152,8 +1156,37 @@ test_expect_success '.gitmodules ignore=untracked suppresses submodules with unt
>  	test_cmp expect output &&
>  	git config --add -f .gitmodules submodule.subname.ignore untracked &&
>  	git config --add -f .gitmodules submodule.subname.path sm &&
> +	cat > expect-modified-gitmodules << EOF &&
> +On branch main
> +Your branch and '\''upstream'\'' have diverged,
> +and have 2 and 2 different commits each, respectively.
> +  (use "git pull" to merge the remote branch into yours)
> +
> +Changes to be committed:
> +  (use "git restore --staged <file>..." to unstage)
> +	modified:   sm
> +
> +Changes not staged for commit:
> +  (use "git add <file>..." to update what will be committed)
> +  (use "git restore <file>..." to discard changes in working directory)
> +	modified:   .gitmodules
> +	modified:   dir1/modified
> +
> +Submodule changes to be committed:
> +
> +* sm $head...$new_head (1):
> +  > Add bar
> +
> +Untracked files:
> +  (use "git add <file>..." to include in what will be committed)
> +	dir1/untracked
> +	dir2/modified
> +	dir2/untracked
> +	untracked
> +
> +EOF
>  	git status >output &&
> -	test_cmp expect output &&
> +	test_cmp expect-modified-gitmodules output &&
>  	git config -f .gitmodules  --remove-section submodule.subname
>  '

That another giant snapshot makes me a bit wary, since it's harder to tell whether the "modifed .gitmodules" and "unmodified .gitmodules" are really checking the same things, but there might not be a way around it. The following tests check various combinations of values (dirty, untracked, etc) and sources "--ignore-submodules", ".git/config ignore=" and ".gitmodules ignore=". For the .gitmodules tests, we really do have to modify .gitmodules to test that it gives us the behavior we want.

As a hack, we could preemptively modify .gitmodules, so that it's modified in all of the snapshots we're diffing. That feels too hacky to me, but maybe others think it's fine.

(Side note: I recall a previous conversation with Junio about how we shouldn't be changing behavior based on .gitmodules. If we had that, we wouldn't need to worry about this right now.)

Previous: Calvin WanNext: Calvin Wan
Message 34 of 40 in “add: block invalid submodules”
  1. 0/6 add: block invalid submodulesCalvin Wan, Feb 13, 2023
  2. 1/6 leak fix: cache_put_pathCalvin Wan, Feb 13, 2023
  3. Junio C HamanoFeb 13, 2023
  4. Calvin WanFeb 14, 2023
  5. Junio C HamanoFeb 14, 2023
  6. Calvin WanFeb 14, 2023
  7. Junio C HamanoFeb 14, 2023
  8. 3/6 tests: Use `git submodule add` instead of `git add`Calvin Wan, Feb 13, 2023
  9. 4/6 tests: use `git submodule add` and fix expected diffsCalvin Wan, Feb 13, 2023
  10. Junio C HamanoFeb 13, 2023
  11. Junio C HamanoFeb 13, 2023
  12. 5/6 tests: use `git submodule add` and fix expected statusCalvin Wan, Feb 13, 2023
  13. 6/6 add: reject nested repositoriesCalvin Wan, Feb 13, 2023
  14. Jeff KingFeb 13, 2023
  15. Junio C HamanoFeb 14, 2023
  16. Jeff KingFeb 14, 2023
  17. Junio C HamanoFeb 14, 2023
  18. Calvin WanFeb 14, 2023
  19. 2/6 t4041, t4060: modernize test styleCalvin Wan, Feb 13, 2023
  20. Junio C HamanoFeb 13, 2023
  21. Calvin WanFeb 14, 2023
  22. 0/6 add: block invalid submodulesCalvin Wan, Feb 28, 2023
  23. 1/6 t4041, t4060: modernize test styleCalvin Wan, Feb 28, 2023
  24. Glen ChooMar 6, 2023
  25. Calvin WanMar 6, 2023
  26. 2/6 tests: Use `git submodule add` instead of `git add`Calvin Wan, Feb 28, 2023
  27. Junio C HamanoFeb 28, 2023
  28. Calvin WanMar 3, 2023
  29. Glen ChooMar 6, 2023
  30. 3/6 tests: use `git submodule add` and fix expected diffsCalvin Wan, Feb 28, 2023
  31. Glen ChooMar 6, 2023
  32. Junio C HamanoMar 6, 2023
  33. 4/6 tests: use `git submodule add` and fix expected statusCalvin Wan, Feb 28, 2023
  34. Glen ChooMar 7, 2023
  35. 5/6 tests: remove duplicate .gitmodules pathCalvin Wan, Feb 28, 2023
  36. Junio C HamanoFeb 28, 2023
  37. Calvin WanMar 2, 2023
  38. Glen ChooMar 7, 2023
  39. 6/6 add: reject nested repositoriesCalvin Wan, Feb 28, 2023
  40. Glen ChooMar 7, 2023

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.