@@ -34,7 +34,6 @@ type GitGetter struct {
3434 Timeout time.Duration
3535}
3636
37- var defaultBranchRegexp = regexp .MustCompile (`\s->\sorigin/(.*)` )
3837var lsRemoteSymRefRegexp = regexp .MustCompile (`ref: refs/heads/([^\s]+).*` )
3938
4039func (g * GitGetter ) ClientMode (_ * url.URL ) (ClientMode , error ) {
@@ -83,7 +82,7 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
8382 q .Del ("depth" )
8483
8584 // Copy the URL
86- var newU url. URL = * u
85+ newU : = * u
8786 u = & newU
8887 u .RawQuery = q .Encode ()
8988 }
@@ -313,22 +312,6 @@ func (g *GitGetter) fetchSubmodules(ctx context.Context, dst, sshKeyFile string,
313312 return getRunCommand (cmd )
314313}
315314
316- // findDefaultBranch checks the repo's origin remote for its default branch
317- // (generally "master"). "master" is returned if an origin default branch
318- // can't be determined.
319- func findDefaultBranch (ctx context.Context , dst string ) string {
320- var stdoutbuf bytes.Buffer
321- cmd := exec .CommandContext (ctx , "git" , "branch" , "-r" , "--points-at" , "refs/remotes/origin/HEAD" )
322- cmd .Dir = dst
323- cmd .Stdout = & stdoutbuf
324- err := cmd .Run ()
325- matches := defaultBranchRegexp .FindStringSubmatch (stdoutbuf .String ())
326- if err != nil || matches == nil {
327- return "master"
328- }
329- return matches [len (matches )- 1 ]
330- }
331-
332315// findRemoteDefaultBranch checks the remote repo's HEAD symref to return the remote repo's
333316// default branch. "master" is returned if no HEAD symref exists.
334317func findRemoteDefaultBranch (ctx context.Context , u * url.URL ) string {
@@ -374,7 +357,7 @@ func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) {
374357
375358 // We have an SSH key temp file configured, tell ssh about this.
376359 if runtime .GOOS == "windows" {
377- sshKeyFile = strings .Replace (sshKeyFile , `\` , `/` , - 1 )
360+ sshKeyFile = strings .ReplaceAll (sshKeyFile , `\` , `/` )
378361 }
379362 sshCmd = append (sshCmd , "-i" , sshKeyFile )
380363 env = append (env , strings .Join (sshCmd , " " ))
@@ -398,7 +381,7 @@ func checkGitVersion(ctx context.Context, min string) error {
398381
399382 fields := strings .Fields (string (out ))
400383 if len (fields ) < 3 {
401- return fmt .Errorf ("Unexpected 'git version' output: %q" , string (out ))
384+ return fmt .Errorf ("unexpected 'git version' output: %q" , string (out ))
402385 }
403386 v := fields [2 ]
404387 if runtime .GOOS == "windows" && strings .Contains (v , ".windows." ) {
@@ -416,7 +399,7 @@ func checkGitVersion(ctx context.Context, min string) error {
416399 }
417400
418401 if have .LessThan (want ) {
419- return fmt .Errorf ("Required git version = %s, have %s" , want , have )
402+ return fmt .Errorf ("required git version = %s, have %s" , want , have )
420403 }
421404
422405 return nil
@@ -426,13 +409,13 @@ func checkGitVersion(ctx context.Context, min string) error {
426409func removeCaseInsensitiveGitDirectory (dst string ) error {
427410 files , err := os .ReadDir (dst )
428411 if err != nil {
429- return fmt .Errorf ("Failed to read the destination directory %s during git update" , dst )
412+ return fmt .Errorf ("failed to read the destination directory %s during git update" , dst )
430413 }
431414 for _ , f := range files {
432415 if strings .EqualFold (f .Name (), ".git" ) && f .IsDir () {
433416 err := os .RemoveAll (filepath .Join (dst , f .Name ()))
434417 if err != nil {
435- return fmt .Errorf ("Failed to remove the .git directory in the destination directory %s during git update" , dst )
418+ return fmt .Errorf ("failed to remove the .git directory in the destination directory %s during git update" , dst )
436419 }
437420 }
438421 }
0 commit comments