Comments (6)
I followed those git commands to amend co-authors. Unfortunately did not work.
The co-authors did not get appended to the end. I had to copy pasta it into the message. Maybe the template does not apply on amend?
I agree we should not have this in git mob but I think it will be worked documented here how to amend a commit to add co-authors. I can see it being an issue which should have an easy to find solution.
from git-mob.
I started working on a prepare-commit-msg hook written in bash. (My team already relies on a bash prepare-commit-msg hook to insert a ticket number, so we need to combine two hooks into one)
Unlike the sample in node, this implementation only inserts co-authors that are not already present. You can amend a commit with a new set-of co-authors, and it will selectively append the new co-authors after the old co-authors. Tested only on macOS:
# https://github.com/findmypast-oss/git-mob/issues/17#issuecomment-754133882
append_git_mob_co_authors() {
local commit_file="$1"
if [[ "$commit_file" =~ "COMMIT_EDITMSG" ]]; then
local commit_author current_author co_authors missing_co_authors git_message git_comments
commit_author=$(git var GIT_AUTHOR_IDENT | grep -o '^.*>')
current_author="$(git config user.name) <$(git config user.email)>"
co_authors=$(git mob-print | grep '^Co-authored-by')
if [[ "$commit_author" != "$current_author" ]]; then
co_authors=$(echo "$co_authors"; echo "Co-authored-by: $current_author")
fi
commit_file_contents=$(cat "$commit_file")
missing_co_authors="$(comm -1 -3 <(echo "$commit_file_contents" | sort -u) <(echo "$co_authors" | sort -u))"
if [[ -n "$missing_co_authors" ]]; then
git_message=$(echo "$commit_file_contents" | sed '/^#/,$d')
git_comments=$(echo "$commit_file_contents" | sed -n '/^#/,$p')
echo "$git_message" > "$commit_file"
if ! echo "$git_message" | tail -n 1 | grep --quiet '^Co-authored-by'; then
echo -en "\n" >> "$commit_file"
fi
echo "${missing_co_authors}" >> "$commit_file"
echo "$git_comments" >> "$commit_file"
else
echo "git-mob co-author is already present"
fi
fi
}
append_git_mob_co_authors "$1" "$2"
(updated 2021-01-14 to fix a lil bug)
(updated 2021-05-28 to fix a big bug when using git commit --verbose
, and to skip altogether when rebasing or using commit --message
)
(updated 2021-10-15 to append the current user as a coauthor when they are amending a commit by a different author)
(updated 2021-11-09 to undo part of 2021-05-28 update. Do not skip when using commit --message
)
from git-mob.
I don't find it adds much value since this is easily possible with existing commands.
git mob <coauthors>
git commit --amend
If we increase the functionality with a git command, it can become a slippery slope for supporting more existing commands. Would rather keep git-mob's scope small and focused.
from git-mob.
Good catch, doesn't look like commit templates apply to amends. 😮
This should be solved for free if we switch over to a git hook (see #22). In the mean time feel free to document it somewhere visible.
from git-mob.
Thanks for sharing @jonsmithers
This would be good to add in as an alternative hook and we can list the options in the readme
from git-mob.
Perhaps it is worth having a command in Git Mob to replace the co-authors if there is a mistake.
So you would specify all the co-authors for that comment with a command like:
git mob --amend <co-authors>
It grabs the latest message (git log -1 --pretty=format:%B | cat
) and replaces any existing co-authors.
What are your thoughts about the above?
from git-mob.
Related Issues (20)
- The readme instructions on using precommit throws an error HOT 1
- Allow per repo `<repo>/.git-coauthors` file HOT 4
- Config for specifying the CWD for child process HOT 1
- GitMob handleResponse: "git config --get --global commit.template" HOT 2
- Support multiple git trailers
- Git Mob Core: search GitHub for users with free text HOT 1
- pre-commit configuration does not work as per the Readme HOT 1
- Ability to manage coauthors file from command line (update/delete)
- Extract code from bin directory into src directory HOT 1
- Distributed git-mob suggest-coauthors does not have proper line endings on osx HOT 2
- "git mob --installTemplate" should be optional HOT 1
- git mob and git mob-print commands are not found HOT 2
- Show co-authors when making a commit HOT 1
- Ability to add coauthors via GitHub usernames or issue/pull request urls HOT 3
- Great migration to TypeScript
- CI Improvement for suggested co-authors
- Include filter for suggest-coauthors command
- Make it easier to select co-author to pair with HOT 2
- Provide a message flag for git mob
- Only add co-author from GitHub when it's desired HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git-mob.