Merge upstream/main into fix/fresh-install-fixes
This commit is contained in:
@@ -254,18 +254,25 @@ func configureHooksPath(repoPath string) error {
|
||||
// and origin/main never appears in refs/remotes/origin/main.
|
||||
// See: https://github.com/anthropics/gastown/issues/286
|
||||
func configureRefspec(repoPath string) error {
|
||||
cmd := exec.Command("git", "-C", repoPath, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*")
|
||||
gitDir := repoPath
|
||||
if _, err := os.Stat(filepath.Join(repoPath, ".git")); err == nil {
|
||||
gitDir = filepath.Join(repoPath, ".git")
|
||||
}
|
||||
gitDir = filepath.Clean(gitDir)
|
||||
|
||||
var stderr bytes.Buffer
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
configCmd := exec.Command("git", "--git-dir", gitDir, "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*")
|
||||
configCmd.Stderr = &stderr
|
||||
if err := configCmd.Run(); err != nil {
|
||||
return fmt.Errorf("configuring refspec: %s", strings.TrimSpace(stderr.String()))
|
||||
}
|
||||
// Fetch to populate refs/remotes/origin/* so worktrees can use origin/main
|
||||
fetchCmd := exec.Command("git", "-C", repoPath, "fetch", "origin")
|
||||
|
||||
fetchCmd := exec.Command("git", "--git-dir", gitDir, "fetch", "origin")
|
||||
fetchCmd.Stderr = &stderr
|
||||
if err := fetchCmd.Run(); err != nil {
|
||||
return fmt.Errorf("fetching origin: %s", strings.TrimSpace(stderr.String()))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -443,7 +444,7 @@ func TestCloneBareHasOriginRefs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("git branch --show-current: %v", err)
|
||||
}
|
||||
mainBranch := string(out[:len(out)-1]) // trim newline
|
||||
mainBranch := strings.TrimSpace(string(out))
|
||||
|
||||
// Clone as bare repo using our CloneBare function
|
||||
bareDir := filepath.Join(tmp, "bare.git")
|
||||
@@ -454,8 +455,7 @@ func TestCloneBareHasOriginRefs(t *testing.T) {
|
||||
|
||||
// Verify origin/main exists (this was the bug - it didn't exist before the fix)
|
||||
bareGit := NewGitWithDir(bareDir, "")
|
||||
cmd = exec.Command("git", "branch", "-r")
|
||||
cmd.Dir = bareDir
|
||||
cmd = exec.Command("git", "--git-dir", bareDir, "branch", "-r")
|
||||
out, err = cmd.Output()
|
||||
if err != nil {
|
||||
t.Fatalf("git branch -r: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user