filter-repo: allow --dry-run and --debug to be used together

Prior to this commit, git-filter-repo could only be used with either the
--dry-run flag or the --debug flag, not both. When run in debug mode,
git-filter-repo expected to be able to read from the output stream,
which obviously isn't created when doing a dry run, so it stack traced
when it tried to use the non-existent output stream. This commit fixes
that bug with an equally simple sanity check for the existence of the
output stream when run in debug mode.

Signed-off-by: Karl Lenz <xorangekiller@gmail.com>
This commit is contained in:
Karl Lenz 2019-12-10 23:41:37 -05:00
parent 780c74b218
commit caf85b68ec
2 changed files with 28 additions and 1 deletions

View File

@ -3562,7 +3562,7 @@ class RepoFilter(object):
self._output = open(self._fe_filt, 'bw')
else:
self._output = self._fip.stdin
if self._args.debug:
if self._args.debug and not self._args.dry_run:
self._output = DualFileWriter(self._fip.stdin, self._output)
tmp = [decode(x) if isinstance(x, bytes) else x for x in fip_cmd]
print("[DEBUG] Running: {}".format(' '.join(tmp)))

View File

@ -444,6 +444,33 @@ test_expect_success '--dry-run' '
)
'
test_expect_success '--dry-run --debug' '
(
git clone file://"$(pwd)"/metasyntactic dry_run_debug &&
cd dry_run_debug &&
git filter-repo --path words --dry-run --debug &&
git show-ref | grep master >out &&
test_line_count = 2 out &&
awk "{print \$1}" out | uniq >out2 &&
test_line_count = 1 out2 &&
test $(git rev-list --count HEAD) = 3 &&
git cat-file --batch-check --batch-all-objects >all-objs &&
test_line_count = 19 all-objs &&
git log --format=%n --name-only | sort | uniq >filenames &&
test_line_count = 9 filenames &&
test_path_is_file .git/filter-repo/fast-export.original &&
grep "^commit " .git/filter-repo/fast-export.original >out &&
test_line_count = 3 out &&
test_path_is_file .git/filter-repo/fast-export.filtered &&
grep "^commit " .git/filter-repo/fast-export.filtered >out &&
test_line_count = 2 out
)
'
test_expect_success '--dry-run --stdin' '
(
git clone file://"$(pwd)"/metasyntactic dry_run_stdin &&