Skip to content

Commit

Permalink
feat(git-authors)!: no longer to support open the editor
Browse files Browse the repository at this point in the history
    * BREAKING CHANGE: remove behavior of opening authors with the default editor
    * test: add unit test
  • Loading branch information
vanpipy committed Nov 14, 2023
1 parent 59e362a commit 083d3f0
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 86 deletions.
2 changes: 0 additions & 2 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,6 @@ $ git squash HEAD~3 "Work on a feature"
Populates the file matching `authors|contributors -i` with the authors of commits, according to the number of commits per author.
Opens the file in `$EDITOR` when set.
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.
Updating AUTHORS file:
Expand Down
6 changes: 2 additions & 4 deletions bin/git-authors
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
LIST=false
NO_EMAIL=false
FILE=""
EDITOR=$(git var GIT_EDITOR)

while [[ $# -gt 0 ]]; do
case $1 in
Expand Down Expand Up @@ -37,10 +36,10 @@ fi
authors() {
if $NO_EMAIL; then
# email will be used to uniq authors.
git shortlog -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++' \
git shortlog HEAD -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++' \
| awk -F'<' '{gsub(/ +$/, "", $1); print $1}'
else
git shortlog -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++'
git shortlog HEAD -sne | awk '{$1=""; sub(" ", ""); print}' | awk -F'<' '!x[$1]++' | awk -F'<' '!x[$2]++'
fi
}

Expand All @@ -52,5 +51,4 @@ if $LIST; then
authors
else
authors >> "$FILE"
test -n "$EDITOR" && $EDITOR "$FILE"
fi
58 changes: 15 additions & 43 deletions man/git-authors.1
Original file line number Diff line number Diff line change
@@ -1,87 +1,59 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-AUTHORS" "1" "October 2017" "" "Git Extras"
.
.\" generated with Ronn-NG/v0.9.1
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
.TH "GIT\-AUTHORS" "1" "November 2023" "" "Git Extras"
.SH "NAME"
\fBgit\-authors\fR \- Generate authors report
.
.SH "SYNOPSIS"
\fBgit\-authors\fR [\-l, \-\-list] [\-\-no\-email]
.
.SH "DESCRIPTION"
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\.
.
.TS
allbox;
Populates the file matching _authors contributors \-i_ with the authors of commits, according to the number of commits per author\.
.TE
.P
See the "MAPPING AUTHORS" section of \fBgit\-shortlog\fR(1) to coalesce together commits by the same person\.
.
.SH "OPTIONS"
\-l, \-\-list
.
.P
Show authors\.
.
.P
\-\-no\-email
.
.P
Don\'t show authors\' email\.
.
.SH "EXAMPLES"
.
.TP
Updating AUTHORS file:
.
.IP
.IP "" 4
.nf
$ git authors
.
.TP
.fi
.IP "" 0
.P
Listing authors:
.
.IP
$ git authors \-\-list
.
.IP "" 4
.
.nf

$ git authors \-\-list
TJ Holowaychuk <tj@vision\-media\.ca>
hemanth\.hm <hemanth\.hm@gmail\.com>
Jonhnny Weslley <jw@jonhnnyweslley\.net>
nickl\- <github@jigsoft\.co\.za>
Leila Muhtasib <muhtasib@gmail\.com>
.
.fi
.
.IP "" 0

.
.TP
.P
Listing authors without email:
.
.IP
$ git authors \-\-list \-\-no\-email
.
.IP "" 4
.
.nf

$ git authors \-\-list \-\-no\-email
TJ Holowaychuk
hemanth\.hm
Jonhnny Weslley
nickl\-
Leila Muhtasib
.
.fi
.
.IP "" 0

.
.SH "AUTHOR"
Written by Titus Wormer <\fItituswormer@gmail\.com\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
58 changes: 31 additions & 27 deletions man/git-authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions man/git-authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ git-authors(1) -- Generate authors report
## DESCRIPTION

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

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

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

## EXAMPLES

* Updating AUTHORS file:
Updating AUTHORS file:

$ git authors

* Listing authors:
Listing authors:

$ git authors --list

```
TJ Holowaychuk <[email protected]>
hemanth.hm <[email protected]>
Jonhnny Weslley <[email protected]>
nickl- <[email protected]>
Leila Muhtasib <[email protected]>
```

* Listing authors without email:
Listing authors without email:

$ git authors --list --no-email
```
TJ Holowaychuk
hemanth.hm
Jonhnny Weslley
nickl-
Leila Muhtasib
```

## AUTHOR

Expand Down
45 changes: 45 additions & 0 deletions tests/test_authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os, subprocess

expected_authors_list = "test <[email protected]>\ntestagain <[email protected]>\n"
expected_authors_list_without_email = "test\ntestagain\n"
authors_file = "AUTHORS"

class TestGitAuthors:
def test_init(self, temp_repo):
git = temp_repo.get_repo_git()
tmp_file = temp_repo.get_file(0)
temp_repo.writefile(tmp_file, "A")
git.add(".")
git.commit("-m", "test: add data A")
git.config("--local", "user.name", "testagain")
git.config("--local", "user.email", "[email protected]")
temp_repo.writefile(tmp_file, "B")
git.add(".")
git.commit("-m", "test: add data B")

def test_output_authors_has_email_without_any_parameter(self, temp_repo):
git = temp_repo.get_repo_git()
rs = temp_repo.invoke_extras_command("authors")
with open(authors_file) as f:
content = f.read()
print(content)
print(expected_authors_list)
assert content == expected_authors_list

def test_list_authors_has_email_defaultly(self, temp_repo):
git = temp_repo.get_repo_git()
actual = temp_repo.invoke_extras_command("authors", "--list")
actual = actual.stdout.decode()
assert actual == expected_authors_list
actual = temp_repo.invoke_extras_command("authors", "-l")
actual = actual.stdout.decode()
assert actual == expected_authors_list

def test_list_authors_has_not_email(self, temp_repo):
git = temp_repo.get_repo_git()
actual = temp_repo.invoke_extras_command("authors", "--list", "--no-email")
actual = actual.stdout.decode()
assert actual == expected_authors_list_without_email
actual = temp_repo.invoke_extras_command("authors", "-l", "--no-email")
actual = actual.stdout.decode()
assert actual == expected_authors_list_without_email

0 comments on commit 083d3f0

Please sign in to comment.