Skip to content
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

[ws-daemon] update git safe directory at init workspace phase #10012

Merged
merged 1 commit into from
May 13, 2022
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
5 changes: 5 additions & 0 deletions components/ws-daemon/pkg/content/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ func (s *WorkspaceService) InitWorkspace(ctx context.Context, req *api.InitWorks
}
}

err = workspace.UpdateGitSafeDirectory(ctx)
if err != nil {
log.WithError(err).WithField("workspaceId", req.Id).Warn("cannot update git safe directory")
}

// Tell the world we're done
err = workspace.MarkInitDone(ctx)
if err != nil {
Expand Down
28 changes: 22 additions & 6 deletions components/ws-daemon/pkg/internal/session/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,28 @@ func (s *Workspace) SetGitStatus(status *csapi.GitStatus) error {
return s.persist()
}

func (s *Workspace) UpdateGitSafeDirectory(ctx context.Context) (err error) {
loc := s.Location
if loc == "" {
log.WithField("loc", loc).WithFields(s.OWI()).Debug("not updating Git safe directory of FWB workspace")
return nil
}

loc = filepath.Join(loc, s.CheckoutLocation)
if !git.IsWorkingCopy(loc) {
log.WithField("loc", loc).WithField("checkout location", s.CheckoutLocation).WithFields(s.OWI()).Warn("did not find a Git working copy - not updating safe directory")
return nil
}

c := git.Client{Location: loc}

err = c.Git(ctx, "config", "--global", "--add", "safe.directory", loc)
if err != nil {
log.WithError(err).WithFields(s.OWI()).Warn("cannot add safe directory into git global config")
}
return err
}

// UpdateGitStatus attempts to update the LastGitStatus from the workspace's local working copy.
func (s *Workspace) UpdateGitStatus(ctx context.Context) (res *csapi.GitStatus, err error) {
loc := s.Location
Expand All @@ -281,12 +303,6 @@ func (s *Workspace) UpdateGitStatus(ctx context.Context) (res *csapi.GitStatus,

c := git.Client{Location: loc}

err = c.Git(ctx, "config", "--global", "--add", "safe.directory", loc)
if err != nil {
log.WithError(err).WithFields(s.OWI()).Warn("cannot persist latest Git status")
err = nil
}

stat, err := c.Status(ctx)
if err != nil {
return nil, err
Expand Down