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

Re: [PATCH v2 2/2] Teach read-tree the -n|--dry-run option

From
Junio C Hamano <gitster@pobox.com>
Date
May 25, 2011, 22:30 UTC
Message-ID
<7vaaea1kid.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4DDD6241.8070908@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
> Using this option tells read-tree to not update the index. That makes it
> possible to check if updating the index would be successful without
> changing anything. Using this option will silently ignore -u but still
> test if updating the work tree would succeed.

I'll reword the above to de-stress "the index" when I queue this patch, as this is not about the index anymore. Also I do not think you "silently ignore" the "-u" option. Don't you check what would happen when "-u" is given and checking out the merge result would overwrite the file in the working tree? In that scenario, "-u" actively participates in the dry-run check you implemented.

Show 21 quoted lines
> diff --git a/t/lib-read-tree.sh b/t/lib-read-tree.sh
> new file mode 100644
> index 0000000..435d19c
> --- /dev/null
> +++ b/t/lib-read-tree.sh
> @@ -0,0 +1,43 @@
> +#!/bin/sh
> +#
> +# Helper functions to check if read-tree would succeed/fail as expected with
> +# and without the dry-run option. They also test that the dry-run does not
> +# write the index and that together with -u it doesn't touch the work tree.
> +#
> ...
> +read_tree_u_must_succeed () {
> +    git ls-files -s >pre-dry-run &&
> +    git diff-files >pre-dry-run-wt &&
> +    git read-tree -n "$@" &&
> +    git ls-files -s >post-dry-run &&
> +    git diff-files >post-dry-run-wt &&
> +    test_cmp pre-dry-run post-dry-run &&
> +    test_cmp pre-dry-run-wt post-dry-run-wt &&

As the RHS of diff-files output that represent the working tree status indicates "contents indeterminate" with 0{40}, this comparison is the same as comparing what is in the index before and after the dry-run.

Show 11 quoted lines
> ...
> +read_tree_u_must_fail () {
> +    git ls-files -s >pre-dry-run &&
> +    git diff-files >pre-dry-run-wt &&
> +    test_must_fail git read-tree -n "$@" &&
> +    git ls-files -s >post-dry-run &&
> +    git diff-files >post-dry-run-wt &&
> +    test_cmp pre-dry-run post-dry-run &&
> +    test_cmp pre-dry-run-wt post-dry-run-wt &&
> +    test_must_fail git read-tree "$@"
> +}
Same here.  A few additions of -p will trivially fix them, though.
diff --git a/t/lib-read-tree.sh b/t/lib-read-tree.sh
index 435d19c..abc2c6f 100644
--- a/t/lib-read-tree.sh
+++ b/t/lib-read-tree.sh
@@ -22,10 +22,10 @@ read_tree_must_fail () {
 
 read_tree_u_must_succeed () {
     git ls-files -s >pre-dry-run &&
-    git diff-files >pre-dry-run-wt &&
+    git diff-files -p >pre-dry-run-wt &&
     git read-tree -n "$@" &&
     git ls-files -s >post-dry-run &&
-    git diff-files >post-dry-run-wt &&
+    git diff-files -p >post-dry-run-wt &&
     test_cmp pre-dry-run post-dry-run &&
     test_cmp pre-dry-run-wt post-dry-run-wt &&
     git read-tree "$@"
@@ -33,10 +33,10 @@ read_tree_u_must_succeed () {
 
 read_tree_u_must_fail () {
     git ls-files -s >pre-dry-run &&
-    git diff-files >pre-dry-run-wt &&
+    git diff-files -p >pre-dry-run-wt &&
     test_must_fail git read-tree -n "$@" &&
     git ls-files -s >post-dry-run &&
-    git diff-files >post-dry-run-wt &&
+    git diff-files -p >post-dry-run-wt &&
     test_cmp pre-dry-run post-dry-run &&
     test_cmp pre-dry-run-wt post-dry-run-wt &&
     test_must_fail git read-tree "$@"
Previous: Jens Lehmann
Message 7 of 7 in “unpack-trees: add the dry_run flag to unpack_trees_options”
  1. unpack-trees: add the dry_run flag to unpack_trees_optionsJens Lehmann, May 24, 2011
  2. Junio C HamanoMay 24, 2011
  3. 0/2 Teach read-tree the -n|--dry-run optionJens Lehmann, May 25, 2011
  4. 1/2 unpack-trees: add the dry_run flag to unpack_trees_optionsJens Lehmann, May 25, 2011
  5. Junio C HamanoMay 25, 2011
  6. 2/2 Teach read-tree the -n|--dry-run optionJens Lehmann, May 25, 2011
  7. Junio C HamanoMay 25, 2011

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.