MCPcopy Create free account
hub / github.com/Facets-cloud/flow / detectGitRemote

Function detectGitRemote

internal/app/workdir.go:432–461  ·  view source on GitHub ↗

detectGitRemote reads /.git/config (if present) and extracts the origin remote URL. Returns "" on any error or if the section isn't present. Handles `.git` being either a directory (normal repo) or a file (git worktree — we follow the gitdir pointer).

(path string)

Source from the content-addressed store, hash-verified

430// present. Handles `.git` being either a directory (normal repo) or a
431// file (git worktree — we follow the gitdir pointer).
432func detectGitRemote(path string) string {
433 configPath := resolveGitConfigPath(path)
434 if configPath == "" {
435 return ""
436 }
437 f, err := os.Open(configPath)
438 if err != nil {
439 return ""
440 }
441 defer f.Close()
442
443 scanner := bufio.NewScanner(f)
444 inOrigin := false
445 for scanner.Scan() {
446 line := scanner.Text()
447 trimmed := strings.TrimSpace(line)
448 if strings.HasPrefix(trimmed, "[") && strings.HasSuffix(trimmed, "]") {
449 // Section header.
450 inOrigin = (trimmed == `[remote "origin"]`)
451 continue
452 }
453 if !inOrigin {
454 continue
455 }
456 if m := gitRemoteURLRE.FindStringSubmatch(line); m != nil {
457 return m[1]
458 }
459 }
460 return ""
461}
462
463// resolveGitConfigPath returns the absolute path to the git config for a
464// repo rooted at path, or "" if none exists. Handles both the common case

Callers 4

cmdWorkdirAddFunction · 0.85
cmdWorkdirScanFunction · 0.85
TestDetectGitRemoteBasicFunction · 0.85

Calls 1

resolveGitConfigPathFunction · 0.85

Tested by 2

TestDetectGitRemoteBasicFunction · 0.68