Fix relative path compatibility for --replace-text and bfg_args.repo

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) <Buo.Ren.Lin@gmail.com>
[en: tweaked commit message to explain the problem]
Signed-off-by: Elijah Newren <newren@gmail.com>
pull/222/merge
林博仁(Buo-ren Lin) 3 years ago committed by Elijah Newren
parent 75e67bcd44
commit e732141363

@ -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__':

Loading…
Cancel
Save