mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-13 22:17:05 +02:00
Add 'w' keybinding in files panel to commit as a WIP
If your git.skipHookPrefix is set to, say, WIP, in your config, then hitting 'w' in the files panel will bring up the commit message panel with 'WIP' pre-filled, so you just need to hit enter to confirm (or add some more to the message) in order to commit your changes with the --no-verify flag, meaning the pre-commit hook will be skipped
This commit is contained in:
parent
ab9fa291a8
commit
0d3a193ab5
@ -801,6 +801,7 @@ func TestGitCommandCommit(t *testing.T) {
|
|||||||
command func(string, ...string) *exec.Cmd
|
command func(string, ...string) *exec.Cmd
|
||||||
getGlobalGitConfig func(string) (string, error)
|
getGlobalGitConfig func(string) (string, error)
|
||||||
test func(*exec.Cmd, error)
|
test func(*exec.Cmd, error)
|
||||||
|
flags string
|
||||||
}
|
}
|
||||||
|
|
||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
@ -819,6 +820,7 @@ func TestGitCommandCommit(t *testing.T) {
|
|||||||
assert.NotNil(t, cmd)
|
assert.NotNil(t, cmd)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
},
|
},
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Commit without using gpg",
|
"Commit without using gpg",
|
||||||
@ -835,6 +837,24 @@ func TestGitCommandCommit(t *testing.T) {
|
|||||||
assert.Nil(t, cmd)
|
assert.Nil(t, cmd)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
},
|
},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Commit with --no-verify flag",
|
||||||
|
func(cmd string, args ...string) *exec.Cmd {
|
||||||
|
assert.EqualValues(t, "git", cmd)
|
||||||
|
assert.EqualValues(t, []string{"commit", "--no-verify", "-m", "test"}, args)
|
||||||
|
|
||||||
|
return exec.Command("echo")
|
||||||
|
},
|
||||||
|
func(string) (string, error) {
|
||||||
|
return "false", nil
|
||||||
|
},
|
||||||
|
func(cmd *exec.Cmd, err error) {
|
||||||
|
assert.Nil(t, cmd)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
},
|
||||||
|
"--no-verify",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Commit without using gpg with an error",
|
"Commit without using gpg with an error",
|
||||||
@ -851,6 +871,7 @@ func TestGitCommandCommit(t *testing.T) {
|
|||||||
assert.Nil(t, cmd)
|
assert.Nil(t, cmd)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
},
|
},
|
||||||
|
"",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -859,7 +880,7 @@ func TestGitCommandCommit(t *testing.T) {
|
|||||||
gitCmd := NewDummyGitCommand()
|
gitCmd := NewDummyGitCommand()
|
||||||
gitCmd.getGlobalGitConfig = s.getGlobalGitConfig
|
gitCmd.getGlobalGitConfig = s.getGlobalGitConfig
|
||||||
gitCmd.OSCommand.command = s.command
|
gitCmd.OSCommand.command = s.command
|
||||||
s.test(gitCmd.Commit("test"))
|
s.test(gitCmd.Commit("test", s.flags))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,6 +274,22 @@ func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return gui.refreshFiles()
|
return gui.refreshFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) handleWIPCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||||
|
skipHookPreifx := gui.Config.GetUserConfig().GetString("git.skipHookPrefix")
|
||||||
|
if skipHookPreifx == "" {
|
||||||
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("SkipHookPrefixNotConfigured"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := gui.renderString(g, "commitMessage", skipHookPreifx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := gui.getCommitMessageView().SetCursor(len(skipHookPreifx), 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.handleCommitPress(g, filesView)
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||||
if len(gui.stagedFiles()) == 0 && gui.State.WorkingTreeState == "normal" {
|
if len(gui.stagedFiles()) == 0 && gui.State.WorkingTreeState == "normal" {
|
||||||
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit"))
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit"))
|
||||||
|
@ -408,7 +408,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
|
|
||||||
if gui.getCommitMessageView() == nil {
|
if gui.getCommitMessageView() == nil {
|
||||||
// doesn't matter where this view starts because it will be hidden
|
// doesn't matter where this view starts because it will be hidden
|
||||||
if commitMessageView, err := g.SetView("commitMessage", 0, 0, width/2, height/2, 0); err != nil {
|
if commitMessageView, err := g.SetView("commitMessage", width, height, width*2, height*2, 0); err != nil {
|
||||||
if err.Error() != "unknown view" {
|
if err.Error() != "unknown view" {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -422,7 +422,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
|
|
||||||
if check, _ := g.View("credentials"); check == nil {
|
if check, _ := g.View("credentials"); check == nil {
|
||||||
// doesn't matter where this view starts because it will be hidden
|
// doesn't matter where this view starts because it will be hidden
|
||||||
if credentialsView, err := g.SetView("credentials", 0, 0, width/2, height/2, 0); err != nil {
|
if credentialsView, err := g.SetView("credentials", width, height, width*2, height*2, 0); err != nil {
|
||||||
if err.Error() != "unknown view" {
|
if err.Error() != "unknown view" {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.handleCommitPress,
|
Handler: gui.handleCommitPress,
|
||||||
Description: gui.Tr.SLocalize("CommitChanges"),
|
Description: gui.Tr.SLocalize("CommitChanges"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ViewName: "files",
|
||||||
|
Key: 'w',
|
||||||
|
Modifier: gocui.ModNone,
|
||||||
|
Handler: gui.handleWIPCommitPress,
|
||||||
|
Description: gui.Tr.SLocalize("commitChangesWithoutHook"),
|
||||||
}, {
|
}, {
|
||||||
ViewName: "files",
|
ViewName: "files",
|
||||||
Key: 'A',
|
Key: 'A',
|
||||||
|
@ -750,6 +750,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "CustomCommand",
|
ID: "CustomCommand",
|
||||||
Other: "Custom Command:",
|
Other: "Custom Command:",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "commitChangesWithoutHook",
|
||||||
|
Other: "commit changes without pre-commit hook",
|
||||||
|
}, &i18n.Message{
|
||||||
|
ID: "SkipHookPrefixNotConfigured",
|
||||||
|
Other: "You have not configured a commit message prefix for skipping hooks. Set `git.skipHookPrefix = 'WIP'` in your config",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user