From 34f54e9c253bc6b78f6795a221d301974726231b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Thu, 7 Oct 2021 20:37:20 +0200 Subject: [PATCH] handle missing commits (shallow clones) in git_version retrieving --- git_version.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/git_version.py b/git_version.py index 11009de..e6da79c 100644 --- a/git_version.py +++ b/git_version.py @@ -7,13 +7,14 @@ def get_history(commit: git.objects.commit.Commit, priority=0, depth=0) -> Dict: 'priority': priority, 'depth': depth }} - if len(commit.parents) == 0: - return commit_history - else: - commit_history.update(get_history(commit.parents[0], priority, depth+1)) - for parent in commit.parents[1:]: - commit_history.update(get_history(parent, priority+1, depth+1)) - return commit_history + try: + if len(commit.parents) > 0: + commit_history.update(get_history(commit.parents[0], priority, depth+1)) + for parent in commit.parents[1:]: + commit_history.update(get_history(parent, priority+1, depth+1)) + except ValueError: + pass + return commit_history def git_describe(commit: git.objects.commit.Commit):