Skip to content

Commit 74dcbe5

Browse files
committed
feat: add support for coauthors on new commit
feat: add support for commit coauthors feat: add coauthor support to commit description feat: keep current message when adding co author feat: update copy to include coauthors binding feat: enhance commit message copy test: fix coauthor tests
1 parent ef75150 commit 74dcbe5

File tree

7 files changed

+39
-3
lines changed

7 files changed

+39
-3
lines changed

pkg/commands/git_commands/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (self *CommitCommands) AddCoAuthor(sha string, value string) error {
4545
return err
4646
}
4747

48-
message = message + fmt.Sprintf("\nCo-authored-by: %s", value)
48+
message = message + fmt.Sprintf("\n\nCo-authored-by: %s", value)
4949

5050
cmdArgs := NewGitCmd("commit").
5151
Arg("--allow-empty", "--amend", "--only", "-m", message).

pkg/config/user_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ type KeybindingSubmodulesConfig struct {
441441

442442
type KeybindingCommitMessageConfig struct {
443443
SwitchToEditor string `yaml:"switchToEditor"`
444+
AddCoAuthor string `yaml:"addCoAuthor"`
444445
}
445446

446447
// OSConfig contains config on the level of the os
@@ -830,6 +831,7 @@ func GetDefaultConfig() *UserConfig {
830831
},
831832
CommitMessage: KeybindingCommitMessageConfig{
832833
SwitchToEditor: "<c-o>",
834+
AddCoAuthor: "<c-e>",
833835
},
834836
},
835837
OS: OSConfig{},

pkg/gui/context/commit_message_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (self *CommitMessageContext) SetPanelState(
117117
map[string]string{
118118
"togglePanelKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.Universal.TogglePanel),
119119
"switchToEditorKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.SwitchToEditor),
120+
"addCoAuthorKeyBinding": keybindings.Label(self.c.UserConfig.Keybinding.CommitMessage.AddCoAuthor),
120121
})
121122
}
122123

pkg/gui/controllers/commit_description_controller.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func (self *CommitDescriptionController) GetKeybindings(opts types.KeybindingsOp
3939
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor),
4040
Handler: self.switchToEditor,
4141
},
42+
{
43+
Key: opts.GetKey(opts.Config.CommitMessage.AddCoAuthor),
44+
Handler: self.addCoAuthor,
45+
},
4246
}
4347

4448
return bindings
@@ -67,3 +71,16 @@ func (self *CommitDescriptionController) confirm() error {
6771
func (self *CommitDescriptionController) switchToEditor() error {
6872
return self.c.Helpers().Commits.SwitchToEditor()
6973
}
74+
75+
func (self *CommitDescriptionController) addCoAuthor() error {
76+
return self.c.Prompt(types.PromptOpts{
77+
Title: self.c.Tr.AddCoAuthorPromptTitle,
78+
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc(),
79+
HandleConfirm: func(value string) error {
80+
commitMessage := self.c.Helpers().Commits.JoinCommitMessageAndDescription()
81+
coAuthorString := commitMessage + "\nCo-authored-by: " + value
82+
self.c.Helpers().Commits.SetMessageAndDescriptionInView(coAuthorString)
83+
return nil
84+
},
85+
})
86+
}

pkg/gui/controllers/commit_message_controller.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts)
5050
Key: opts.GetKey(opts.Config.CommitMessage.SwitchToEditor),
5151
Handler: self.switchToEditor,
5252
},
53+
{
54+
Key: opts.GetKey(opts.Config.CommitMessage.AddCoAuthor),
55+
Handler: self.addCoAuthor,
56+
},
5357
}
5458

5559
return bindings
@@ -92,6 +96,19 @@ func (self *CommitMessageController) switchToEditor() error {
9296
return self.c.Helpers().Commits.SwitchToEditor()
9397
}
9498

99+
func (self *CommitMessageController) addCoAuthor() error {
100+
return self.c.Prompt(types.PromptOpts{
101+
Title: self.c.Tr.AddCoAuthorPromptTitle,
102+
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetAuthorsSuggestionsFunc(),
103+
HandleConfirm: func(value string) error {
104+
commitMessage := self.c.Helpers().Commits.JoinCommitMessageAndDescription()
105+
coAuthorString := commitMessage + "\nCo-authored-by: " + value
106+
self.c.Helpers().Commits.SetMessageAndDescriptionInView(coAuthorString)
107+
return nil
108+
},
109+
})
110+
}
111+
95112
func (self *CommitMessageController) handleCommitIndexChange(value int) error {
96113
currentIndex := self.context().GetSelectedIndex()
97114
newIndex := currentIndex + value

pkg/i18n/english.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ func EnglishTranslationSet() TranslationSet {
10001000
RebaseOptionsTitle: "Rebase options",
10011001
CommitSummaryTitle: "Commit summary",
10021002
CommitDescriptionTitle: "Commit description",
1003-
CommitDescriptionSubTitle: "Press {{.togglePanelKeyBinding}} to toggle focus, {{.switchToEditorKeyBinding}} to switch to editor",
1003+
CommitDescriptionSubTitle: "{{.togglePanelKeyBinding}} Toggle focus, {{.switchToEditorKeyBinding}} Open editor, {{.addCoAuthorKeyBinding}} Add author",
10041004
CommitDescriptionSubTitleNoSwitch: "Press {{.togglePanelKeyBinding}} to toggle focus",
10051005
LocalBranchesTitle: "Local branches",
10061006
SearchTitle: "Search",

pkg/integration/tests/commit/add_co_author.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ var AddCoAuthor = NewIntegrationTest(NewIntegrationTestArgs{
3333
})
3434

3535
t.Views().Main().ContainsLines(
36-
Contains("initial commit"),
3736
Contains("Co-authored-by: John Smith <[email protected]>"),
3837
)
3938
},

0 commit comments

Comments
 (0)