Skip to content

Commit 5a8c9b5

Browse files
fix/gitindex: keep clone setting sync scoped to zoekt metadata
The #635 port accidentally introduced remote.origin.url rewrites for existing clones. That is a behavior change from the original flow and not required for the metadata-diff optimization. This keeps the update path focused on zoekt settings only, while preserving the return-value signal that triggers reindex when metadata actually changes. The integration test now validates metadata mutation and no-op behavior without expecting remote URL churn. Test Plan: go test ./... Amp-Thread-ID: https://ampcode.com/threads/T-019d0c05-51b0-77ee-a1dc-cb60ce14712d Co-authored-by: Amp <amp@ampcode.com>
1 parent 1d089a0 commit 5a8c9b5

3 files changed

Lines changed: 6 additions & 11 deletions

File tree

gitindex/clone.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"bytes"
1919
"fmt"
2020
"log"
21-
"maps"
2221
"os"
2322
"os/exec"
2423
"path/filepath"
@@ -39,9 +38,7 @@ func CloneRepo(destDir, name, cloneURL string, settings map[string]string) (stri
3938

4039
repoDest := filepath.Join(parent, filepath.Base(name)+".git")
4140
if _, err := os.Lstat(repoDest); err == nil {
42-
// Repository exists, ensure settings are in sync including the clone URL
43-
settings := maps.Clone(settings)
44-
settings["remote.origin.url"] = cloneURL
41+
// Repository exists, ensure zoekt settings are in sync.
4542
hadUpdate, err := updateZoektGitConfig(repoDest, settings)
4643
if err != nil {
4744
return "", fmt.Errorf("failed to update repository settings: %w", err)

gitindex/clone_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func cloneConfigArgs(settings map[string]string) []string {
3838
return args
3939
}
4040

41-
// updateZoektGitConfig applies zoekt.* settings and remote.origin.url updates
42-
// to an existing clone. It returns whether the repository config changed.
41+
// updateZoektGitConfig applies zoekt.* settings to an existing clone.
42+
// It returns whether the repository config changed.
4343
func updateZoektGitConfig(repoDest string, settings map[string]string) (bool, error) {
4444
changed := false
4545
for _, key := range sortedKeys(settings) {

gitindex/clone_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ func gitConfigValue(t *testing.T, repoDir, key string) (string, bool) {
8585
func TestCloneRepoUpdatesExistingSettings(t *testing.T) {
8686
root := t.TempDir()
8787
originA := filepath.Join(root, "origin-a.git")
88-
originB := filepath.Join(root, "origin-b.git")
8988
runScript(t, root, "git init --bare "+originA)
90-
runScript(t, root, "git init --bare "+originB)
9189

9290
destRoot := filepath.Join(root, "repos")
9391
repoDest := filepath.Join(destRoot, "owner", "repo.git")
@@ -114,7 +112,7 @@ func TestCloneRepoUpdatesExistingSettings(t *testing.T) {
114112
t.Fatalf("got %q want empty destination for unchanged settings", dest)
115113
}
116114

117-
dest, err = CloneRepo(destRoot, "owner/repo", originB, map[string]string{
115+
dest, err = CloneRepo(destRoot, "owner/repo", originA, map[string]string{
118116
"zoekt.name": "github.com/owner/repo",
119117
"zoekt.description": "",
120118
})
@@ -128,7 +126,7 @@ func TestCloneRepoUpdatesExistingSettings(t *testing.T) {
128126
if got, ok := gitConfigValue(t, repoDest, "zoekt.description"); ok {
129127
t.Fatalf("got stale zoekt.description=%q, want it removed", got)
130128
}
131-
if got, ok := gitConfigValue(t, repoDest, "remote.origin.url"); !ok || got != originB {
132-
t.Fatalf("got remote.origin.url=%q exists=%t want %q/true", got, ok, originB)
129+
if got, ok := gitConfigValue(t, repoDest, "remote.origin.url"); !ok || got != originA {
130+
t.Fatalf("got remote.origin.url=%q exists=%t want %q/true", got, ok, originA)
133131
}
134132
}

0 commit comments

Comments
 (0)