The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
hooks: remove the unused GetRemoteInfo and its helpers (#1093)
kyle-elliott-asymptote6681a860d776
diff --git a/cli/beacon-hooks/internal/git/git.go b/cli/beacon-hooks/internal/git/git.goindex 832c8720..01c1647f 100644--- a/cli/beacon-hooks/internal/git/git.go+++ b/cli/beacon-hooks/internal/git/git.go@@ -1,11 +1,9 @@package gitimport (- "bufio""io""os""path/filepath"- "regexp""strings")@@ -34,9 +32,9 @@ func CurrentBranch(cwd string) string {}// findHeadFile walks up from cwd to the HEAD file of the innermost checkout.-// Unlike findGitDir, a worktree ".git" pointer file resolves to the-// per-worktree gitdir, which holds this checkout's HEAD; the shared commondir-// HEAD would report another worktree's branch.+// A worktree ".git" pointer file resolves to the per-worktree gitdir, which+// holds this checkout's HEAD; the shared commondir HEAD would report another+// worktree's branch.func findHeadFile(cwd string) string {cwd = physicalDir(cwd)if cwd == "" {@@ -139,151 +137,3 @@ func isValidBranchName(branch string) bool {}return true}--// GetRemoteInfo returns the owner and repository name from the git remote origin.-// Returns empty strings if not in a git repo or no origin remote is configured.-// Supports both SSH ([email protected]:owner/name.git) and HTTPS (https://github.com/owner/name.git) URLs.-// If cwd is provided, it uses that directory as the starting point; otherwise uses os.Getwd().-func GetRemoteInfo(cwd string) (owner, name string) {- // Find .git directory by walking up from cwd- gitDir := findGitDir(cwd)- if gitDir == "" {- return "", ""- }-- // Read .git/config- configPath := filepath.Join(gitDir, "config")- url := parseRemoteOriginURL(configPath)- if url == "" {- return "", ""- }-- // Parse owner/name from URL- return parseGitURL(url)-}--// findGitDir walks up the directory tree to find the .git directory.-// If cwd is provided, it uses that directory as the starting point; otherwise uses os.Getwd().-// Handles both normal repositories (.git is a directory) and worktrees (.git is a file-// containing a "gitdir:" reference).-func findGitDir(cwd string) string {- cwd = physicalDir(cwd)- if cwd == "" {- return ""- }-- dir := cwd- for {- gitPath := filepath.Join(dir, ".git")- info, err := os.Stat(gitPath)- if err == nil {- if info.IsDir() {- // Normal repository: .git is a directory- return gitPath- }- // Worktree: .git is a file with "gitdir: <path>"- if resolved := resolveWorktreeGitDir(gitPath); resolved != "" {- return resolved- }- }-- parent := filepath.Dir(dir)- if parent == dir {- // Reached root- return ""- }- dir = parent- }-}--// resolveWorktreeGitDir reads a .git file (as found in worktrees),-// extracts the gitdir path, and resolves the common git directory-// that contains the config with remote URLs.-func resolveWorktreeGitDir(dotGitFile string) string {- gitdir := parseGitDirPointer(dotGitFile)- if gitdir == "" {- return ""- }-- // In a worktree, gitdir points to e.g. /repo/.git/worktrees/foo- // which contains a "commondir" file with a relative path to the shared .git dir- commondirPath := filepath.Join(gitdir, "commondir")- if commondirData, err := os.ReadFile(commondirPath); err == nil {- commondir := strings.TrimSpace(string(commondirData))- if commondir != "" {- if !filepath.IsAbs(commondir) {- commondir = filepath.Join(gitdir, commondir)- }- commondir = filepath.Clean(commondir)- // Verify it looks like a git dir (has a config file)- if _, err := os.Stat(filepath.Join(commondir, "config")); err == nil {- return commondir- }- }- }-- // No commondir means this is not a worktree (likely a submodule).- // Return "" so findGitDir continues walking up to the parent repo.- return ""-}--// parseRemoteOriginURL reads .git/config and extracts the origin remote URL-func parseRemoteOriginURL(configPath string) string {- file, err := os.Open(configPath)- if err != nil {- return ""- }- defer file.Close()-- scanner := bufio.NewScanner(file)- inOriginSection := false-- for scanner.Scan() {- line := strings.TrimSpace(scanner.Text())-- // Check for section headers- if strings.HasPrefix(line, "[") {- inOriginSection = line == `[remote "origin"]`- continue- }-- // Look for url in origin section- if inOriginSection && strings.HasPrefix(line, "url") {- parts := strings.SplitN(line, "=", 2)- if len(parts) == 2 {- return strings.TrimSpace(parts[1])- }- }- }-- return ""-}--// parseGitURL extracts owner and repository name from a git URL-// Supports:-// - [email protected]:owner/name.git-// - [email protected]:owner/name-// - https://github.com/owner/name.git-// - https://github.com/owner/name-// - ssh://[email protected]/owner/name.git-func parseGitURL(url string) (owner, name string) {- // SSH format: [email protected]:owner/name.git- sshRegex := regexp.MustCompile(`^git@[^:]+:([^/]+)/([^/]+?)(?:\.git)?$`)- if matches := sshRegex.FindStringSubmatch(url); len(matches) == 3 {- return matches[1], matches[2]- }-- // HTTPS format: https://github.com/owner/name.git- httpsRegex := regexp.MustCompile(`^https?://[^/]+/([^/]+)/([^/]+?)(?:\.git)?$`)- if matches := httpsRegex.FindStringSubmatch(url); len(matches) == 3 {- return matches[1], matches[2]- }-- // SSH with ssh:// prefix: ssh://[email protected]/owner/name.git- sshPrefixRegex := regexp.MustCompile(`^ssh://[^/]+/([^/]+)/([^/]+?)(?:\.git)?$`)- if matches := sshPrefixRegex.FindStringSubmatch(url); len(matches) == 3 {- return matches[1], matches[2]- }-- return "", ""-}diff --git a/cli/beacon-hooks/internal/git/git_cwd_alias_test.go b/cli/beacon-hooks/internal/git/git_cwd_alias_test.goindex f3742ae3..3033ac9f 100644--- a/cli/beacon-hooks/internal/git/git_cwd_alias_test.go+++ b/cli/beacon-hooks/internal/git/git_cwd_alias_test.go@@ -27,10 +27,6 @@ func TestCurrentBranchFollowsThePhysicalWorkingDirectory(t *testing.T) {if out, err := cmd.CombinedOutput(); err != nil {t.Fatalf("init real repository: %v %s", err, out)}- remote := exec.Command(binary, "-C", path, "remote", "add", "origin", "https://github.com/acme/"+name+".git")- if out, err := remote.CombinedOutput(); err != nil {- t.Fatalf("add origin: %v %s", err, out)- }return path}target := initRepo("target", "feature/target")@@ -58,15 +54,6 @@ func TestCurrentBranchFollowsThePhysicalWorkingDirectory(t *testing.T) {if got := CurrentBranch(tc.path); got != want {t.Fatalf("CurrentBranch=%q native git=%q", got, want)}- // Branch and remote must come from the same repository.- url, err := exec.Command(binary, "-C", tc.path, "remote", "get-url", "origin").CombinedOutput()- if err != nil {- t.Fatalf("native git oracle: %v %s", err, url)- }- wantName := strings.TrimSuffix(filepath.Base(strings.TrimSpace(string(url))), ".git")- if _, name := GetRemoteInfo(tc.path); name != wantName {- t.Fatalf("GetRemoteInfo name=%q native git=%q", name, wantName)- }})}}diff --git a/cli/beacon-hooks/internal/git/git_test.go b/cli/beacon-hooks/internal/git/git_test.goindex e1dbabab..ef9a477c 100644--- a/cli/beacon-hooks/internal/git/git_test.go+++ b/cli/beacon-hooks/internal/git/git_test.go@@ -38,7 +38,6 @@ func TestCurrentBranchWorktreeUsesPerWorktreeHead(t *testing.T) {worktree := filepath.Join(base, "wt")writeTestFile(t, filepath.Join(mainRepo, ".git", "HEAD"), "ref: refs/heads/main\n")- writeTestFile(t, filepath.Join(mainRepo, ".git", "config"), "[remote \"origin\"]\n\turl = [email protected]:asymptote-labs/agent-beacon.git\n")worktreeGitDir := filepath.Join(mainRepo, ".git", "worktrees", "wt")writeTestFile(t, filepath.Join(worktreeGitDir, "HEAD"), "ref: refs/heads/feature/wt-branch\n")writeTestFile(t, filepath.Join(worktreeGitDir, "commondir"), "../..\n")@@ -50,12 +49,6 @@ func TestCurrentBranchWorktreeUsesPerWorktreeHead(t *testing.T) {if got := CurrentBranch(mainRepo); got != "main" {t.Fatalf("CurrentBranch = %q, want the main checkout's branch", got)}- // The commondir path used by GetRemoteInfo must keep working after the- // shared pointer-parsing refactor.- owner, name := GetRemoteInfo(worktree)- if owner != "asymptote-labs" || name != "agent-beacon" {- t.Fatalf("GetRemoteInfo = %q/%q, want asymptote-labs/agent-beacon", owner, name)- }}func TestCurrentBranchWorktreeRelativeGitDirPointer(t *testing.T) {