MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / GetMainBranchName

Method GetMainBranchName

cli/pkg/common/git.go:202–234  ·  view source on GitHub ↗

获取默认分支 e.g. git remote show $(git remote show|tail -1)|grep 'HEAD branch'|awk '{print $NF}'

(repoDirPath string)

Source from the content-addressed store, hash-verified

200// 获取默认分支
201// e.g. git remote show $(git remote show|tail -1)|grep 'HEAD branch'|awk '{print $NF}'
202func (g gitOperation) GetMainBranchName(repoDirPath string) string {
203 remoteName := g.GetRemoteName(repoDirPath)
204
205 output1, _ := EXEC.CombinedOutput("git remote show "+remoteName, repoDirPath)
206 tmpArray1 := strings.Split(strings.TrimSpace(output1), "\n")
207 for _, line := range tmpArray1 {
208 /*
209 * remote origin
210 Fetch URL: https://github.com/idcf-boat-house/boathouse-calculator.git
211 Push URL: https://github.com/idcf-boat-house/boathouse-calculator.git
212 HEAD branch: master
213 Remote branches:
214 feature-vmlc-arm-improve tracked
215 kaikeba tracked
216 master tracked
217 new-base tracked
218 test-git-config tracked
219 Local branches configured for 'git pull':
220 feature-vmlc-arm-improve merges with remote feature-vmlc-arm-improve
221 master merges with remote master
222 Local refs configured for 'git push':
223 feature-vmlc-arm-improve pushes to feature-vmlc-arm-improve (up to date)
224 master pushes to master (local out of date)
225 */
226 text := "HEAD branch:"
227 index := strings.Index(line, text)
228 if index > -1 {
229 tmp := line[index+len(text):]
230 return strings.TrimSpace(tmp)
231 }
232 }
233 return ""
234}
235
236// 从git下载相关文件
237func (g gitOperation) DownloadFilesByGit(workingRootDir string, gitCloneUrl string, branch string, filePathExpression string) (

Callers 1

SparseCheckoutMethod · 0.95

Calls 2

GetRemoteNameMethod · 0.95
CombinedOutputMethod · 0.80

Tested by

no test coverage detected