MCPcopy Index your code
hub / github.com/coder/coder / detectGitRef

Function detectGitRef

cli/gitaskpass.go:27–43  ·  view source on GitHub ↗

detectGitRef attempts to resolve the current git branch and remote origin URL from the given working directory. These are sent to the control plane so it can look up PR/diff status via the GitHub API without SSHing into the workspace. Failures are silently ignored since this is best-effort.

(workingDirectory string)

Source from the content-addressed store, hash-verified

25// without SSHing into the workspace. Failures are silently ignored
26// since this is best-effort.
27func detectGitRef(workingDirectory string) (branch string, remoteOrigin string) {
28 run := func(args ...string) string {
29 //nolint:gosec
30 cmd := exec.Command(args[0], args[1:]...)
31 if workingDirectory != "" {
32 cmd.Dir = workingDirectory
33 }
34 out, err := cmd.Output()
35 if err != nil {
36 return ""
37 }
38 return strings.TrimSpace(string(out))
39 }
40 branch = run("git", "rev-parse", "--abbrev-ref", "HEAD")
41 remoteOrigin = run("git", "config", "--get", "remote.origin.url")
42 return branch, remoteOrigin
43}
44
45// gitAskpass is used by the Coder agent to automatically authenticate
46// with Git providers based on a hostname.

Callers 1

gitAskpassFunction · 0.85

Calls 3

CommandMethod · 0.80
OutputMethod · 0.65
runFunction · 0.50

Tested by

no test coverage detected