mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
Merge pull request #1893 from JensPfeifle/reset_author
This commit is contained in:
commit
125e948d82
@ -96,6 +96,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
||||
<kbd>ctrl+k</kbd>: move commit up one
|
||||
<kbd>v</kbd>: paste commits (cherry-pick)
|
||||
<kbd>A</kbd>: amend commit with staged changes
|
||||
<kbd>a</kbd>: reset commit author
|
||||
<kbd>t</kbd>: revert commit
|
||||
<kbd>T</kbd>: tag commit
|
||||
<kbd>ctrl+l</kbd>: open log menu
|
||||
|
@ -85,6 +85,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
||||
<kbd>ctrl+k</kbd>: コミットを1つ上に移動
|
||||
<kbd>v</kbd>: コミットを貼り付け (cherry-pick)
|
||||
<kbd>A</kbd>: ステージされた変更でamendコミット
|
||||
<kbd>a</kbd>: reset commit author
|
||||
<kbd>t</kbd>: コミットをrevert
|
||||
<kbd>T</kbd>: タグを作成
|
||||
<kbd>ctrl+l</kbd>: ログメニューを開く
|
||||
|
@ -123,6 +123,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
||||
<kbd>ctrl+k</kbd>: verplaats commit 1 naar boven
|
||||
<kbd>v</kbd>: plak commits (cherry-pick)
|
||||
<kbd>A</kbd>: wijzig commit met staged veranderingen
|
||||
<kbd>a</kbd>: reset commit author
|
||||
<kbd>t</kbd>: commit ongedaan maken
|
||||
<kbd>T</kbd>: tag commit
|
||||
<kbd>ctrl+l</kbd>: open log menu
|
||||
|
@ -82,6 +82,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
||||
<kbd>ctrl+k</kbd>: przenieś commit 1 w górę
|
||||
<kbd>v</kbd>: wklej commity (przebieranie)
|
||||
<kbd>A</kbd>: popraw commit zmianami z poczekalni
|
||||
<kbd>a</kbd>: reset commit author
|
||||
<kbd>t</kbd>: odwróć commit
|
||||
<kbd>T</kbd>: tag commit
|
||||
<kbd>ctrl+l</kbd>: open log menu
|
||||
|
@ -125,6 +125,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
|
||||
<kbd>ctrl+k</kbd>: 上移提交
|
||||
<kbd>v</kbd>: 粘贴提交(拣选)
|
||||
<kbd>A</kbd>: 用已暂存的更改来修补提交
|
||||
<kbd>a</kbd>: reset commit author
|
||||
<kbd>t</kbd>: 还原提交
|
||||
<kbd>T</kbd>: 标签提交
|
||||
<kbd>ctrl+l</kbd>: 打开日志菜单
|
||||
|
@ -47,7 +47,7 @@ func Check() {
|
||||
if err != nil {
|
||||
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err)
|
||||
}
|
||||
fmt.Printf("\nCheatsheets are out of date. Please run `%s` at the project root and commit the changes\n", CommandToRun())
|
||||
fmt.Printf("\nCheatsheets are out of date. Please run `%s` at the project root and commit the changes. If you run the script and no keybindings files are updated as a result, try rebasing onto master and trying again.\n", CommandToRun())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,11 @@ func (self *CommitCommands) RewordLastCommit(message string) error {
|
||||
return self.cmd.New("git commit --allow-empty --amend --only -m " + self.cmd.Quote(message)).Run()
|
||||
}
|
||||
|
||||
// ResetAuthor resets the author of the topmost commit
|
||||
func (self *CommitCommands) ResetAuthor() error {
|
||||
return self.cmd.New("git commit --allow-empty --only --no-edit --amend --reset-author").Run()
|
||||
}
|
||||
|
||||
// ResetToCommit reset to commit
|
||||
func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars []string) error {
|
||||
return self.cmd.New(fmt.Sprintf("git reset --%s %s", strength, sha)).
|
||||
|
@ -62,6 +62,26 @@ func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index
|
||||
return self.PrepareInteractiveRebaseCommand(sha, todo, false), nil
|
||||
}
|
||||
|
||||
func (self *RebaseCommands) ResetCommitAuthor(commits []*models.Commit, index int) error {
|
||||
if index == 0 {
|
||||
// we've selected the top commit so no rebase is required
|
||||
return self.commit.ResetAuthor()
|
||||
}
|
||||
|
||||
err := self.BeginInteractiveRebaseForCommit(commits, index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// now the selected commit should be our head so we'll amend it with the new author
|
||||
err = self.commit.ResetAuthor()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.ContinueRebase()
|
||||
}
|
||||
|
||||
func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int) error {
|
||||
// we must ensure that we have at least two commits after the selected one
|
||||
if len(commits) <= index+2 {
|
||||
|
@ -242,6 +242,7 @@ type KeybindingCommitsConfig struct {
|
||||
MoveDownCommit string `yaml:"moveDownCommit"`
|
||||
MoveUpCommit string `yaml:"moveUpCommit"`
|
||||
AmendToCommit string `yaml:"amendToCommit"`
|
||||
ResetCommitAuthor string `yaml:"resetCommitAuthor"`
|
||||
PickCommit string `yaml:"pickCommit"`
|
||||
RevertCommit string `yaml:"revertCommit"`
|
||||
CherryPickCopy string `yaml:"cherryPickCopy"`
|
||||
@ -513,6 +514,7 @@ func GetDefaultConfig() *UserConfig {
|
||||
MoveDownCommit: "<c-j>",
|
||||
MoveUpCommit: "<c-k>",
|
||||
AmendToCommit: "A",
|
||||
ResetCommitAuthor: "a",
|
||||
PickCommit: "p",
|
||||
RevertCommit: "t",
|
||||
CherryPickCopy: "c",
|
||||
|
@ -121,6 +121,11 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
|
||||
Handler: self.checkSelected(self.amendTo),
|
||||
Description: self.c.Tr.LcAmendToCommit,
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Commits.ResetCommitAuthor),
|
||||
Handler: self.checkSelected(self.resetAuthor),
|
||||
Description: self.c.Tr.LcResetCommitAuthor,
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Commits.RevertCommit),
|
||||
Handler: self.checkSelected(self.revert),
|
||||
@ -418,6 +423,21 @@ func (self *LocalCommitsController) amendTo(commit *models.Commit) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) resetAuthor(commit *models.Commit) error {
|
||||
return self.c.Confirm(types.ConfirmOpts{
|
||||
Title: self.c.Tr.LcResetCommitAuthor,
|
||||
Prompt: self.c.Tr.SureResetCommitAuthor,
|
||||
HandleConfirm: func() error {
|
||||
self.c.LogAction(self.c.Tr.Actions.ResetCommitAuthor)
|
||||
if err := self.git.Rebase.ResetCommitAuthor(self.model.Commits, self.context().GetSelectedLineIdx()); err != nil {
|
||||
return self.c.Error(err)
|
||||
}
|
||||
|
||||
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) revert(commit *models.Commit) error {
|
||||
if commit.IsMerge() {
|
||||
return self.createRevertMergeCommitMenu(commit)
|
||||
|
@ -98,6 +98,8 @@ type TranslationSet struct {
|
||||
LcMoveUpCommit string
|
||||
LcEditCommit string
|
||||
LcAmendToCommit string
|
||||
LcResetCommitAuthor string
|
||||
SureResetCommitAuthor string
|
||||
LcRenameCommitEditor string
|
||||
NoCommitsThisBranch string
|
||||
Error string
|
||||
@ -529,6 +531,7 @@ type Actions struct {
|
||||
DropCommit string
|
||||
EditCommit string
|
||||
AmendCommit string
|
||||
ResetCommitAuthor string
|
||||
RevertCommit string
|
||||
CreateFixupCommit string
|
||||
SquashAllAboveFixupCommits string
|
||||
@ -713,6 +716,8 @@ func EnglishTranslationSet() TranslationSet {
|
||||
LcMoveUpCommit: "move commit up one",
|
||||
LcEditCommit: "edit commit",
|
||||
LcAmendToCommit: "amend commit with staged changes",
|
||||
LcResetCommitAuthor: "reset commit author",
|
||||
SureResetCommitAuthor: "The author field of this commit will be updated to match the configured user. This also renews the author timestamp. Continue?",
|
||||
LcRenameCommitEditor: "reword commit with editor",
|
||||
Error: "Error",
|
||||
LcSelectHunk: "select hunk",
|
||||
@ -1125,6 +1130,7 @@ func EnglishTranslationSet() TranslationSet {
|
||||
DropCommit: "Drop commit",
|
||||
EditCommit: "Edit commit",
|
||||
AmendCommit: "Amend commit",
|
||||
ResetCommitAuthor: "Reset commit author",
|
||||
RevertCommit: "Revert commit",
|
||||
CreateFixupCommit: "Create fixup commit",
|
||||
SquashAllAboveFixupCommits: "Squash all above fixup commits",
|
||||
|
@ -375,7 +375,7 @@ func generateSnapshot(dir string) (string, error) {
|
||||
// TODO: find a way to bring this back without breaking tests
|
||||
// `ls-remote origin`,
|
||||
`status`, // file tree
|
||||
`log --pretty=%B -p -1`, // log
|
||||
`log --pretty=%B|%an|%ae -p -1`, // log
|
||||
`tag -n`, // tags
|
||||
`stash list`, // stash
|
||||
`submodule foreach 'git status'`, // submodule status
|
||||
|
@ -0,0 +1 @@
|
||||
myfile2
|
@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
10
test/integration/resetAuthor/expected/repo/.git_keep/config
Normal file
10
test/integration/resetAuthor/expected/repo/.git_keep/config
Normal file
@ -0,0 +1,10 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
[user]
|
||||
email = Author2@example.com
|
||||
name = Author2
|
@ -0,0 +1 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
BIN
test/integration/resetAuthor/expected/repo/.git_keep/index
Normal file
BIN
test/integration/resetAuthor/expected/repo/.git_keep/index
Normal file
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
@ -0,0 +1,3 @@
|
||||
0000000000000000000000000000000000000000 291bcc7e708303b395f52245ec988ddbc985bae3 Author1 <Author1@example.com> 1651932821 +0200 commit (initial): myfile1
|
||||
291bcc7e708303b395f52245ec988ddbc985bae3 63aff3f0f54955ea149f9c2f3c07697b8864940d Author1 <Author1@example.com> 1651932821 +0200 commit: myfile2
|
||||
63aff3f0f54955ea149f9c2f3c07697b8864940d 0714eb875f11c56a2dc8c53c148889fe43602349 Author2 <Author2@example.com> 1651932824 +0200 commit (amend): myfile2
|
@ -0,0 +1,3 @@
|
||||
0000000000000000000000000000000000000000 291bcc7e708303b395f52245ec988ddbc985bae3 Author1 <Author1@example.com> 1651932821 +0200 commit (initial): myfile1
|
||||
291bcc7e708303b395f52245ec988ddbc985bae3 63aff3f0f54955ea149f9c2f3c07697b8864940d Author1 <Author1@example.com> 1651932821 +0200 commit: myfile2
|
||||
63aff3f0f54955ea149f9c2f3c07697b8864940d 0714eb875f11c56a2dc8c53c148889fe43602349 Author2 <Author2@example.com> 1651932824 +0200 commit (amend): myfile2
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
x•�Q
|
||||
Â0DýÎ)ö_�lºÝ¦ ¢GÙ&,t‰”z{ƒx¿fx0oR5[ ó¡íªà•SñÂË4kÌDŠ‘sÄ X&ZhÈLEÒœ<Û½îpûÂùW®ú{lzJÕ.];â<„Ž>xï:íwMÿ:{—uStÈ×5'
|
@ -0,0 +1,2 @@
|
||||
x•ŽK
|
||||
1]çÙ’î$=iÑ£äÓÁ�‰3ôöñ®ªxPðòÚÚÜ5‚;ô]DÇÉ:ˆž«)E¤2±×D–Äd*: µÅ]#dH9O2™`�M–}õˆÎKæJI>E±*>û}ÝõíÐçŸ\åÛ¶È)¯í¢�<°Å€ ��Qc÷ºüªö®ó"¨>dB„
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
0714eb875f11c56a2dc8c53c148889fe43602349
|
1
test/integration/resetAuthor/expected/repo/myfile1
Normal file
1
test/integration/resetAuthor/expected/repo/myfile1
Normal file
@ -0,0 +1 @@
|
||||
test1
|
1
test/integration/resetAuthor/expected/repo/myfile2
Normal file
1
test/integration/resetAuthor/expected/repo/myfile2
Normal file
@ -0,0 +1 @@
|
||||
test2
|
1
test/integration/resetAuthor/recording.json
Normal file
1
test/integration/resetAuthor/recording.json
Normal file
@ -0,0 +1 @@
|
||||
{"KeyEvents":[{"Timestamp":638,"Mod":0,"Key":256,"Ch":52},{"Timestamp":1406,"Mod":0,"Key":256,"Ch":97},{"Timestamp":2584,"Mod":0,"Key":256,"Ch":121},{"Timestamp":5654,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":117,"Height":83}]}
|
20
test/integration/resetAuthor/setup.sh
Normal file
20
test/integration/resetAuthor/setup.sh
Normal file
@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
cd $1
|
||||
|
||||
git init
|
||||
|
||||
git config user.email "Author1@example.com"
|
||||
git config user.name "Author1"
|
||||
|
||||
echo test1 > myfile1
|
||||
git add .
|
||||
git commit -am "myfile1"
|
||||
echo test2 > myfile2
|
||||
git add .
|
||||
git commit -am "myfile2"
|
||||
|
||||
git config user.email "Author2@example.com"
|
||||
git config user.name "Author2"
|
1
test/integration/resetAuthor/test.json
Normal file
1
test/integration/resetAuthor/test.json
Normal file
@ -0,0 +1 @@
|
||||
{ "description": "In this test the author of a commit is reset to a different name/email.", "speed": 5 }
|
Loading…
Reference in New Issue
Block a user