mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
rename any commit
This commit is contained in:
parent
adc2529019
commit
76a27f417f
2
main.go
2
main.go
@ -40,7 +40,7 @@ func main() {
|
|||||||
fmt.Printf("%s\n", config.GetDefaultConfig())
|
fmt.Printf("%s\n", config.GetDefaultConfig())
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
appConfig, err := config.NewAppConfig("lazygit", version, commit, date, buildSource, debuggingFlag)
|
appConfig, err := config.NewAppConfig("lazygit", version, commit, date, buildSource, *debuggingFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,14 @@ import (
|
|||||||
type App struct {
|
type App struct {
|
||||||
closers []io.Closer
|
closers []io.Closer
|
||||||
|
|
||||||
Config config.AppConfigurer
|
Config config.AppConfigurer
|
||||||
Log *logrus.Entry
|
Log *logrus.Entry
|
||||||
OSCommand *commands.OSCommand
|
OSCommand *commands.OSCommand
|
||||||
GitCommand *commands.GitCommand
|
GitCommand *commands.GitCommand
|
||||||
Gui *gui.Gui
|
Gui *gui.Gui
|
||||||
Tr *i18n.Localizer
|
Tr *i18n.Localizer
|
||||||
Updater *updates.Updater // may only need this on the Gui
|
Updater *updates.Updater // may only need this on the Gui
|
||||||
|
DemonContext string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newProductionLogger(config config.AppConfigurer) *logrus.Logger {
|
func newProductionLogger(config config.AppConfigurer) *logrus.Logger {
|
||||||
@ -54,7 +55,7 @@ func newDevelopmentLogger(config config.AppConfigurer) *logrus.Logger {
|
|||||||
func newLogger(config config.AppConfigurer) *logrus.Entry {
|
func newLogger(config config.AppConfigurer) *logrus.Entry {
|
||||||
var log *logrus.Logger
|
var log *logrus.Logger
|
||||||
environment := "production"
|
environment := "production"
|
||||||
if config.GetDebug() {
|
if config.GetDebug() || os.Getenv("DEBUG") == "TRUE" {
|
||||||
environment = "development"
|
environment = "development"
|
||||||
log = newDevelopmentLogger(config)
|
log = newDevelopmentLogger(config)
|
||||||
} else {
|
} else {
|
||||||
@ -86,15 +87,21 @@ func NewApp(config config.AppConfigurer) (*App, error) {
|
|||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
app.Log = newLogger(config)
|
app.Log = newLogger(config)
|
||||||
app.OSCommand = commands.NewOSCommand(app.Log, config)
|
|
||||||
|
|
||||||
app.Tr = i18n.NewLocalizer(app.Log)
|
app.Tr = i18n.NewLocalizer(app.Log)
|
||||||
|
|
||||||
|
// if we are being called in 'demon' mode, we can just return here
|
||||||
|
app.DemonContext = os.Getenv("LAZYGIT_CONTEXT")
|
||||||
|
if app.DemonContext != "" {
|
||||||
|
return app, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
app.OSCommand = commands.NewOSCommand(app.Log, config)
|
||||||
|
|
||||||
app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr)
|
app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr)
|
app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand, app.Tr, app.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return app, err
|
return app, err
|
||||||
}
|
}
|
||||||
@ -106,9 +113,21 @@ func NewApp(config config.AppConfigurer) (*App, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) Run() error {
|
func (app *App) Run() error {
|
||||||
|
if app.DemonContext == "INTERACTIVE_REBASE" {
|
||||||
|
return app.Rebase()
|
||||||
|
}
|
||||||
|
|
||||||
return app.Gui.RunWithSubprocesses()
|
return app.Gui.RunWithSubprocesses()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) Rebase() error {
|
||||||
|
app.Log.Error("TEST")
|
||||||
|
|
||||||
|
ioutil.WriteFile(".git/rebase-merge/git-rebase-todo", []byte(os.Getenv("LAZYGIT_REBASE_TODO")), 0644)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Close closes any resources
|
// Close closes any resources
|
||||||
func (app *App) Close() error {
|
func (app *App) Close() error {
|
||||||
for _, closer := range app.closers {
|
for _, closer := range app.closers {
|
||||||
|
@ -9,9 +9,12 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mgutz/str"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/i18n"
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -68,13 +71,14 @@ type GitCommand struct {
|
|||||||
Worktree *gogit.Worktree
|
Worktree *gogit.Worktree
|
||||||
Repo *gogit.Repository
|
Repo *gogit.Repository
|
||||||
Tr *i18n.Localizer
|
Tr *i18n.Localizer
|
||||||
|
Config config.AppConfigurer
|
||||||
getGlobalGitConfig func(string) (string, error)
|
getGlobalGitConfig func(string) (string, error)
|
||||||
getLocalGitConfig func(string) (string, error)
|
getLocalGitConfig func(string) (string, error)
|
||||||
removeFile func(string) error
|
removeFile func(string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGitCommand it runs git commands
|
// NewGitCommand it runs git commands
|
||||||
func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer) (*GitCommand, error) {
|
func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer, config config.AppConfigurer) (*GitCommand, error) {
|
||||||
var worktree *gogit.Worktree
|
var worktree *gogit.Worktree
|
||||||
var repo *gogit.Repository
|
var repo *gogit.Repository
|
||||||
|
|
||||||
@ -104,6 +108,7 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer)
|
|||||||
Tr: tr,
|
Tr: tr,
|
||||||
Worktree: worktree,
|
Worktree: worktree,
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
|
Config: config,
|
||||||
getGlobalGitConfig: gitconfig.Global,
|
getGlobalGitConfig: gitconfig.Global,
|
||||||
getLocalGitConfig: gitconfig.Local,
|
getLocalGitConfig: gitconfig.Local,
|
||||||
removeFile: os.RemoveAll,
|
removeFile: os.RemoveAll,
|
||||||
@ -774,3 +779,62 @@ func (c *GitCommand) GenericMerge(commandType string, command string) error {
|
|||||||
gitCommand := fmt.Sprintf("git %s %s --%s", c.OSCommand.Platform.skipEditorArg, commandType, command)
|
gitCommand := fmt.Sprintf("git %s %s --%s", c.OSCommand.Platform.skipEditorArg, commandType, command)
|
||||||
return c.OSCommand.RunCommand(gitCommand)
|
return c.OSCommand.RunCommand(gitCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *GitCommand) InteractiveRebase(commits []*Commit, index int, action string) (*exec.Cmd, error) {
|
||||||
|
ex, err := os.Executable() // get the executable path for git to use
|
||||||
|
if err != nil {
|
||||||
|
ex = os.Args[0] // fallback to the first call argument if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
// assume for now they won't pick the bottom commit
|
||||||
|
c.Log.Warn(len(commits))
|
||||||
|
c.Log.Warn(index)
|
||||||
|
if len(commits) <= index+1 {
|
||||||
|
// TODO: support more than say 30 commits and ensure this logic is correct, and i18n
|
||||||
|
return nil, errors.New("You cannot interactive rebase onto the first commit")
|
||||||
|
}
|
||||||
|
|
||||||
|
todo := ""
|
||||||
|
for i, commit := range commits[0 : index+1] {
|
||||||
|
a := "pick"
|
||||||
|
if i == index {
|
||||||
|
a = action
|
||||||
|
}
|
||||||
|
todo += a + " " + commit.Sha + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
debug := "FALSE"
|
||||||
|
if c.OSCommand.Config.GetDebug() == true {
|
||||||
|
debug = "TRUE"
|
||||||
|
}
|
||||||
|
|
||||||
|
splitCmd := str.ToArgv(fmt.Sprintf("git rebase --interactive %s", commits[index+1].Sha))
|
||||||
|
|
||||||
|
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
|
||||||
|
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Env = append(
|
||||||
|
cmd.Env,
|
||||||
|
"LAZYGIT_CONTEXT=INTERACTIVE_REBASE",
|
||||||
|
"LAZYGIT_REBASE_TODO="+todo,
|
||||||
|
"DEBUG="+debug,
|
||||||
|
"LANG=en_US.UTF-8", // Force using EN as language
|
||||||
|
"LC_ALL=en_US.UTF-8", // Force using EN as language
|
||||||
|
"GIT_SEQUENCE_EDITOR="+ex,
|
||||||
|
)
|
||||||
|
|
||||||
|
if true {
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
outString := string(out)
|
||||||
|
c.Log.Info(outString)
|
||||||
|
if err != nil {
|
||||||
|
if len(outString) == 0 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, errors.New(outString)
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
@ -66,6 +66,7 @@ func newDummyGitCommand() *GitCommand {
|
|||||||
Log: newDummyLog(),
|
Log: newDummyLog(),
|
||||||
OSCommand: newDummyOSCommand(),
|
OSCommand: newDummyOSCommand(),
|
||||||
Tr: i18n.NewLocalizer(newDummyLog()),
|
Tr: i18n.NewLocalizer(newDummyLog()),
|
||||||
|
Config: newDummyAppConfig(),
|
||||||
getGlobalGitConfig: func(string) (string, error) { return "", nil },
|
getGlobalGitConfig: func(string) (string, error) { return "", nil },
|
||||||
getLocalGitConfig: func(string) (string, error) { return "", nil },
|
getLocalGitConfig: func(string) (string, error) { return "", nil },
|
||||||
removeFile: func(string) error { return nil },
|
removeFile: func(string) error { return nil },
|
||||||
|
@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/shibukawa/configdir"
|
"github.com/shibukawa/configdir"
|
||||||
@ -42,18 +43,22 @@ type AppConfigurer interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewAppConfig makes a new app config
|
// NewAppConfig makes a new app config
|
||||||
func NewAppConfig(name, version, commit, date string, buildSource string, debuggingFlag *bool) (*AppConfig, error) {
|
func NewAppConfig(name, version, commit, date string, buildSource string, debuggingFlag bool) (*AppConfig, error) {
|
||||||
userConfig, err := LoadConfig("config", true)
|
userConfig, err := LoadConfig("config", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if os.Getenv("DEBUG") == "TRUE" {
|
||||||
|
debuggingFlag = true
|
||||||
|
}
|
||||||
|
|
||||||
appConfig := &AppConfig{
|
appConfig := &AppConfig{
|
||||||
Name: "lazygit",
|
Name: "lazygit",
|
||||||
Version: version,
|
Version: version,
|
||||||
Commit: commit,
|
Commit: commit,
|
||||||
BuildDate: date,
|
BuildDate: date,
|
||||||
Debug: *debuggingFlag,
|
Debug: debuggingFlag,
|
||||||
BuildSource: buildSource,
|
BuildSource: buildSource,
|
||||||
UserConfig: userConfig,
|
UserConfig: userConfig,
|
||||||
AppState: &AppState{},
|
AppState: &AppState{},
|
||||||
|
@ -181,14 +181,17 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleRenameCommitEditor(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleRenameCommitEditor(g *gocui.Gui, v *gocui.View) error {
|
||||||
if gui.State.Panels.Commits.SelectedLine != 0 {
|
subProcess, err := gui.GitCommand.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLine, "reword")
|
||||||
return gui.createErrorPanel(g, gui.Tr.SLocalize("OnlyRenameTopCommit"))
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
if subProcess != nil {
|
||||||
gui.SubProcess = gui.GitCommand.PrepareCommitAmendSubProcess()
|
gui.SubProcess = subProcess
|
||||||
g.Update(func(g *gocui.Gui) error {
|
// g.Update(func(g *gocui.Gui) error {
|
||||||
|
// return gui.Errors.ErrSubProcess
|
||||||
|
// })
|
||||||
return gui.Errors.ErrSubProcess
|
return gui.Errors.ErrSubProcess
|
||||||
})
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func (gui *Gui) handleCreateRecentReposMenu(g *gocui.Gui, v *gocui.View) error {
|
|||||||
if err := os.Chdir(repo.path); err != nil {
|
if err := os.Chdir(repo.path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr)
|
newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr, gui.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user