@@ -34,7 +34,6 @@ type GitGetter struct {
34
34
Timeout time.Duration
35
35
}
36
36
37
- var defaultBranchRegexp = regexp .MustCompile (`\s->\sorigin/(.*)` )
38
37
var lsRemoteSymRefRegexp = regexp .MustCompile (`ref: refs/heads/([^\s]+).*` )
39
38
40
39
func (g * GitGetter ) ClientMode (_ * url.URL ) (ClientMode , error ) {
@@ -83,7 +82,7 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
83
82
q .Del ("depth" )
84
83
85
84
// Copy the URL
86
- var newU url. URL = * u
85
+ newU : = * u
87
86
u = & newU
88
87
u .RawQuery = q .Encode ()
89
88
}
@@ -313,22 +312,6 @@ func (g *GitGetter) fetchSubmodules(ctx context.Context, dst, sshKeyFile string,
313
312
return getRunCommand (cmd )
314
313
}
315
314
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
-
332
315
// findRemoteDefaultBranch checks the remote repo's HEAD symref to return the remote repo's
333
316
// default branch. "master" is returned if no HEAD symref exists.
334
317
func findRemoteDefaultBranch (ctx context.Context , u * url.URL ) string {
@@ -374,7 +357,7 @@ func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) {
374
357
375
358
// We have an SSH key temp file configured, tell ssh about this.
376
359
if runtime .GOOS == "windows" {
377
- sshKeyFile = strings .Replace (sshKeyFile , `\` , `/` , - 1 )
360
+ sshKeyFile = strings .ReplaceAll (sshKeyFile , `\` , `/` )
378
361
}
379
362
sshCmd = append (sshCmd , "-i" , sshKeyFile )
380
363
env = append (env , strings .Join (sshCmd , " " ))
@@ -398,7 +381,7 @@ func checkGitVersion(ctx context.Context, min string) error {
398
381
399
382
fields := strings .Fields (string (out ))
400
383
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 ))
402
385
}
403
386
v := fields [2 ]
404
387
if runtime .GOOS == "windows" && strings .Contains (v , ".windows." ) {
@@ -416,7 +399,7 @@ func checkGitVersion(ctx context.Context, min string) error {
416
399
}
417
400
418
401
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 )
420
403
}
421
404
422
405
return nil
@@ -426,13 +409,13 @@ func checkGitVersion(ctx context.Context, min string) error {
426
409
func removeCaseInsensitiveGitDirectory (dst string ) error {
427
410
files , err := os .ReadDir (dst )
428
411
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 )
430
413
}
431
414
for _ , f := range files {
432
415
if strings .EqualFold (f .Name (), ".git" ) && f .IsDir () {
433
416
err := os .RemoveAll (filepath .Join (dst , f .Name ()))
434
417
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 )
436
419
}
437
420
}
438
421
}
0 commit comments