From 66288296b22cbe925075cda5e1310780aabc1edf Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Fri, 23 Aug 2019 20:21:43 -0500 Subject: [PATCH 1/3] Add git coauthor command This adds a feature to add additional authors to the previous commit, this feature is supported by GitHub and GitLab and based on the format should be self-evident to anyone reading the commit message. --- Commands.md | 25 +++++++ bin/git-coauthor | 4 ++ etc/git-extras-completion.zsh | 6 ++ man/git-coauthor.1 | 42 ++++++++++++ man/git-coauthor.html | 121 ++++++++++++++++++++++++++++++++++ man/git-coauthor.md | 36 ++++++++++ man/git-extras.md | 1 + man/index.txt | 1 + 8 files changed, 236 insertions(+) create mode 100755 bin/git-coauthor create mode 100644 man/git-coauthor.1 create mode 100644 man/git-coauthor.html create mode 100644 man/git-coauthor.md diff --git a/Commands.md b/Commands.md index 26876b460..dfcbd7251 100644 --- a/Commands.md +++ b/Commands.md @@ -9,6 +9,7 @@ - [`git chore`](#git-featurerefactorbugchore) - [`git clear`](#git-clear) - [`git clear-soft`](#git-clear-soft) + - [`git coauthor`](#git-coauthor) - [`git commits-since`](#git-commits-since) - [`git contrib`](#git-contrib) - [`git count`](#git-count) @@ -347,6 +348,30 @@ Straight from the shell! git (master)> quit ``` +## git coauthor + +Add a co-author to the last commit + +```bash +$ git coauthor user user@email.com + +[master b62ceae] Add documentation files + Date: Sat Aug 17 17:33:53 2019 -0500 + 2 files changed, 145 insertions(+), 0 deletions(-) + create mode 100644 README.md + create mode 100644 CONTRIBUTING.md + + $ git log -1 + +commit b62ceae2685e6ece071f3c3754e9b77fd0a35c88 (HEAD -> master) +Author: user person +Date: Sat Aug 17 17:33:53 2019 -0500 + + Add documentation files + + Co-authored-by: user +``` + ## git commits-since List commits since `date` (defaults to "last week"): diff --git a/bin/git-coauthor b/bin/git-coauthor new file mode 100755 index 000000000..2d69a3790 --- /dev/null +++ b/bin/git-coauthor @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +old_message="$(git log --format=%B -n1)" +git commit --amend -m "$old_message" -m "Co-authored-by: $1 <$2>" diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index 713121050..0552eca42 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -196,6 +196,11 @@ _git-chore() { '(--remote -r)'{--remote,-r}'[setup remote tracking branch]' } +_git-coauthor() { + _arguments \ + ':co-author[co-author to add]' \ + ':co-author-email[email address of co-author to add]' +} _git-contrib() { _arguments \ @@ -441,6 +446,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \ chore:'create chore branch' \ clear-soft:'soft clean up a repository' \ clear:'rigorously clean up a repository' \ + coauthor: 'add a co-author to the last commit' \ commits-since:'show commit logs since some date' \ contrib:'show user contributions' \ count:'show commit count' \ diff --git a/man/git-coauthor.1 b/man/git-coauthor.1 new file mode 100644 index 000000000..9e8acf424 --- /dev/null +++ b/man/git-coauthor.1 @@ -0,0 +1,42 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "GIT\-COAUTHOR" "1" "August 2019" "" "Git Extras" +. +.SH "NAME" +\fBgit\-coauthor\fR \- Add a co\-author to the last commit +. +.SH "SYNOPSIS" +\fBgit\-coauthor\fR +. +.SH "DESCRIPTION" +Add a co\-author to the last commit +. +.SH "OPTIONS" + +. +.P +The username of the co\-author you want to add\. +. +.P + +. +.P +The email address of the author you want to add\. +. +.SH "EXAMPLES" +. +.nf + +$ git coauthor user user@email\.com +. +.fi +. +.SH "AUTHOR" +Written by Jacob Herrington \fIjacobherringtondeveloper@gmail\.com\fR +. +.SH "REPORTING BUGS" +<\fIhttps://github\.com/tj/git\-extras/issues\fR> +. +.SH "SEE ALSO" +<\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-coauthor.html b/man/git-coauthor.html new file mode 100644 index 000000000..f7a7ac71e --- /dev/null +++ b/man/git-coauthor.html @@ -0,0 +1,121 @@ + + + + + + git-coauthor(1) - Add a co-author to the last commit + + + + +
+ + + +
    +
  1. git-coauthor(1)
  2. +
  3. Git Extras
  4. +
  5. git-coauthor(1)
  6. +
+ +

NAME

+

+ git-coauthor - Add a co-author to the last commit +

+ +

SYNOPSIS

+ +

git-coauthor <co-author> <co-author-email>

+ +

DESCRIPTION

+ +

Add a co-author to the last commit

+ +

OPTIONS

+ +

<co-author>

+ +

The username of the co-author you want to add.

+ +

<co-author-email>

+ +

The email address of the author you want to add.

+ +

EXAMPLES

+ +
$ git coauthor user user@email.com
+
+ +

AUTHOR

+ +

Written by Jacob Herrington jacobherringtondeveloper@gmail.com

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. August 2019
  3. +
  4. git-coauthor(1)
  5. +
+ +
+ + diff --git a/man/git-coauthor.md b/man/git-coauthor.md new file mode 100644 index 000000000..15d8181ae --- /dev/null +++ b/man/git-coauthor.md @@ -0,0 +1,36 @@ +git-coauthor(1) -- Add a co-author to the last commit +================================ + +## SYNOPSIS + +`git-coauthor` <co-author> <co-author-email> + +## DESCRIPTION + + Add a co-author to the last commit + +## OPTIONS + + <co-author> + + The username of the co-author you want to add. + + <co-author-email> + + The email address of the author you want to add. + +## EXAMPLES + + $ git coauthor user user@email.com + +## AUTHOR + +Written by Jacob Herrington + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> diff --git a/man/git-extras.md b/man/git-extras.md index ab09ec63b..788653dfc 100644 --- a/man/git-extras.md +++ b/man/git-extras.md @@ -31,6 +31,7 @@ git-extras(1) -- Awesome GIT utilities - **git-chore(1)** Create chore branch - **git-clear-soft(1)** Soft clean up a repository - **git-clear(1)** Rigorously clean up a repository + - **git-coauthor(1)** Add a co-author to the last commit - **git-commits-since(1)** Show commit logs since some date - **git-contrib(1)** Show user's contributions - **git-count(1)** Show commit count diff --git a/man/index.txt b/man/index.txt index e90c14c02..f4ab5c021 100644 --- a/man/index.txt +++ b/man/index.txt @@ -9,6 +9,7 @@ git-changelog(1) git-changelog git-chore(1) git-chore git-clear-soft(1) git-clear-soft git-clear(1) git-clear +git-coauthor(1) git-coauthor git-commits-since(1) git-commits-since git-contrib(1) git-contrib git-count(1) git-count From 3484df9ca4c3a297cbe6b4581189aad45a4f6709 Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Fri, 23 Aug 2019 20:30:18 -0500 Subject: [PATCH 2/3] Ensure arguments exist --- bin/git-coauthor | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/git-coauthor b/bin/git-coauthor index 2d69a3790..a13f4562b 100755 --- a/bin/git-coauthor +++ b/bin/git-coauthor @@ -1,4 +1,10 @@ #!/usr/bin/env bash +coauthor=$1 +email=$2 + +test -z $coauthor && echo "co-author required." 1>&2 && exit 1 +test -z $email && echo "co-author email required." 1>&2 && exit 1 + old_message="$(git log --format=%B -n1)" -git commit --amend -m "$old_message" -m "Co-authored-by: $1 <$2>" +git commit --amend -m "$old_message" -m "Co-authored-by: $coauthor <$email>" From 55cefa9021f72191faf7193ac156f0021d22b9b6 Mon Sep 17 00:00:00 2001 From: jacobherrington Date: Sun, 25 Aug 2019 11:43:08 -0500 Subject: [PATCH 3/3] Add conditional logic for linebreaks --- bin/git-coauthor | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/git-coauthor b/bin/git-coauthor index a13f4562b..522f2db80 100755 --- a/bin/git-coauthor +++ b/bin/git-coauthor @@ -1,10 +1,17 @@ #!/usr/bin/env bash +set -e -o pipefail + coauthor=$1 email=$2 -test -z $coauthor && echo "co-author required." 1>&2 && exit 1 -test -z $email && echo "co-author email required." 1>&2 && exit 1 +test -z "$coauthor" && echo "co-author required." 1>&2 && exit 1 +test -z "$email" && echo "co-author email required." 1>&2 && exit 1 old_message="$(git log --format=%B -n1)" -git commit --amend -m "$old_message" -m "Co-authored-by: $coauthor <$email>" +if [[ $old_message == *"Co-authored-by:"* ]]; then + git commit --amend -m "$old_message +Co-authored-by: $coauthor <$email>" +else + git commit --amend -m "$old_message" -m "Co-authored-by: $coauthor <$email>" +fi