Skip to content

Commit

Permalink
support muting of staging
Browse files Browse the repository at this point in the history
petar committed Mar 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3420b9e commit 6a6b923
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions git/git.go
Original file line number Diff line number Diff line change
@@ -111,6 +111,9 @@ func Worktree(ctx context.Context, repo *Repository) *Tree {
}

func Add(ctx context.Context, wt *Tree, path ns.NS) {
if IsStagingMuted(ctx) {
return
}
if _, err := wt.Add(path.GitPath()); err != nil {
must.Panic(ctx, err)
}
18 changes: 18 additions & 0 deletions git/mute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package git

import "context"

type muteStagingCtxKey struct{}

func MuteStaging(ctx context.Context) context.Context {
return context.WithValue(ctx, muteStagingCtxKey{}, true)
}

func UnmuteStaging(ctx context.Context) context.Context {
return context.WithValue(ctx, muteStagingCtxKey{}, false)
}

func IsStagingMuted(ctx context.Context) bool {
v, ok := ctx.Value(muteStagingCtxKey{}).(bool)
return ok && v
}

0 comments on commit 6a6b923

Please sign in to comment.