Skip to content

Commit

Permalink
Merge branch 'jl/read-tree-m-dry-run'
Browse files Browse the repository at this point in the history
* jl/read-tree-m-dry-run:
  Teach read-tree the -n|--dry-run option
  unpack-trees: add the dry_run flag to unpack_trees_options
  • Loading branch information
Junio C Hamano committed May 31, 2011
2 parents 2951df7 + ea5070c commit efd02e9
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 143 deletions.
5 changes: 5 additions & 0 deletions Documentation/git-read-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ OPTIONS
trees that are not directly related to the current
working tree status into a temporary index file.

-n::
--dry-run::
Check if the command would error out, without updating the index
nor the files in the working tree for real.

-v::
Show the progress of checking files out.

Expand Down
3 changes: 2 additions & 1 deletion builtin/read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
PARSE_OPT_NONEG, exclude_per_directory_cb },
OPT_SET_INT('i', NULL, &opts.index_only,
"don't check the working tree after merging", 1),
OPT__DRY_RUN(&opts.dry_run, "don't update the index or the work tree"),
OPT_SET_INT(0, "no-sparse-checkout", &opts.skip_sparse_checkout,
"skip applying sparse checkout filter", 1),
OPT_SET_INT(0, "debug-unpack", &opts.debug_unpack,
Expand Down Expand Up @@ -219,7 +220,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
if (unpack_trees(nr_trees, t, &opts))
return 128;

if (opts.debug_unpack)
if (opts.debug_unpack || opts.dry_run)
return 0; /* do not write the index out */

/*
Expand Down
43 changes: 43 additions & 0 deletions t/lib-read-tree.sh
Original file line number Diff line number Diff line change
@@ -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_must_succeed () {
git ls-files -s >pre-dry-run &&
git read-tree -n "$@" &&
git ls-files -s >post-dry-run &&
test_cmp pre-dry-run post-dry-run &&
git read-tree "$@"
}

read_tree_must_fail () {
git ls-files -s >pre-dry-run &&
test_must_fail git read-tree -n "$@" &&
git ls-files -s >post-dry-run &&
test_cmp pre-dry-run post-dry-run &&
test_must_fail git read-tree "$@"
}

read_tree_u_must_succeed () {
git ls-files -s >pre-dry-run &&
git diff-files -p >pre-dry-run-wt &&
git read-tree -n "$@" &&
git ls-files -s >post-dry-run &&
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 "$@"
}

read_tree_u_must_fail () {
git ls-files -s >pre-dry-run &&
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 -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 "$@"
}
Loading

0 comments on commit efd02e9

Please sign in to comment.