Skip to content

Commit 01b2534

Browse files
committed
fix: use env as package
1 parent 9dffc05 commit 01b2534

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package git
1+
package env
22

33
import (
44
"context"
@@ -21,10 +21,19 @@ func (g *ExecProvider) BranchStatus(ctx context.Context, dir string) (string, bo
2121
return "", false, err
2222
}
2323
branch := strings.TrimSpace(string(out))
24+
isGitDirty := checkGitDirty(ctx, dir)
25+
return branch, isGitDirty, nil
26+
}
2427

25-
diffErr := exec.CommandContext(ctx, "git", "-C", dir, "diff", "--quiet").Run()
26-
cachedErr := exec.CommandContext(ctx, "git", "-C", dir, "diff", "--cached", "--quiet").Run()
27-
dirty := diffErr != nil || cachedErr != nil
28-
29-
return branch, dirty, nil
28+
func checkGitDirty(ctx context.Context, repositoryDir string) bool {
29+
gitCmds := []*exec.Cmd{
30+
exec.CommandContext(ctx, "git", "-C", repositoryDir, "diff", "--quiet"),
31+
exec.CommandContext(ctx, "git", "-C", repositoryDir, "diff", "--cached", "--quiet"),
32+
}
33+
for _, cmd := range gitCmds {
34+
if err := cmd.Run(); err != nil {
35+
return true
36+
}
37+
}
38+
return false
3039
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package git
1+
package env
22

33
import (
44
"os"

internal/tooling/render/renderer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"io"
88
"os"
99

10-
"github.com/jgfranco17/delphi-cli/internal/tooling/git"
10+
"github.com/jgfranco17/delphi-cli/internal/tooling/env"
1111
"github.com/jgfranco17/delphi-cli/internal/tooling/model"
1212
)
1313

@@ -40,7 +40,7 @@ func New(opts Options) *StatusLine {
4040
if out == nil {
4141
out = os.Stdout
4242
}
43-
return newRenderer(out, git.NewExecProvider(), opts)
43+
return newRenderer(out, env.NewExecProvider(), opts)
4444
}
4545

4646
// GenerateFrom decodes JSON from r and renders the statusline.

0 commit comments

Comments
 (0)