Skip to content

Commit 6e53c62

Browse files
committed
Use current branch if there's no master branch.
1 parent cb5d219 commit 6e53c62

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

const.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# coding: utf8
22

3+
REPO_URL = 'https://github.com/baijiangliang/year2018'
4+
35
GIT_EMAIL_CMD = 'git config --get user.email'
46
CHECK_GIT_DIR_CMD = 'git rev-parse --is-inside-work-tree'
57
GIT_COMMIT_SEPARATOR = 'git-commit-separator'
68
GIT_LOG_FORMAT = GIT_COMMIT_SEPARATOR + '%H%n%P%n%an%n%ae%n%at%n%s%n'
79
GIT_REMOTE_URL_CMD = 'git config --get remote.origin.url'
10+
GIT_BRANCH_CMD = 'git branch --list'
11+
812
COMMIT_WEIGHT = 16
913
PROJECT_WEIGHT = 64
1014
MAX_YEAR_DAY = 366
11-
REPO_URL = 'https://github.com/baijiangliang/year2018'

repository.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import util
99

1010
git_clone_tmpl = 'git clone {git_url}'
11-
git_log_tmpl = 'git log master --since="{begin}" --until="{end}" --format="{fmt}" --numstat'
11+
git_log_tmpl = 'git log {branch} --since="{begin}" --until="{end}" --format="{fmt}" --numstat'
1212
git_show_tmpl = 'git show {commit_id} --format="{fmt}"'
1313

1414
# If the commit stat exceeds limits in one commit, this commit will be considered as auto-generated
@@ -79,7 +79,14 @@ def __init__(self, git_url_or_path: str, ctx: util.DotDict):
7979
def parse_git_commits(self):
8080
""" Parse commits in the given time range. """
8181
os.chdir(self.git_dir)
82-
git_log_cmd = git_log_tmpl.format(begin=self.ctx.begin, end=self.ctx.end,
82+
# Use master branch if it exists
83+
branches = util.run(const.GIT_BRANCH_CMD).split('\n')
84+
branch = ''
85+
for line in branches:
86+
if line.strip() == 'master':
87+
branch = 'master'
88+
break
89+
git_log_cmd = git_log_tmpl.format(branch=branch, begin=self.ctx.begin, end=self.ctx.end,
8390
fmt=const.GIT_LOG_FORMAT)
8491
git_log = util.run(git_log_cmd)
8592
commit_logs = git_log.split(const.GIT_COMMIT_SEPARATOR)

0 commit comments

Comments
 (0)