Bug: LOC from multiple repos not averaged
juliusHuelsmann opened this issue · 1 comments
juliusHuelsmann commented
When I add multiple repos as command line arguments to git-fame
, their lines of code are not averaged because check_output
reports fatal: no such path [repo-name/path] in HEAD
in ~ line 287, _gitfame.py
.
Root of the bug: prefix_gitdir
is set if multiple repos are given, which joins the git directory to the fname
.
Example:
Setup
git clone git@github.com:casperdcl/git-fame.git
cd git-fame
python -m gitfame ../git-fame ../git-fame
Output
Total commits: 492
Total ctimes: 0
Total files: 0
Total loc: 0
| Author | loc | coms | fils | distribution |
|:-------------------------|------:|-------:|-------:|:----------------|
| Casper da Costa-Luis | 0 | 470 | 0 | 0.0/95.5/ 0.0 |
| Cory Carson (Salesforce) | 0 | 10 | 0 | 0.0/ 2.0/ 0.0 |
...
Desired output
Total ctimes: 1798
Total files: 31
Total loc: 4550
| Author | loc | coms | fils | distribution |
|:-------------------------|------:|-------:|-------:|:----------------|
| Casper da Costa-Luis | 4536 | 470 | 28 | 99.7/95.5/90.3 |
| Cory Carson (Salesforce) | 10 | 10 | 1 | 0.2/ 2.0/ 3.2 |
...
Environment
OS: Arch Linux
python version : Python 3.9.2
Patch which works for me
As I am unfamiliar with the code base and do not know why prefix_gitdir
is set, I did not open a PR for this. My version can be found here I am unsure if my solution is really a fix or if it causes other problems for different command line options. However, I attached the patch which fixes the issue for me below:
diff --git a/gitfame/_gitfame.py b/gitfame/_gitfame.py
index 59916e9..01ce6f7 100755
--- a/gitfame/_gitfame.py
+++ b/gitfame/_gitfame.py
@@ -279,14 +279,16 @@ def _get_auth_stats(
for fname in tqdm(file_list, desc=gitdir if prefix_gitdir else "Processing",
disable=silent_progress, unit="file"):
- if prefix_gitdir:
- fname = path.join(gitdir, fname)
try:
blame_out = check_output(
base_cmd + [branch, fname], stderr=subprocess.STDOUT)
except Exception as err:
getattr(log, "warn" if warn_binary else "debug")(fname + ':' + str(err))
continue
+
+ if prefix_gitdir:
+ fname = path.join(gitdir, fname)
+
log.log(logging.NOTSET, blame_out)
# Strip boundary messages,