Skip to content

Commit aca812a

Browse files
committed
Resolve file paths to their absolute path, make error messages more succinct.
1 parent eca8f19 commit aca812a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

git_template_repo/git_template_repo.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
import subprocess
66
import sys
7+
import pathlib
78

89
from ._version import version as __version__
910

@@ -21,18 +22,25 @@ def make_call(*args, error_msg=None, suppress_output=True):
2122
print(error_msg)
2223
print("")
2324
print(e)
24-
raise e
25+
sys.exit()
2526

2627

2728
def is_sha1(sha):
2829
match = re.match(r'\b[0-9a-f]{40}\b', sha)
2930
return match is not None
3031

32+
def is_remote(location):
33+
if "https://" in location or "http://" in location or "ssh://" in location:
34+
return True
35+
return False
3136

3237
def execute(args):
3338
new_repo = args.new_repo
3439
template_repo = args.template_repo
3540

41+
if not is_remote(template_repo):
42+
template_repo = pathlib.Path(template_repo).resolve()
43+
3644
clone_dir = args.clone_dir
3745
new_root_branch = args.new_root
3846
no_clone = args.no_clone
@@ -48,7 +56,7 @@ def execute(args):
4856
suppress_output=False)
4957

5058
local_new = True
51-
if push_origin or "https://" in new_repo or "http://" in new_repo or "ssh://" in new_repo:
59+
if push_origin or is_remote(new_repo):
5260
local_new = False
5361

5462
if local_new:

tests/test_commands.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ def test_template_from_local_commit(self):
7171
self.assertIsDir(TEST_REPO_DIR_GIT)
7272
self.assertEqual(int(git_template_repo.make_call("git", "--git-dir", str(TEST_REPO_DIR_GIT), "rev-list", "--all", "--count")), 1)
7373

74+
def test_template_from_local_commit_relative_path(self):
75+
sha = git_template_repo.make_call("git", "rev-parse", "--verify", "HEAD").decode()[:-1]
76+
sys.argv = ["git-template-repo", str(TEST_REPO_DIR), ".", "--template-branch", sha]
77+
ret = git_template_repo.main()
78+
self.assertEqual(ret, 0)
79+
self.assertIsDir(TEST_REPO_DIR)
80+
self.assertIsDir(TEST_REPO_DIR_GIT)
81+
self.assertEqual(int(git_template_repo.make_call("git", "--git-dir", str(TEST_REPO_DIR_GIT), "rev-list", "--all", "--count")), 1)
82+
7483
def test_template_push(self):
7584
git_template_repo.make_call("git", "init", str(TEST_DIR), "--bare")
7685
self.assertIsDir(TEST_DIR)

0 commit comments

Comments
 (0)