Skip to content

Commit 05e3548

Browse files
committed
Merge branch 'rnd/add-report-dir-option'
Signed-off-by: Elijah Newren <[email protected]>
2 parents a8ed692 + e9d5ab3 commit 05e3548

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

git-filter-repo

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,12 @@ EXAMPLES
17581758
help=_("Analyze repository history and create a report that may be "
17591759
"useful in determining what to filter in a subsequent run. "
17601760
"Will not modify your repo."))
1761+
analyze.add_argument('--report-dir',
1762+
metavar='DIR_OR_FILE',
1763+
type=os.fsencode,
1764+
dest='report_dir',
1765+
help=_("Directory to write report, defaults to GIT_DIR/filter_repo/analysis,"
1766+
"refuses to run if exists, --force delete existing dir first."))
17611767

17621768
path = parser.add_argument_group(title=_("Filtering based on paths "
17631769
"(see also --filename-callback)"))
@@ -2647,15 +2653,25 @@ class RepoAnalyze(object):
26472653

26482654
@staticmethod
26492655
def run(args):
2650-
git_dir = GitUtils.determine_git_dir(b'.')
2656+
if args.report_dir:
2657+
reportdir = args.report_dir
2658+
else:
2659+
git_dir = GitUtils.determine_git_dir(b'.')
26512660

26522661
# Create the report directory as necessary
2653-
results_tmp_dir = os.path.join(git_dir, b'filter-repo')
2654-
if not os.path.isdir(results_tmp_dir):
2655-
os.mkdir(results_tmp_dir)
2656-
reportdir = os.path.join(results_tmp_dir, b"analysis")
2657-
if not args.force and os.path.isdir(reportdir):
2658-
shutil.rmtree(reportdir)
2662+
results_tmp_dir = os.path.join(git_dir, b'filter-repo')
2663+
if not os.path.isdir(results_tmp_dir):
2664+
os.mkdir(results_tmp_dir)
2665+
reportdir = os.path.join(results_tmp_dir, b"analysis")
2666+
2667+
if os.path.isdir(reportdir):
2668+
if args.force:
2669+
sys.stdout.write(_("Warning: Removing recursively: \"%s\"") % decode(reportdir))
2670+
shutil.rmtree(reportdir)
2671+
else:
2672+
sys.stdout.write(_("Error: dir already exists (use --force to delete): \"%s\"\n") % decode(reportdir))
2673+
sys.exit(1)
2674+
26592675
os.mkdir(reportdir)
26602676

26612677
# Gather the data we need

t/t9390-filter-repo.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,11 @@ test_expect_success C_LOCALE_OUTPUT '--analyze' '
723723
724724
git filter-repo --analyze &&
725725
726-
# It should work and overwrite report if run again
727-
git filter-repo --analyze &&
726+
# It should not work again without a --force
727+
test_must_fail git filter-repo --analyze &&
728+
729+
# With a --force, another run should succeed
730+
git filter-repo --analyze --force &&
728731
729732
test -d .git/filter-repo/analysis &&
730733
cd .git/filter-repo/analysis &&
@@ -825,6 +828,38 @@ test_expect_success C_LOCALE_OUTPUT '--analyze' '
825828
)
826829
'
827830

831+
test_expect_success C_LOCALE_OUTPUT '--analyze --report-dir' '
832+
setup_analyze_me &&
833+
(
834+
cd analyze_me &&
835+
836+
rm -rf .git/filter-repo &&
837+
git filter-repo --analyze --report-dir foobar &&
838+
839+
# It should not work again without a --force
840+
test_must_fail git filter-repo --analyze --report-dir foobar &&
841+
842+
# With a --force, though, it should overwrite
843+
git filter-repo --analyze --report-dir foobar --force &&
844+
845+
test ! -d .git/filter-repo/analysis &&
846+
test -d foobar &&
847+
848+
cd foobar &&
849+
850+
# Very simple tests because already tested above.
851+
test_path_is_file renames.txt &&
852+
test_path_is_file README &&
853+
test_path_is_file blob-shas-and-paths.txt &&
854+
test_path_is_file directories-all-sizes.txt &&
855+
test_path_is_file directories-deleted-sizes.txt &&
856+
test_path_is_file extensions-all-sizes.txt &&
857+
test_path_is_file extensions-deleted-sizes.txt &&
858+
test_path_is_file path-all-sizes.txt &&
859+
test_path_is_file path-deleted-sizes.txt
860+
)
861+
'
862+
828863
test_expect_success '--replace-text all options' '
829864
setup_analyze_me &&
830865
(

0 commit comments

Comments
 (0)