Skip to content

[supervisor] Improve git status calls to disable optional locks #20715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
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
27 changes: 25 additions & 2 deletions components/content-service/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,32 @@ func GitStatusFromFiles(ctx context.Context, loc string) (res *Status, err error
}, nil
}

// StatusOption configures the behavior of git status
type StatusOption func(*statusOptions)

type statusOptions struct {
disableOptionalLocks bool
}

// WithDisableOptionalLocks disables optional locks during git status
func WithDisableOptionalLocks(disable bool) StatusOption {
return func(o *statusOptions) {
o.disableOptionalLocks = disable
}
}

// Status runs git status
func (c *Client) Status(ctx context.Context) (res *Status, err error) {
gitout, err := c.GitWithOutput(ctx, nil, "status", "--porcelain=v2", "--branch", "-uall")
func (c *Client) Status(ctx context.Context, opts ...StatusOption) (res *Status, err error) {
options := &statusOptions{}
for _, opt := range opts {
opt(options)
}

args := []string{"status", "--porcelain=v2", "--branch", "-uall"}
if options.disableOptionalLocks {
args = append([]string{"--no-optional-locks"}, args...)
}
gitout, err := c.GitWithOutput(ctx, nil, args[0], args[1:]...)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion components/supervisor/pkg/supervisor/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (s *GitStatusService) Run(ctx context.Context, wg *sync.WaitGroup) {
}

func (s *GitStatusService) update(ctx context.Context, updateContext *gitStatusUpdateContext) {
status, err := s.git.Status(ctx)
status, err := s.git.Status(ctx, git.WithDisableOptionalLocks(true))
if err != nil {
log.WithError(err).Error("git: error getting status")
time.Sleep(updateContext.statusBackoff.NextBackOff())
Expand Down
Loading