Skip to content
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
2 changes: 1 addition & 1 deletion cmd/internal/agent_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (cmd *DaemonCmd) runShutdownCommand(
workspace *provider2.AgentWorkspaceInfo,
) {
// get environ
environ, err := custom.ToEnvironWithBinaries(workspace)
environ, err := custom.ToEnvironWithBinaries(ctx, workspace)
if err != nil {
log.Errorf("%v", err)
return
Expand Down
13 changes: 8 additions & 5 deletions cmd/internal/agentcontainer/credentials_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ func (cmd *CredentialsServerCmd) Run(ctx context.Context, port int) error {
if err != nil {
return err
}
err = gitcredentials.ConfigureHelper(binaryPath, cmd.User, port)
err = gitcredentials.ConfigureHelper(ctx, binaryPath, cmd.User, port)
if err != nil {
return fmt.Errorf("configure git helper: %w", err)
}

// cleanup when we are done
// cleanup when we are done. This defer runs after the server loop
// returns on shutdown, when ctx is already canceled — use an uncanceled
// context so the helper is actually removed instead of aborting early.
cleanupCtx := context.WithoutCancel(ctx)
defer func(userName string) {
_ = gitcredentials.RemoveHelper(userName)
_ = gitcredentials.RemoveHelper(cleanupCtx, userName)
}(cmd.User)
}

Expand Down Expand Up @@ -165,7 +168,7 @@ func configureGitUserLocally(
client tunnel.TunnelClient,
) error {
// get local credentials
localGitUser, err := gitcredentials.GetUser(userName, "")
localGitUser, err := gitcredentials.GetUser(ctx, userName, "")
if err != nil {
return err
} else if localGitUser.Name != "" && localGitUser.Email != "" {
Expand Down Expand Up @@ -194,7 +197,7 @@ func configureGitUserLocally(
}

// set git user
err = gitcredentials.SetUser(userName, gitUser)
err = gitcredentials.SetUser(ctx, userName, gitUser)
if err != nil {
return fmt.Errorf("set git user & email: %w", err)
}
Expand Down
10 changes: 3 additions & 7 deletions cmd/internal/agentcontainer/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,18 +805,14 @@ func configureSystemGitCredentials(
)
_ = os.Setenv(config2.EnvGitHelperPort, strconv.Itoa(serverPort))

err = git.CommandContext(ctx, git.GetDefaultExtraEnv(false), "config", "--system", "--add",
"credential.helper", gitCredentials).
Run()
if err != nil {
gitConfig := git.At("", git.WithStrictHostKeyChecking(false)).Config()
if err = gitConfig.Add(ctx, "credential.helper", gitCredentials, git.ScopeSystem); err != nil {
return nil, fmt.Errorf("add git credential helper: %w", err)
}

cleanup := func() {
log.Debug("unset setup system credential helper")
err = git.CommandContext(ctx, git.GetDefaultExtraEnv(false), "config", "--system", "--unset", "credential.helper").
Run()
if err != nil {
if err = gitConfig.Unset(ctx, "credential.helper", git.ScopeSystem); err != nil {
log.Errorf("unset system credential helper %v", err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/internal/agentworkspace/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func (cmd *BuildCmd) Run(ctx context.Context) error {
// initialize the workspace
cancelCtx, cancel := context.WithCancel(ctx)
defer cancel()
_, credentialsDir, err := initWorkspace(initWorkspaceParams{
ctx: cancelCtx,
_, credentialsDir, err := initWorkspace(cancelCtx, initWorkspaceParams{
workspaceInfo: workspaceInfo,
debug: cmd.Debug,
shouldInstallDaemon: false,
Expand Down
9 changes: 2 additions & 7 deletions cmd/internal/agentworkspace/install_dotfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ func (cmd *InstallDotfilesCmd) Run(ctx context.Context) error {
log.Infof("Cloning dotfiles %s", cmd.Repository)

gitInfo := git.NormalizeRepository(cmd.Repository)
if err := git.CloneRepository(
ctx,
gitInfo,
targetDir,
"",
cmd.StrictHostKeyChecking,
); err != nil {
if err := git.At(targetDir, git.WithStrictHostKeyChecking(cmd.StrictHostKeyChecking)).
CloneFromInfo(ctx, gitInfo, ""); err != nil {
return err
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/agentworkspace/setup_gpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (cmd *SetupGPGCmd) Run(ctx context.Context) error {

if gpgConf.GitKey != "" {
log.Debugf("Setup git signing key")
if err := gitcredentials.SetupGpgGitKey(gpgConf.GitKey); err != nil {
if err := gitcredentials.SetupGpgGitKey(ctx, gpgConf.GitKey); err != nil {
log.Warnf("Setup git signing key failed (non-fatal): %v", err)
}
}
Expand Down
Loading
Loading