Skip to content

Commit

Permalink
Refactor the git clone (#5190)
Browse files Browse the repository at this point in the history
Move the authArgs into the singleflight closure, as they are only used within it.

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
Warashi authored Sep 5, 2024
1 parent 0f52877 commit d9db2c6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ func (c *client) Clone(ctx context.Context, repoID, remote, branch, destination
)
)

authArgs := []string{}
if c.username != "" && c.password != "" {
token := fmt.Sprintf("%s:%s", c.username, c.password)
encodedToken := base64.StdEncoding.EncodeToString([]byte(token))
header := fmt.Sprintf("Authorization: Basic %s", encodedToken)
authArgs = append(authArgs, "-c", fmt.Sprintf("http.extraHeader=%s", header))
}

_, err, _ := c.repoSingleFlights.Do(repoID, func() (interface{}, error) {
authArgs := []string{}
if c.username != "" && c.password != "" {
token := fmt.Sprintf("%s:%s", c.username, c.password)
encodedToken := base64.StdEncoding.EncodeToString([]byte(token))
header := fmt.Sprintf("Authorization: Basic %s", encodedToken)
authArgs = append(authArgs, "-c", fmt.Sprintf("http.extraHeader=%s", header))
}

_, err := os.Stat(repoCachePath)
if err != nil && !os.IsNotExist(err) {
return nil, err
Expand Down

0 comments on commit d9db2c6

Please sign in to comment.