Skip to content

Commit d20067d

Browse files
Fix error when running add and status commands on empty repo
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 280aebf commit d20067d

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

git_sim/git_sim_add.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def __init__(self, scene):
77
super().__init__(scene)
88
self.maxrefs = 2
99
self.hide_first_tag = True
10+
self.allow_no_commits = True
1011

1112
try:
1213
self.selected_branches.append(self.repo.active_branch.name)
@@ -40,10 +41,14 @@ def populate_zones(self, firstColumnFileNames, secondColumnFileNames, thirdColum
4041
if name == x.a_path:
4142
thirdColumnFileNames.add(x.a_path)
4243
secondColumnArrowMap[x.a_path] = Arrow(stroke_width=3, color=self.scene.fontColor)
43-
44-
for y in self.repo.index.diff("HEAD"):
45-
if "git-sim_media" not in y.a_path:
46-
thirdColumnFileNames.add(y.a_path)
44+
try:
45+
for y in self.repo.index.diff("HEAD"):
46+
if "git-sim_media" not in y.a_path:
47+
thirdColumnFileNames.add(y.a_path)
48+
except git.exc.BadName:
49+
for (y, _stage), entry in self.repo.index.entries.items():
50+
if "git-sim_media" not in y:
51+
thirdColumnFileNames.add(y)
4752

4853
for z in self.repo.untracked_files:
4954
if "git-sim_media" not in z:

git_sim/git_sim_base_command.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self, scene):
2323
self.hide_first_tag = False
2424
self.stop = False
2525
self.zone_title_offset = 2.6 if platform.system() == "Windows" else 2.6
26+
self.allow_no_commits = False
2627

2728
self.logo = ImageMobject(self.scene.args.logo)
2829
self.logo.width = 3
@@ -43,8 +44,14 @@ def execute(self):
4344

4445
def get_commits(self, start="HEAD"):
4546
if not self.numCommits:
46-
print("git-sim error: No commits in current Git repository.")
47-
sys.exit(1)
47+
if self.allow_no_commits:
48+
self.numCommits = self.defaultNumCommits
49+
self.commits = ["dark"]*5
50+
self.zone_title_offset = 2
51+
return
52+
else:
53+
print("git-sim error: No commits in current Git repository.")
54+
sys.exit(1)
4855

4956
try:
5057
self.commits = list(self.repo.iter_commits(start)) if self.numCommits == 1 else list(self.repo.iter_commits(start + "~" + str(self.numCommits) + "..." + start))
@@ -416,9 +423,14 @@ def populate_zones(self, firstColumnFileNames, secondColumnFileNames, thirdColum
416423
if "git-sim_media" not in x.a_path:
417424
secondColumnFileNames.add(x.a_path)
418425

419-
for y in self.repo.index.diff("HEAD"):
420-
if "git-sim_media" not in y.a_path:
421-
thirdColumnFileNames.add(y.a_path)
426+
try:
427+
for y in self.repo.index.diff("HEAD"):
428+
if "git-sim_media" not in y.a_path:
429+
thirdColumnFileNames.add(y.a_path)
430+
except git.exc.BadName:
431+
for (y, _stage), entry in self.repo.index.entries.items():
432+
if "git-sim_media" not in y:
433+
thirdColumnFileNames.add(y)
422434

423435
for z in self.repo.untracked_files:
424436
if "git-sim_media" not in z:

git_sim/git_sim_status.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def __init__(self, scene):
77
super().__init__(scene)
88
self.maxrefs = 2
99
self.hide_first_tag = True
10+
self.allow_no_commits = True
1011

1112
try:
1213
self.selected_branches.append(self.repo.active_branch.name)

0 commit comments

Comments
 (0)