summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorOrlando Maussa <orlando.maussa@gmail.com>2023-09-09 07:18:47 -0500
committerGitHub <noreply@github.com>2023-09-09 07:18:47 -0500
commitdb409fa69fe3a04ba99ab83cd2e2cac085827b30 (patch)
tree57c5d21f49b2ef3f5fc5721b69aeaebe2e944ac3 /pkg/commands
parentd7e2ca3f10b7e6d6a1fb87636408f1c0bee3d381 (diff)
Add coauthor (#2)
Add co-author to commits Add addCoAuthor command for commits - Implement the `addCoAuthor` command to add co-authors to commits. - Utilize suggestions helpers to populate author names from the suggestions list. - Added command to gui at `LocalCommitsController`. This commit introduces the `addCoAuthor` command, which allows users to easily add co-authors to their commits. The co-author names are populated from the suggestions list, minimizing the chances of user input errors. The co-authors are added using the Co-authored-by metadata format recognized by GitHub and GitLab.
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/commit.go16
-rw-r--r--pkg/commands/git_commands/rebase.go6
2 files changed, 22 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go
index 2f8446b1a..7a218e4e1 100644
--- a/pkg/commands/git_commands/commit.go
+++ b/pkg/commands/git_commands/commit.go
@@ -38,6 +38,22 @@ func (self *CommitCommands) SetAuthor(value string) error {
return self.cmd.New(cmdArgs).Run()
}
+// Add a commit's coauthor using Github/Gitlab Co-authored-by metadata. Value is expected to be of the form 'Name <Email>'
+func (self *CommitCommands) AddCoAuthor(sha string, value string) error {
+ message, err := self.GetCommitMessage(sha)
+ if err != nil {
+ return err
+ }
+
+ message = message + fmt.Sprintf("\nCo-authored-by: %s", value)
+
+ cmdArgs := NewGitCmd("commit").
+ Arg("--allow-empty", "--amend", "--only", "-m", message).
+ ToArgv()
+
+ return self.cmd.New(cmdArgs).Run()
+}
+
// ResetToCommit reset to commit
func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars []string) error {
cmdArgs := NewGitCmd("reset").Arg("--"+strength, sha).ToArgv()
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go
index 5732bc0d3..66adee2af 100644
--- a/pkg/commands/git_commands/rebase.go
+++ b/pkg/commands/git_commands/rebase.go
@@ -79,6 +79,12 @@ func (self *RebaseCommands) SetCommitAuthor(commits []*models.Commit, index int,
})
}
+func (self *RebaseCommands) AddCommitCoAuthor(commits []*models.Commit, index int, value string) error {
+ return self.GenericAmend(commits, index, func() error {
+ return self.commit.AddCoAuthor(commits[index].Sha, value)
+ })
+}
+
func (self *RebaseCommands) GenericAmend(commits []*models.Commit, index int, f func() error) error {
if models.IsHeadCommit(commits, index) {
// we've selected the top commit so no rebase is required