github.com/drone/runner-go@v1.12.0/clone/utils.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package clone 6 7 import ( 8 "fmt" 9 "strings" 10 ) 11 12 // fetchFlags is a helper function that returns a string of 13 // optional git-fetch command line flags. 14 func fetchFlags(args Args) string { 15 var flags []string 16 if depth := args.Depth; depth > 0 { 17 flag := fmt.Sprintf("--depth=%d", depth) 18 flags = append(flags, flag) 19 } 20 if args.Tags { 21 flags = append(flags, "--tags") 22 } 23 return strings.Join(flags, " ") 24 } 25 26 // mergeFlags is a helper function that returns a string of 27 // optional git-merge command line flags. 28 func mergeFlags(args Args) string { 29 var flags []string 30 if args.NoFF { 31 flags = append(flags, "--no-ff") 32 } 33 return strings.Join(flags, " ") 34 } 35 36 // isTag returns true if the reference path points to 37 // a tag object. 38 func isTag(ref string) bool { 39 return strings.HasPrefix(ref, "refs/tags/") 40 } 41 42 // isPullRequest returns true if the reference path points to 43 // a pull request object. 44 func isPullRequest(ref string) bool { 45 return strings.HasPrefix(ref, "refs/pull/") || 46 strings.HasPrefix(ref, "refs/pull-requests/") || 47 strings.HasPrefix(ref, "refs/merge-requests/") 48 }