Skip to content

Commit db574a1

Browse files
committed
Fix missing advanced option _GIT_BRANCH
* Missed implementing _GIT_BRANCH. Implemented it for the CSV option, but will need to rethink how to handle the changelogs by branch option a bit. Might need a refactor
1 parent f95d1e7 commit db574a1

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export _GIT_MERGE_VIEW="exclusive"
307307
### Git Branch
308308
309309
You can set the variable `_GIT_BRANCH` to set the branch of the stats.
310-
Works with commands `--git-stats-by-branch` and `--csv-output-by-branch`.
310+
Works with command `--csv-output-by-branch` only currently.
311311
312312
```bash
313313
export _GIT_BRANCH="master"

git_py_stats/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def get_config() -> Dict[str, Union[str, int]]:
104104
- 'enable' to use the user's default merge view from the conf.
105105
Default is usually to show both regular and merge commits.
106106
- Any other value defaults to '--no-merges' currently.
107+
_GIT_BRANCH (str): Sets branch you want to target for some stats.
108+
Default is empty which falls back to the current branch you're on.
107109
_GIT_LIMIT (int): Limits the git log output. Defaults to 10.
108110
_GIT_LOG_OPTIONS (str): Additional git log options. Default is empty.
109111
_GIT_DAYS (int): Defines number of days for the heatmap. Default is empty.
@@ -124,10 +126,11 @@ def get_config() -> Dict[str, Union[str, int]]:
124126
- 'until' (str): Git command option for the end date.
125127
- 'pathspec' (str): Git command option for pathspec.
126128
- 'merges' (str): Git command option for merge commit view strategy.
129+
- 'branch' (str): Git branch name.
127130
- 'limit' (int): Git log output limit.
128131
- 'log_options' (str): Additional git log options.
129-
- 'sort_by' (str): Sort by field and sort direction (asc/desc).
130132
- 'days' (str): Number of days for the heatmap.
133+
- 'sort_by' (str): Sort by field and sort direction (asc/desc).
131134
- 'ignore_authors': (str): Any author(s) to ignore.
132135
- 'menu_theme' (str): Menu theme color.
133136
"""
@@ -173,6 +176,13 @@ def get_config() -> Dict[str, Union[str, int]]:
173176
else:
174177
config["merges"] = "--no-merges"
175178

179+
# _GIT_BRANCH
180+
git_branch: Optional[str] = os.environ.get("_GIT_BRANCH")
181+
if git_branch:
182+
config["branch"] = git_branch
183+
else:
184+
config["branch"] = ""
185+
176186
# _GIT_LIMIT
177187
git_limit: Optional[str] = os.environ.get("_GIT_LIMIT")
178188
if git_limit:

git_py_stats/generate_cmds.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,11 @@ def output_daily_stats_csv(config: Dict[str, Union[str, int]]) -> None:
451451
until = config.get("until", "")
452452
log_options = config.get("log_options", "")
453453
pathspec = config.get("pathspec", "")
454+
branch = config.get("branch", "")
454455
ignore_authors = config.get("ignore_authors", lambda _s: False)
455456

456-
branch = input("Enter branch name (leave empty for current branch): ")
457+
if not branch:
458+
branch = input("Enter branch name (leave empty for current branch): ")
457459

458460
# Original command:
459461
# git -c log.showSignature=false log ${_branch} --use-mailmap $_merges --numstat \

0 commit comments

Comments
 (0)