summaryrefslogtreecommitdiffstats
path: root/pkg/app
diff options
context:
space:
mode:
authorAzraelSec <federicogerardi94@gmail.com>2023-03-29 00:49:19 +0200
committerJesse Duffield <jessedduffield@gmail.com>2023-04-15 17:26:08 +1000
commit368f9c8cb3d1f86d2a854cdfc20a8c87221e4087 (patch)
treebb2b3437cd82a9a88183a0c55650af275cd28c3e /pkg/app
parente18b4a4cc39e1f031936911910202b1925218117 (diff)
feat: let interactive rebase prepend commands to the default todo file
Diffstat (limited to 'pkg/app')
-rw-r--r--pkg/app/daemon/daemon.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/pkg/app/daemon/daemon.go b/pkg/app/daemon/daemon.go
index 182807b02..5490a25e5 100644
--- a/pkg/app/daemon/daemon.go
+++ b/pkg/app/daemon/daemon.go
@@ -29,6 +29,11 @@ const (
const (
DaemonKindEnvKey string = "LAZYGIT_DAEMON_KIND"
RebaseTODOEnvKey string = "LAZYGIT_REBASE_TODO"
+
+ // The `PrependLinesEnvKey` env variable is set to `true` to tell our daemon
+ // to prepend the content of `RebaseTODOEnvKey` to the default `git-rebase-todo`
+ // file instead of using it as a replacement.
+ PrependLinesEnvKey string = "LAZYGIT_PREPEND_LINES"
)
type Daemon interface {
@@ -74,12 +79,25 @@ type rebaseDaemon struct {
func (self *rebaseDaemon) Run() error {
self.c.Log.Info("Lazygit invoked as interactive rebase demon")
self.c.Log.Info("args: ", os.Args)
+ filePath := os.Args[1]
+
+ if strings.HasSuffix(filePath, "git-rebase-todo") {
+ todoEnvKey := os.Getenv(RebaseTODOEnvKey)
- if strings.HasSuffix(os.Args[1], "git-rebase-todo") {
- if err := os.WriteFile(os.Args[1], []byte(os.Getenv(RebaseTODOEnvKey)), 0o644); err != nil {
- return err
+ var todoContent []byte
+ if v := os.Getenv(PrependLinesEnvKey); v != "" {
+ existingContent, err := os.ReadFile(filePath)
+ if err != nil {
+ return err
+ }
+
+ todoContent = append([]byte(todoEnvKey), existingContent...)
+ } else {
+ todoContent = []byte(todoEnvKey)
}
- } else if strings.HasSuffix(os.Args[1], filepath.Join(gitDir(), "COMMIT_EDITMSG")) { // TODO: test
+
+ return os.WriteFile(filePath, todoContent, 0o644)
+ } else if strings.HasSuffix(filePath, filepath.Join(gitDir(), "COMMIT_EDITMSG")) { // TODO: test
// if we are rebasing and squashing, we'll see a COMMIT_EDITMSG
// but in this case we don't need to edit it, so we'll just return
} else {