Skip to content

Commit 04b8fc7

Browse files
committed
fixup! wip
1 parent 88cdbdb commit 04b8fc7

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

pkg/app/daemon/daemon.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/fsmiamoto/git-todo-parser/todo"
1111
"github.com/jesseduffield/lazygit/pkg/commands/models"
1212
"github.com/jesseduffield/lazygit/pkg/common"
13+
"github.com/jesseduffield/lazygit/pkg/secureexec"
1314
"github.com/jesseduffield/lazygit/pkg/utils"
1415
"github.com/samber/lo"
1516
)
@@ -90,6 +91,15 @@ func getDaemonKind() DaemonKind {
9091
return DaemonKind(intValue)
9192
}
9293

94+
func getCommentChar() byte {
95+
cmd := secureexec.Command("git", "config", "--get", "--null", "core.commentChar")
96+
if output, err := cmd.Output(); err == nil && len(output) == 2 {
97+
return output[0]
98+
}
99+
100+
return '#'
101+
}
102+
93103
// An Instruction is a command to be run by lazygit in daemon mode.
94104
// It is serialized to json and passed to lazygit via environment variables
95105
type Instruction interface {
@@ -196,10 +206,10 @@ func (self *ChangeTodoActionsInstruction) SerializedInstructions() string {
196206
return serializeInstruction(self)
197207
}
198208

199-
func (self *ChangeTodoActionsInstruction) run(common *common.Common, commentChar byte) error {
209+
func (self *ChangeTodoActionsInstruction) run(common *common.Common) error {
200210
return handleInteractiveRebase(common, func(path string) error {
201211
for _, c := range self.Changes {
202-
if err := utils.EditRebaseTodo(path, c.Sha, todo.Pick, c.NewAction, commentChar); err != nil {
212+
if err := utils.EditRebaseTodo(path, c.Sha, todo.Pick, c.NewAction, getCommentChar()); err != nil {
203213
return err
204214
}
205215
}
@@ -231,9 +241,9 @@ func (self *MoveFixupCommitDownInstruction) SerializedInstructions() string {
231241
return serializeInstruction(self)
232242
}
233243

234-
func (self *MoveFixupCommitDownInstruction) run(common *common.Common, commentChar byte) error {
244+
func (self *MoveFixupCommitDownInstruction) run(common *common.Common) error {
235245
return handleInteractiveRebase(common, func(path string) error {
236-
return utils.MoveFixupCommitDown(path, self.OriginalSha, self.FixupSha, commentChar)
246+
return utils.MoveFixupCommitDown(path, self.OriginalSha, self.FixupSha, getCommentChar())
237247
})
238248
}
239249

@@ -255,9 +265,9 @@ func (self *MoveTodoUpInstruction) SerializedInstructions() string {
255265
return serializeInstruction(self)
256266
}
257267

258-
func (self *MoveTodoUpInstruction) run(common *common.Common, commentChar byte) error {
268+
func (self *MoveTodoUpInstruction) run(common *common.Common) error {
259269
return handleInteractiveRebase(common, func(path string) error {
260-
return utils.MoveTodoUp(path, self.Sha, todo.Pick, commentChar)
270+
return utils.MoveTodoUp(path, self.Sha, todo.Pick, getCommentChar())
261271
})
262272
}
263273

@@ -279,9 +289,9 @@ func (self *MoveTodoDownInstruction) SerializedInstructions() string {
279289
return serializeInstruction(self)
280290
}
281291

282-
func (self *MoveTodoDownInstruction) run(common *common.Common, commentChar byte) error {
292+
func (self *MoveTodoDownInstruction) run(common *common.Common) error {
283293
return handleInteractiveRebase(common, func(path string) error {
284-
return utils.MoveTodoDown(path, self.Sha, todo.Pick, commentChar)
294+
return utils.MoveTodoDown(path, self.Sha, todo.Pick, getCommentChar())
285295
})
286296
}
287297

pkg/commands/git_commands/rebase.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,21 @@ func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) e
241241
}
242242

243243
// EditRebaseTodo sets the action for a given rebase commit in the git-rebase-todo file
244-
func (self *RebaseCommands) EditRebaseTodo(commit *models.Commit, action todo.TodoCommand, commentChar byte) error {
244+
func (self *RebaseCommands) EditRebaseTodo(commit *models.Commit, action todo.TodoCommand) error {
245245
return utils.EditRebaseTodo(
246-
filepath.Join(self.dotGitDir, "rebase-merge/git-rebase-todo"), commit.Sha, commit.Action, action, commentChar)
246+
filepath.Join(self.dotGitDir, "rebase-merge/git-rebase-todo"), commit.Sha, commit.Action, action, self.getCommentChar())
247247
}
248248

249249
// MoveTodoDown moves a rebase todo item down by one position
250-
func (self *RebaseCommands) MoveTodoDown(commit *models.Commit, commentChar byte) error {
250+
func (self *RebaseCommands) MoveTodoDown(commit *models.Commit) error {
251251
fileName := filepath.Join(self.dotGitDir, "rebase-merge/git-rebase-todo")
252-
return utils.MoveTodoDown(fileName, commit.Sha, commit.Action, commentChar)
252+
return utils.MoveTodoDown(fileName, commit.Sha, commit.Action, self.getCommentChar())
253253
}
254254

255255
// MoveTodoDown moves a rebase todo item down by one position
256-
func (self *RebaseCommands) MoveTodoUp(commit *models.Commit, commentChar byte) error {
256+
func (self *RebaseCommands) MoveTodoUp(commit *models.Commit) error {
257257
fileName := filepath.Join(self.dotGitDir, "rebase-merge/git-rebase-todo")
258-
return utils.MoveTodoUp(fileName, commit.Sha, commit.Action, commentChar)
258+
return utils.MoveTodoUp(fileName, commit.Sha, commit.Action, self.getCommentChar())
259259
}
260260

261261
// SquashAllAboveFixupCommits squashes all fixup! commits above the given one
@@ -416,3 +416,11 @@ func getBaseShaOrRoot(commits []*models.Commit, index int) string {
416416
return "--root"
417417
}
418418
}
419+
420+
func (self *RebaseCommands) getCommentChar() byte {
421+
if commentString := self.config.GetCoreCommentChar(); len(commentString) == 1 {
422+
return commentString[0]
423+
}
424+
425+
return '#'
426+
}

pkg/gui/controllers/local_commits_controller.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ func secondaryPatchPanelUpdateOpts(c *ControllerCommon) *types.ViewUpdateOpts {
200200
return nil
201201
}
202202

203-
func (self *LocalCommitsController) squashDown(commit *models.Commit, commentChar byte) error {
203+
func (self *LocalCommitsController) squashDown(commit *models.Commit) error {
204204
if self.context().GetSelectedLineIdx() >= len(self.c.Model().Commits)-1 {
205205
return self.c.ErrorMsg(self.c.Tr.CannotSquashOrFixupFirstCommit)
206206
}
207207

208-
applied, err := self.handleMidRebaseCommand(todo.Squash, commit, commentChar)
208+
applied, err := self.handleMidRebaseCommand(todo.Squash, commit)
209209
if err != nil {
210210
return err
211211
}
@@ -225,12 +225,12 @@ func (self *LocalCommitsController) squashDown(commit *models.Commit, commentCha
225225
})
226226
}
227227

228-
func (self *LocalCommitsController) fixup(commit *models.Commit, commentChar byte) error {
228+
func (self *LocalCommitsController) fixup(commit *models.Commit) error {
229229
if self.context().GetSelectedLineIdx() >= len(self.c.Model().Commits)-1 {
230230
return self.c.ErrorMsg(self.c.Tr.CannotSquashOrFixupFirstCommit)
231231
}
232232

233-
applied, err := self.handleMidRebaseCommand(todo.Fixup, commit, commentChar)
233+
applied, err := self.handleMidRebaseCommand(todo.Fixup, commit)
234234
if err != nil {
235235
return err
236236
}
@@ -250,8 +250,8 @@ func (self *LocalCommitsController) fixup(commit *models.Commit, commentChar byt
250250
})
251251
}
252252

253-
func (self *LocalCommitsController) reword(commit *models.Commit, commentChar byte) error {
254-
applied, err := self.handleMidRebaseCommand(todo.Reword, commit, commentChar)
253+
func (self *LocalCommitsController) reword(commit *models.Commit) error {
254+
applied, err := self.handleMidRebaseCommand(todo.Reword, commit)
255255
if err != nil {
256256
return err
257257
}
@@ -305,8 +305,8 @@ func (self *LocalCommitsController) doRewordEditor() error {
305305
return nil
306306
}
307307

308-
func (self *LocalCommitsController) rewordEditor(commit *models.Commit, commentChar byte) error {
309-
midRebase, err := self.handleMidRebaseCommand(todo.Reword, commit, commentChar)
308+
func (self *LocalCommitsController) rewordEditor(commit *models.Commit) error {
309+
midRebase, err := self.handleMidRebaseCommand(todo.Reword, commit)
310310
if err != nil {
311311
return err
312312
}
@@ -325,8 +325,8 @@ func (self *LocalCommitsController) rewordEditor(commit *models.Commit, commentC
325325
}
326326
}
327327

328-
func (self *LocalCommitsController) drop(commit *models.Commit, commentChar byte) error {
329-
applied, err := self.handleMidRebaseCommand(todo.Drop, commit, commentChar)
328+
func (self *LocalCommitsController) drop(commit *models.Commit) error {
329+
applied, err := self.handleMidRebaseCommand(todo.Drop, commit)
330330
if err != nil {
331331
return err
332332
}
@@ -346,8 +346,8 @@ func (self *LocalCommitsController) drop(commit *models.Commit, commentChar byte
346346
})
347347
}
348348

349-
func (self *LocalCommitsController) edit(commit *models.Commit, commentChar byte) error {
350-
applied, err := self.handleMidRebaseCommand(todo.Edit, commit, commentChar)
349+
func (self *LocalCommitsController) edit(commit *models.Commit) error {
350+
applied, err := self.handleMidRebaseCommand(todo.Edit, commit)
351351
if err != nil {
352352
return err
353353
}
@@ -362,8 +362,8 @@ func (self *LocalCommitsController) edit(commit *models.Commit, commentChar byte
362362
})
363363
}
364364

365-
func (self *LocalCommitsController) pick(commit *models.Commit, commentChar byte) error {
366-
applied, err := self.handleMidRebaseCommand(todo.Pick, commit, commentChar)
365+
func (self *LocalCommitsController) pick(commit *models.Commit) error {
366+
applied, err := self.handleMidRebaseCommand(todo.Pick, commit)
367367
if err != nil {
368368
return err
369369
}
@@ -384,7 +384,7 @@ func (self *LocalCommitsController) interactiveRebase(action todo.TodoCommand) e
384384
// handleMidRebaseCommand sees if the selected commit is in fact a rebasing
385385
// commit meaning you are trying to edit the todo file rather than actually
386386
// begin a rebase. It then updates the todo file with that action
387-
func (self *LocalCommitsController) handleMidRebaseCommand(action todo.TodoCommand, commit *models.Commit, commentChar byte) (bool, error) {
387+
func (self *LocalCommitsController) handleMidRebaseCommand(action todo.TodoCommand, commit *models.Commit) (bool, error) {
388388
if !commit.IsTODO() {
389389
if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE {
390390
// If we are in a rebase, the only action that is allowed for
@@ -415,7 +415,7 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action todo.TodoComma
415415
false,
416416
)
417417

418-
if err := self.c.Git().Rebase.EditRebaseTodo(commit, action, commentChar); err != nil {
418+
if err := self.c.Git().Rebase.EditRebaseTodo(commit, action); err != nil {
419419
return false, self.c.Error(err)
420420
}
421421

@@ -424,7 +424,7 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action todo.TodoComma
424424
})
425425
}
426426

427-
func (self *LocalCommitsController) moveDown(commit *models.Commit, commentChar byte) error {
427+
func (self *LocalCommitsController) moveDown(commit *models.Commit) error {
428428
index := self.context().GetSelectedLineIdx()
429429
commits := self.c.Model().Commits
430430

@@ -443,7 +443,7 @@ func (self *LocalCommitsController) moveDown(commit *models.Commit, commentChar
443443
self.c.LogAction(self.c.Tr.Actions.MoveCommitDown)
444444
self.c.LogCommand(fmt.Sprintf("Moving commit %s down", commit.ShortSha()), false)
445445

446-
if err := self.c.Git().Rebase.MoveTodoDown(commit, commentChar); err != nil {
446+
if err := self.c.Git().Rebase.MoveTodoDown(commit); err != nil {
447447
return self.c.Error(err)
448448
}
449449
self.context().MoveSelectedLine(1)
@@ -466,7 +466,7 @@ func (self *LocalCommitsController) moveDown(commit *models.Commit, commentChar
466466
})
467467
}
468468

469-
func (self *LocalCommitsController) moveUp(commit *models.Commit, commentChar byte) error {
469+
func (self *LocalCommitsController) moveUp(commit *models.Commit) error {
470470
index := self.context().GetSelectedLineIdx()
471471
if index == 0 {
472472
return nil
@@ -481,7 +481,7 @@ func (self *LocalCommitsController) moveUp(commit *models.Commit, commentChar by
481481
false,
482482
)
483483

484-
if err := self.c.Git().Rebase.MoveTodoUp(self.c.Model().Commits[index], commentChar); err != nil {
484+
if err := self.c.Git().Rebase.MoveTodoUp(self.c.Model().Commits[index]); err != nil {
485485
return self.c.Error(err)
486486
}
487487
self.context().MoveSelectedLine(-1)

0 commit comments

Comments
 (0)