Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/ext/lint-staged/gitWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type gitWorkflow struct {
allowEmpty bool
diff string
diffFilter string
breakReason string
logger *slog.Logger

partiallyStagedFiles []string
Expand Down Expand Up @@ -59,6 +60,10 @@ var gitDiffArgs = []string{
}
var gitApplyArgs = []string{"-v", "--whitespace=nowarn", "--recount", "--unidiff-zero"}

func (g *gitWorkflow) prepareOK() (bool, string) {
return g.breakReason != "", g.breakReason
}

// Create a diff of partially staged files and backup stash if enabled.
//
// will set state.hasPartiallyStagedFiles
Expand Down Expand Up @@ -109,6 +114,12 @@ func (g *gitWorkflow) prepare(state *State) (err error) {
if err != nil {
return ee.Wrap(err, "cannot create stash")
}

if hash == "" {
g.breakReason = "workspace is clean"
return nil
}

_, err = g.execGit("stash", "store", "--quiet", "--message", stashMessage, hash)
if err != nil {
return ee.Wrap(err, "cannot save stash")
Expand Down
3 changes: 2 additions & 1 deletion internal/ext/lint-staged/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func runAll(options *Options) (*State, error) {
Run: func(callback tl.TaskCallback) error {
return gw.prepare(ctx)
},
PostRun: handleInternalError,
PostRun: handleInternalError,
BreakFlow: gw.prepareOK,
},
{
Title: "Hiding unstaged changes to partially staged files...",
Expand Down
7 changes: 6 additions & 1 deletion internal/lib/tl/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,21 @@ func (tl *TaskList) start(p *tea.Program) (result *Result) {
}

preventContinue := false
shouldBreak := false

for i, task := range tl.tasks {
if preventContinue {
if preventContinue || shouldBreak {
task.skip(p)
continue
}

taskResult := task.start(p)
result.SubResults[i] = taskResult

if task.BreakFlow != nil {
shouldBreak, _ = task.BreakFlow()
}

if taskResult.Error {
result.Error = true

Expand Down
3 changes: 3 additions & 0 deletions internal/lib/tl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ type Task struct {
PostRun func(result *Result)
Enable func() bool

// BreakFlow return true interrupts flow execution
BreakFlow func() (shouldBreak bool, reason string)

Options []OptionApplier

id string
Expand Down
Loading