From e732141363fc7848e6cdacfb908020b808c41c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=8D=9A=E4=BB=81=28Buo-ren=20Lin=29?= Date: Sat, 17 Apr 2021 14:46:03 +0800 Subject: [PATCH] Fix relative path compatibility for --replace-text and bfg_args.repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users could specify relative paths on the command line, and then also provide a directory other than '.' for the repo. Since we did an unconditional os.chdir() to move into the repo, that would invalidate the original relative paths. Fix that by changing the relative paths into absolute paths. Signed-off-by: ๆž—ๅšไป(Buo-ren Lin) [en: tweaked commit message to explain the problem] Signed-off-by: Elijah Newren --- contrib/filter-repo-demos/bfg-ish | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/filter-repo-demos/bfg-ish b/contrib/filter-repo-demos/bfg-ish index 29ae8f1..db39385 100755 --- a/contrib/filter-repo-demos/bfg-ish +++ b/contrib/filter-repo-demos/bfg-ish @@ -371,6 +371,7 @@ class BFG_ish: bfg_args = self.parse_options() preserve_refs = self.get_preservation_info(bfg_args.preserve_ref_tips) + work_dir = os.getcwd() os.chdir(bfg_args.repo) bfg_args.delete_files = java_to_fnmatch_glob(bfg_args.delete_files) bfg_args.delete_folders = java_to_fnmatch_glob(bfg_args.delete_folders) @@ -395,6 +396,9 @@ class BFG_ish: extra_args += ['--preserve-commit-hashes'] new_replace_file = None if bfg_args.replace_text: + if not os.path.isabs(bfg_args.replace_text): + bfg_args.replace_text = os.path.join(work_dir, bfg_args.replace_text) + new_replace_file = self.convert_replace_text(bfg_args.replace_text) rules = fr.FilteringOptions.get_replace_text(new_replace_file) self.replacement_rules = rules @@ -432,6 +436,9 @@ class BFG_ish: if not fr.GitUtils.is_repository_bare('.'): need_another_reset = True + if not os.path.isabs(os.fsdecode(bfg_args.repo)): + bfg_args.repo = os.fsencode(os.path.join(work_dir, os.fsdecode(bfg_args.repo))) + fr.RepoFilter.cleanup(bfg_args.repo, repack=True, reset=need_another_reset) if __name__ == '__main__':