From e6731225f80815d1f0808ebce175f390f4289c06 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 3 Sep 2018 12:10:49 -0700 Subject: [PATCH] filter-repo: allow importing into an empty repo Signed-off-by: Elijah Newren --- git-filter-repo | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/git-filter-repo b/git-filter-repo index 2e03a38..1643af7 100755 --- a/git-filter-repo +++ b/git-filter-repo @@ -1255,7 +1255,14 @@ def sanity_check(refs, is_bare): abort('{} does not match {}'.format(refname, origin_ref)) def get_refs(): - output = subprocess.check_output('git show-ref'.split()) + try: + output = subprocess.check_output('git show-ref'.split()) + except subprocess.CalledProcessError as e: + # If error code is 1, there just isn't any refs; i.e. bare repo. + # If error code is other than 1, some other error (e.g. not a git repo) + if e.returncode != 1: + raise SystemExit('fatal: {}'.format(e)) + output = '' return dict(reversed(x.split()) for x in output.splitlines()) def tweak_commit(args, commit):