Skip to content

Commit cf9fe2d

Browse files
authored
test(git-authors): add unit test (#1098)
1 parent c13ab52 commit cf9fe2d

9 files changed

+113
-101
lines changed

Diff for: .pytest.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
minversion = 7.4
33
addopts = -ra -q
44
testpaths = tests
5+
faulthandler_timeout = 5

Diff for: Commands.md

-2
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,6 @@ $ git squash HEAD~3 "Work on a feature"
953953
954954
Populates the file matching `authors|contributors -i` with the authors of commits, according to the number of commits per author.
955955
956-
Opens the file in `$EDITOR` when set.
957-
958956
See the ["MAPPING AUTHORS" section](https://git-scm.com/docs/git-shortlog#_mapping_authors) of **git-shortlog**(1) to coalesce together commits by the same person.
959957
960958
Updating AUTHORS file:

Diff for: bin/git-authors

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
LIST=false
44
NO_EMAIL=false
55
FILE=""
6-
EDITOR=$(git var GIT_EDITOR)
76

87
while [[ $# -gt 0 ]]; do
98
case $1 in
@@ -37,10 +36,10 @@ fi
3736
authors() {
3837
if $NO_EMAIL; then
3938
# email will be used to uniq authors.
40-
git shortlog -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++' \
39+
git shortlog HEAD -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++' \
4140
| awk -F'<' '{gsub(/ +$/, "", $1); print $1}'
4241
else
43-
git shortlog -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++'
42+
git shortlog HEAD -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++'
4443
fi
4544
}
4645

@@ -52,5 +51,4 @@ if $LIST; then
5251
authors
5352
else
5453
authors >> "$FILE"
55-
test -n "$EDITOR" && $EDITOR "$FILE"
5654
fi

Diff for: man/git-authors.1

+15-43
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,59 @@
1-
.\" generated with Ronn/v0.7.3
2-
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3-
.
4-
.TH "GIT\-AUTHORS" "1" "October 2017" "" "Git Extras"
5-
.
1+
.\" generated with Ronn-NG/v0.9.1
2+
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3+
.TH "GIT\-AUTHORS" "1" "November 2023" "" "Git Extras"
64
.SH "NAME"
75
\fBgit\-authors\fR \- Generate authors report
8-
.
96
.SH "SYNOPSIS"
107
\fBgit\-authors\fR [\-l, \-\-list] [\-\-no\-email]
11-
.
128
.SH "DESCRIPTION"
13-
Populates the file matching \fIauthors|contributors \-i\fR with the authors of commits, according to the number of commits per author\. Opens the file in \fB$EDITOR\fR when set\.
14-
.
9+
.TS
10+
allbox;
11+
Populates the file matching _authors contributors \-i_ with the authors of commits, according to the number of commits per author\.
12+
.TE
1513
.P
1614
See the "MAPPING AUTHORS" section of \fBgit\-shortlog\fR(1) to coalesce together commits by the same person\.
17-
.
1815
.SH "OPTIONS"
1916
\-l, \-\-list
20-
.
2117
.P
2218
Show authors\.
23-
.
2419
.P
2520
\-\-no\-email
26-
.
2721
.P
2822
Don\'t show authors\' email\.
29-
.
3023
.SH "EXAMPLES"
31-
.
32-
.TP
3324
Updating AUTHORS file:
34-
.
35-
.IP
25+
.IP "" 4
26+
.nf
3627
$ git authors
37-
.
38-
.TP
28+
.fi
29+
.IP "" 0
30+
.P
3931
Listing authors:
40-
.
41-
.IP
42-
$ git authors \-\-list
43-
.
4432
.IP "" 4
45-
.
4633
.nf
47-
34+
$ git authors \-\-list
4835
TJ Holowaychuk <tj@vision\-media\.ca>
4936
hemanth\.hm <hemanth\.hm@gmail\.com>
5037
Jonhnny Weslley <jw@jonhnnyweslley\.net>
5138
nickl\- <github@jigsoft\.co\.za>
5239
Leila Muhtasib <muhtasib@gmail\.com>
53-
.
5440
.fi
55-
.
5641
.IP "" 0
57-
58-
.
59-
.TP
42+
.P
6043
Listing authors without email:
61-
.
62-
.IP
63-
$ git authors \-\-list \-\-no\-email
64-
.
6544
.IP "" 4
66-
.
6745
.nf
68-
46+
$ git authors \-\-list \-\-no\-email
6947
TJ Holowaychuk
7048
hemanth\.hm
7149
Jonhnny Weslley
7250
nickl\-
7351
Leila Muhtasib
74-
.
7552
.fi
76-
.
7753
.IP "" 0
78-
79-
.
8054
.SH "AUTHOR"
8155
Written by Titus Wormer <\fItituswormer@gmail\.com\fR>
82-
.
8356
.SH "REPORTING BUGS"
8457
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
85-
.
8658
.SH "SEE ALSO"
8759
<\fIhttps://github\.com/tj/git\-extras\fR>

Diff for: man/git-authors.html

+31-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/git-authors.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ git-authors(1) -- Generate authors report
88
## DESCRIPTION
99

1010
Populates the file matching _authors|contributors -i_ with the authors of commits, according to the number of commits per author.
11-
Opens the file in **$EDITOR** when set.
1211

1312
See the "MAPPING AUTHORS" section of **git-shortlog**(1) to coalesce together commits by the same person.
1413

@@ -24,33 +23,27 @@ git-authors(1) -- Generate authors report
2423

2524
## EXAMPLES
2625

27-
* Updating AUTHORS file:
26+
Updating AUTHORS file:
2827

2928
$ git authors
3029

31-
* Listing authors:
30+
Listing authors:
3231

3332
$ git authors --list
34-
35-
```
3633
TJ Holowaychuk <[email protected]>
3734
hemanth.hm <[email protected]>
3835
Jonhnny Weslley <[email protected]>
3936
4037
Leila Muhtasib <[email protected]>
41-
```
4238

43-
* Listing authors without email:
39+
Listing authors without email:
4440

4541
$ git authors --list --no-email
46-
47-
```
4842
TJ Holowaychuk
4943
hemanth.hm
5044
Jonhnny Weslley
5145
nickl-
5246
Leila Muhtasib
53-
```
5447

5548
## AUTHOR
5649

Diff for: tests/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ def named_temp_repo(request):
2929
dirname = request.param
3030
repo = create_repo(dirname)
3131
init_repo_git_status(repo)
32-
return repo
32+
yield repo
33+
repo.teardown()

Diff for: tests/helper.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import os, subprocess, stat, shutil, tempfile, git
1+
import os, subprocess, shutil, tempfile
2+
from git import Repo
23

34
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
4-
GIT_EXTRAS_BIN = os.path.join(CURRENT_DIR, "..", "bin")
5-
GIT_EXTRAS_HELPER = os.path.join(CURRENT_DIR, "..", "helper")
6-
7-
def invoke_git_extras_command(name, *params):
8-
script = [os.path.join(GIT_EXTRAS_BIN, name), *params]
9-
print(f"Run the script \"{script}\"")
10-
return subprocess.run(script, capture_output=True)
5+
GIT_EXTRAS_BIN = os.path.abspath(os.path.join(CURRENT_DIR, "..", "bin"))
6+
GIT_EXTRAS_HELPER = os.path.abspath(os.path.join(CURRENT_DIR, "..", "helper"))
117

128
class TempRepository:
139
def __init__(self, repo_work_dir = None):
@@ -18,7 +14,7 @@ def __init__(self, repo_work_dir = None):
1814
repo_work_dir = os.path.join(self._system_tmpdir, repo_work_dir)
1915
self._cwd = repo_work_dir
2016
self._tempdirname = self._cwd[len(self._system_tmpdir) + 1:]
21-
self._git_repo = git.Repo.init(repo_work_dir, b="default")
17+
self._git_repo = Repo.init(repo_work_dir, b="default")
2218
self._files = []
2319

2420
def switch_cwd_under_repo(self):
@@ -69,12 +65,14 @@ def teardown(self):
6965

7066
def invoke_extras_command(self, name, *params):
7167
command_name = "git-" + name
72-
print(f"Invoke the git-extras command - {command_name}")
73-
return invoke_git_extras_command(command_name, *params)
68+
print(f"Invoke the git-extras command - {command_name} at {self._cwd}")
69+
script = [os.path.join(GIT_EXTRAS_BIN, command_name), *list(params)]
70+
print(f"Run the script \"{' '.join(script)}\"")
71+
return subprocess.run(script, capture_output=True)
7472

7573
def invoke_installed_extras_command(self, name, *params):
7674
command_name = "git-" + name
77-
print(f"Invoke the git-extras command - {command_name}")
75+
print(f"Invoke the git-extras command - {command_name} at {self._cwd}")
7876
origin_extras_command = os.path.join(GIT_EXTRAS_BIN, command_name)
7977
temp_extras_command = os.path.join(self._cwd, command_name)
8078
helpers = [
@@ -94,7 +92,9 @@ def invoke_installed_extras_command(self, name, *params):
9492
whole.extend(rest)
9593
whole.insert(0, first)
9694
t.write("\n".join(whole))
97-
print("Update file {temp_extras_command}:\n{t.read()}")
95+
print(f"Update file {temp_extras_command}")
9896
os.chmod(temp_extras_command, 0o775)
9997

100-
return subprocess.run([temp_extras_command, *params], capture_output=True)
98+
script = [temp_extras_command, *params]
99+
print(f"Run the script \"{script}\"")
100+
return subprocess.run(script, capture_output=True)

0 commit comments

Comments
 (0)