From dc012d277b0c666d01c5274a4bf5de73eaa50c5b Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 5 Jun 2021 11:26:26 -0700 Subject: [PATCH] bfg-ish: add some sanity checks on the specified repo Signed-off-by: Elijah Newren --- contrib/filter-repo-demos/bfg-ish | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/contrib/filter-repo-demos/bfg-ish b/contrib/filter-repo-demos/bfg-ish index db39385..7ccea86 100755 --- a/contrib/filter-repo-demos/bfg-ish +++ b/contrib/filter-repo-demos/bfg-ish @@ -174,6 +174,19 @@ class BFG_ish: help=("file path for Git repository to clean")) args = parser.parse_args() + + # Sanity check on args.repo + if not os.path.isdir(args.repo): + raise SystemExit("Repo not found: {}".format(os.fsdecode(args.repo))) + dirname, basename = os.path.split(args.repo) + if not basename: + dirname, basename = os.path.split(dirname) + if not dirname: + dirname = b'.' + if basename == b".git": + raise SystemExit("For non-bare repos, please specify the toplevel directory ({}) for repo" + .format(os.fsdecode(dirname))) + return args def convert_replace_text(self, filename):