fix(cmd/bd): note config writes by other worktrees of a shared clone in the git-state guard (wy-qlvlmf)
The TestMain git-state guard from #7650 fails the run on any common-config change except branch tracking and whole non-origin remotes. On a clone with linked worktrees, the other worktrees rewrite that config while the suite runs: identities (user.*), the bd role (beads.role), merge and rerere settings. Any one of those writes during a ~9 minute `go test ./cmd/bd` turned a green run red, and the ERROR blamed the suite. The guard now decides before the run whether the clone is shared (its common dir has a linked worktree registered). In a shared clone only keys of the kind the r880 clobber rewrote fail the run: core.bare, core.worktree, core.hooksPath, every extensions.* key and every key of origin. Other common-config changes draw a NOTE that names another process first. A clone with no linked worktree, such as a CI checkout, keeps the landed check unchanged. Hook files, the checkout's own config.worktree, and a common config that is created, deleted or unparseable still fail the run in every clone. Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
46aa59cc65
commit
d55ed3110f
2 changed files with 227 additions and 67 deletions
|
|
@ -379,10 +379,15 @@ func testMainInner(m *testing.M) int {
|
|||
// host rig's shared .git/config (core.bare=true, extensions.worktreeConfig,
|
||||
// a test remote.origin.url over the real origin) and its hooks, breaking
|
||||
// every worktree of that clone (wy-qlvlmf, r880). The common config and
|
||||
// hooks are shared by every worktree of the clone, so the keys other
|
||||
// worktrees rewrite routinely (branch tracking, a remote other than origin
|
||||
// added or removed whole) only draw a note; any other change means a test
|
||||
// most likely ran git against this checkout instead of a fixture it owns.
|
||||
// hooks are shared by every worktree of the clone. Common-config changes
|
||||
// that ordinary git use in any checkout makes (branch tracking, a remote
|
||||
// other than origin added or removed whole) only draw a note. Other
|
||||
// worktrees of a shared clone rewrite more of its common config while this
|
||||
// suite runs, so there only keys of the kind the clobber rewrote fail the
|
||||
// run. Any other common-config change in a clone no other checkout uses,
|
||||
// and any change to a hook or to this checkout's own config.worktree,
|
||||
// means a test most likely ran git against this checkout instead of a
|
||||
// fixture it owns.
|
||||
gitDirs, err := locateRepoGitDirs(repoRoot)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: this checkout's own git state is not guarded in this run: %v\n", err)
|
||||
|
|
@ -469,9 +474,13 @@ func testMainInner(m *testing.M) int {
|
|||
|
||||
// repoGitDirs names a checkout's git directories: gitDir is its own (a linked
|
||||
// worktree's .git/worktrees/<name>), common is the one every worktree of the
|
||||
// clone shares. They are the same directory for a main checkout.
|
||||
// clone shares. They are the same directory for a main checkout. shared
|
||||
// records that the clone has linked worktrees registered (a linked worktree
|
||||
// is one of them), so checkouts other than this one can write its common
|
||||
// config.
|
||||
type repoGitDirs struct {
|
||||
gitDir, common string
|
||||
shared bool
|
||||
}
|
||||
|
||||
func (d repoGitDirs) commonConfig() string { return filepath.Join(d.common, "config") }
|
||||
|
|
@ -516,9 +525,20 @@ func locateRepoGitDirs(repoRoot string) (repoGitDirs, error) {
|
|||
if dirs.common == "" {
|
||||
return repoGitDirs{}, fmt.Errorf("git rev-parse in %s: no common git dir in %q", repoRoot, out)
|
||||
}
|
||||
// Decided here, before the run, so a test that registers a worktree on
|
||||
// this clone cannot relax the check of its own writes.
|
||||
dirs.shared = hasLinkedWorktrees(dirs.common)
|
||||
return dirs, nil
|
||||
}
|
||||
|
||||
// hasLinkedWorktrees reports whether a clone's common dir has any linked
|
||||
// worktree registered. A stale entry that `git worktree prune` has not removed
|
||||
// yet counts too, which only relaxes the guard.
|
||||
func hasLinkedWorktrees(common string) bool {
|
||||
entries, err := os.ReadDir(filepath.Join(common, "worktrees"))
|
||||
return err == nil && len(entries) > 0
|
||||
}
|
||||
|
||||
// repoGitState captures the parts of a checkout's own git state that the r880
|
||||
// incident showed a test escape mutates: the common (shared) config, the
|
||||
// checkout's own config.worktree, and every file under the common hooks dir.
|
||||
|
|
@ -564,10 +584,11 @@ type gitStateChange struct {
|
|||
}
|
||||
|
||||
// diffRepoGitState compares two readRepoGitState results. A common-config
|
||||
// change is routine when every changed key is one that other worktrees of a
|
||||
// shared clone rewrite as a matter of course (routineSharedConfigKey). Any
|
||||
// other change (a hook file, config.worktree, core.*, user.*, extensions.*, an
|
||||
// existing remote's url, origin added or removed) is the clobber class.
|
||||
// change is routine when ordinary git use outside this suite explains every
|
||||
// changed key (routineConfigKey). Every other change is the clobber class,
|
||||
// including any change to a hook file or config.worktree, a common config
|
||||
// created, deleted or left unparseable, and, in any clone, a change to a key
|
||||
// of the kind the r880 clobber rewrote (clobberConfigKey).
|
||||
func diffRepoGitState(before, after repoGitState) []gitStateChange {
|
||||
paths := make([]string, 0, len(before.files))
|
||||
for p := range before.files {
|
||||
|
|
@ -591,9 +612,13 @@ func diffRepoGitState(before, after repoGitState) []gitStateChange {
|
|||
case !a.present:
|
||||
changes = append(changes, gitStateChange{path: p, detail: fmt.Sprintf("deleted (was %d bytes)", len(b.data))})
|
||||
case p == before.dirs.commonConfig():
|
||||
changes = append(changes, diffGitConfig(p, b.data, a.data, true))
|
||||
scope := soleCloneConfig
|
||||
if before.dirs.shared {
|
||||
scope = sharedCloneConfig
|
||||
}
|
||||
changes = append(changes, diffGitConfig(p, b.data, a.data, scope))
|
||||
case p == before.dirs.worktreeConfig():
|
||||
changes = append(changes, diffGitConfig(p, b.data, a.data, false))
|
||||
changes = append(changes, diffGitConfig(p, b.data, a.data, checkoutConfig))
|
||||
default:
|
||||
changes = append(changes, gitStateChange{path: p, detail: fmt.Sprintf("changed (%d → %d bytes)", len(b.data), len(a.data))})
|
||||
}
|
||||
|
|
@ -601,10 +626,24 @@ func diffRepoGitState(before, after repoGitState) []gitStateChange {
|
|||
return changes
|
||||
}
|
||||
|
||||
// gitConfigScope says which watched git config file a diff is for, and so how
|
||||
// much of its churn ordinary git use outside this suite explains.
|
||||
type gitConfigScope int
|
||||
|
||||
const (
|
||||
// checkoutConfig is a checkout's own config.worktree. Nothing but that
|
||||
// checkout writes it, so every key change fails the run.
|
||||
checkoutConfig gitConfigScope = iota
|
||||
// soleCloneConfig is the common config of a clone no other checkout uses.
|
||||
soleCloneConfig
|
||||
// sharedCloneConfig is the common config of a clone that other worktrees
|
||||
// use too; they rewrite it while this suite runs.
|
||||
sharedCloneConfig
|
||||
)
|
||||
|
||||
// diffGitConfig names the keys that differ between two versions of a git
|
||||
// config file. shared marks the clone's common config, the only file where
|
||||
// routine shared-clone keys do not count as a clobber.
|
||||
func diffGitConfig(path, before, after string, shared bool) gitStateChange {
|
||||
// config file of the given scope.
|
||||
func diffGitConfig(path, before, after string, scope gitConfigScope) gitStateChange {
|
||||
change := gitStateChange{path: path}
|
||||
b, errBefore := gitConfigEntries(before)
|
||||
a, errAfter := gitConfigEntries(after)
|
||||
|
|
@ -614,7 +653,7 @@ func diffGitConfig(path, before, after string, shared bool) gitStateChange {
|
|||
}
|
||||
var clobbered, routine []string
|
||||
for _, key := range changedConfigKeys(b, a) {
|
||||
if shared && routineSharedConfigKey(key, b, a) {
|
||||
if routineConfigKey(key, b, a, scope) {
|
||||
routine = append(routine, describeConfigKey(key, b, a))
|
||||
} else {
|
||||
clobbered = append(clobbered, describeConfigKey(key, b, a))
|
||||
|
|
@ -624,7 +663,7 @@ func diffGitConfig(path, before, after string, shared bool) gitStateChange {
|
|||
case len(clobbered) > 0:
|
||||
change.detail = summarizeConfigKeys(clobbered)
|
||||
if len(routine) > 0 {
|
||||
change.detail += fmt.Sprintf("; also %d branch/remote key change(s)", len(routine))
|
||||
change.detail += fmt.Sprintf("; also %d routine key change(s)", len(routine))
|
||||
}
|
||||
case len(routine) > 0:
|
||||
change.routine = true
|
||||
|
|
@ -679,28 +718,53 @@ func changedConfigKeys(before, after map[string][]string) []string {
|
|||
return keys
|
||||
}
|
||||
|
||||
// routineSharedConfigKey reports whether a change to key in a clone's common
|
||||
// config is one that other worktrees of the clone make as a matter of course:
|
||||
// branch tracking (branch.<name>.*, from checkout -b, push -u or branch -d in
|
||||
// any worktree) and a remote other than origin added or removed whole
|
||||
// (remote.<name>.* where that remote exists on only one side). A changed key
|
||||
// of a remote that exists both before and after, such as remote.origin.url,
|
||||
// is the r880 clobber. So is origin itself appearing or disappearing: the
|
||||
// clone's worktrees do not add or remove it, while `git remote add origin` and
|
||||
// `git remote remove origin` are common fixture steps.
|
||||
func routineSharedConfigKey(key string, before, after map[string][]string) bool {
|
||||
section, subsection, _ := splitConfigKey(key)
|
||||
// routineConfigKey reports whether ordinary git use outside this suite
|
||||
// explains a change to key in a config file of the given scope, so that it
|
||||
// only draws a note. Nothing in a checkout's own config.worktree is routine,
|
||||
// and no clobber key is anywhere. In the common config of any clone, branch
|
||||
// tracking is (branch.<name>.*, from checkout -b, push -u or branch -d in any
|
||||
// checkout), and so is a remote other than origin added or removed whole
|
||||
// (remote.<name>.* where that remote exists on only one side). Other
|
||||
// worktrees of a shared clone also rewrite keys like user.*, merge.*,
|
||||
// rerere.* or beads.role while this suite runs, so in a shared clone's common
|
||||
// config every key but the clobber keys is routine.
|
||||
func routineConfigKey(key string, before, after map[string][]string, scope gitConfigScope) bool {
|
||||
section, subsection, name := splitConfigKey(key)
|
||||
switch {
|
||||
case scope == checkoutConfig, clobberConfigKey(section, subsection, name):
|
||||
return false
|
||||
case scope == sharedCloneConfig:
|
||||
return true
|
||||
case subsection == "":
|
||||
return false
|
||||
case section == "branch":
|
||||
return true
|
||||
case section == "remote" && subsection != "origin":
|
||||
case section == "remote":
|
||||
return !hasConfigSubsection(before, section, subsection) || !hasConfigSubsection(after, section, subsection)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// clobberConfigKey reports whether a common-config key is one whose change
|
||||
// fails the run even in a shared clone: a key the r880 clobber rewrote, or
|
||||
// one of its kind, which changes how git runs in every worktree of the
|
||||
// clone. These are core.bare, core.worktree, core.hooksPath, every
|
||||
// extensions.* key, and every key of origin. That includes origin itself
|
||||
// appearing or disappearing: the clone's worktrees do not add or remove it,
|
||||
// while `git remote add origin` and `git remote remove origin` are common
|
||||
// fixture steps.
|
||||
func clobberConfigKey(section, subsection, name string) bool {
|
||||
switch section {
|
||||
case "core":
|
||||
return subsection == "" && (name == "bare" || name == "worktree" || name == "hookspath")
|
||||
case "extensions":
|
||||
return true
|
||||
case "remote":
|
||||
return subsection == "origin"
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// splitConfigKey splits a `git config --list` key into section, subsection and
|
||||
// variable name. A subsection may contain dots; section and name cannot.
|
||||
func splitConfigKey(key string) (section, subsection, name string) {
|
||||
|
|
@ -744,8 +808,8 @@ func summarizeConfigKeys(descriptions []string) string {
|
|||
}
|
||||
|
||||
// reportGitStateChanges renders the guard's verdict on changes. Routine
|
||||
// shared-clone changes get a NOTE and leave the run green: this suite and any
|
||||
// other process using the clone could have made them. Anything else is an
|
||||
// changes get a NOTE and leave the run green: another process using the clone
|
||||
// could have made them, as could this suite. Anything else is an
|
||||
// ERROR that fails the run, and the pre-run copies of the affected files are
|
||||
// saved under saveDir so a clobbered config can be restored by hand.
|
||||
func reportGitStateChanges(changes []gitStateChange, before repoGitState, saveDir string) (report string, failed bool) {
|
||||
|
|
@ -759,9 +823,9 @@ func reportGitStateChanges(changes []gitStateChange, before repoGitState, saveDi
|
|||
}
|
||||
var out strings.Builder
|
||||
if len(routine) > 0 {
|
||||
fmt.Fprintf(&out, "NOTE: this clone's shared git config changed during the run, by this suite or another "+
|
||||
"process using the clone; branch tracking and whole-remote changes are routine for a shared clone "+
|
||||
"(values not shown):\n%s\n", formatGitStateChanges(routine))
|
||||
fmt.Fprintf(&out, "NOTE: another process using this clone, or this suite, changed its git config "+
|
||||
"during the run; ordinary git use outside the suite makes these changes, so they do not fail "+
|
||||
"the run (values not shown):\n%s\n", formatGitStateChanges(routine))
|
||||
}
|
||||
if len(clobbered) > 0 {
|
||||
saved := "pre-run copies of the changed files: "
|
||||
|
|
|
|||
|
|
@ -11,20 +11,21 @@ import (
|
|||
|
||||
// These tests drive the TestMain git-state guard in
|
||||
// test_repo_beads_guard_test.go against throwaway clones, never this checkout.
|
||||
// Each fixture is a main checkout plus one linked worktree, the layout the
|
||||
// Most fixtures are a main checkout plus one linked worktree, the layout the
|
||||
// r880 clobber broke (wy-qlvlmf): the guard reads the clone's shared common
|
||||
// dir through the linked worktree, as it does when the suite runs from one.
|
||||
// A clone with no linked worktree, such as a CI checkout, gets the stricter
|
||||
// check.
|
||||
|
||||
// guardFixtureHost appears in every remote URL the fixtures write. No guard
|
||||
// report may contain it: configs carry remote URLs and can carry credentials.
|
||||
const guardFixtureHost = "guard-fixture.invalid"
|
||||
|
||||
// newGitGuardFixture returns a main checkout with an origin remote and an
|
||||
// origin/main tracking ref, and a detached linked worktree of it.
|
||||
func newGitGuardFixture(t *testing.T) (mainDir, linkedDir string) {
|
||||
// newGitGuardClone returns a checkout with an origin remote and an origin/main
|
||||
// tracking ref, and no linked worktree.
|
||||
func newGitGuardClone(t *testing.T) string {
|
||||
t.Helper()
|
||||
root := t.TempDir()
|
||||
mainDir = filepath.Join(root, "main")
|
||||
mainDir := filepath.Join(t.TempDir(), "main")
|
||||
if err := os.Mkdir(mainDir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -32,7 +33,15 @@ func newGitGuardFixture(t *testing.T) (mainDir, linkedDir string) {
|
|||
runGitForBootstrapTest(t, mainDir, "commit", "--allow-empty", "-m", "init")
|
||||
runGitForBootstrapTest(t, mainDir, "remote", "add", "origin", "https://"+guardFixtureHost+"/upstream.git")
|
||||
runGitForBootstrapTest(t, mainDir, "update-ref", "refs/remotes/origin/main", "HEAD")
|
||||
linkedDir = filepath.Join(root, "linked")
|
||||
return mainDir
|
||||
}
|
||||
|
||||
// newGitGuardFixture returns a newGitGuardClone checkout and a detached linked
|
||||
// worktree of it.
|
||||
func newGitGuardFixture(t *testing.T) (mainDir, linkedDir string) {
|
||||
t.Helper()
|
||||
mainDir = newGitGuardClone(t)
|
||||
linkedDir = filepath.Join(filepath.Dir(mainDir), "linked")
|
||||
runGitForBootstrapTest(t, mainDir, "worktree", "add", "--detach", linkedDir)
|
||||
return mainDir, linkedDir
|
||||
}
|
||||
|
|
@ -74,6 +83,9 @@ func TestLocateRepoGitDirs(t *testing.T) {
|
|||
if got, want := dirs.worktreeConfig(), filepath.Join(dirs.gitDir, "config.worktree"); got != want {
|
||||
t.Errorf("worktreeConfig() = %q, want %q", got, want)
|
||||
}
|
||||
if !dirs.shared {
|
||||
t.Error("shared = false for a main checkout with a linked worktree registered")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("linked worktree", func(t *testing.T) {
|
||||
|
|
@ -87,6 +99,16 @@ func TestLocateRepoGitDirs(t *testing.T) {
|
|||
if got, want := dirs.worktreeConfig(), filepath.Join(dirs.gitDir, "config.worktree"); got != want {
|
||||
t.Errorf("worktreeConfig() = %q, want %q", got, want)
|
||||
}
|
||||
if !dirs.shared {
|
||||
t.Error("shared = false for a linked worktree")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("clone with no linked worktree", func(t *testing.T) {
|
||||
dirs := locateGitGuardFixture(t, newGitGuardClone(t))
|
||||
if dirs.shared {
|
||||
t.Error("shared = true for a clone no other checkout uses; the guard would let a test's identity or role write through")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("not a checkout", func(t *testing.T) {
|
||||
|
|
@ -113,7 +135,8 @@ func TestLocateRepoGitDirs(t *testing.T) {
|
|||
|
||||
// TestDiffRepoGitStateClassifiesGitWrites runs the git commands that other
|
||||
// worktrees of a shared clone run routinely, and the writes the r880 clobber
|
||||
// made, and checks which ones the guard lets through.
|
||||
// made, and checks which ones the guard lets through, in a shared clone and
|
||||
// in one no other checkout uses.
|
||||
func TestDiffRepoGitStateClassifiesGitWrites(t *testing.T) {
|
||||
type fixture struct {
|
||||
mainDir, linkedDir string
|
||||
|
|
@ -148,6 +171,7 @@ func TestDiffRepoGitStateClassifiesGitWrites(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
guardMain bool // guard the main checkout instead of the linked worktree
|
||||
soleClone bool // a clone with no linked worktree; guard its main checkout
|
||||
setup func(*testing.T, fixture) // before the first snapshot
|
||||
act func(*testing.T, fixture) // between the snapshots
|
||||
routine bool
|
||||
|
|
@ -212,9 +236,50 @@ func TestDiffRepoGitStateClassifiesGitWrites(t *testing.T) {
|
|||
want: []string{"extensions.worktreeconfig added"},
|
||||
},
|
||||
{
|
||||
name: "identity rewritten",
|
||||
act: git(inLinked, "config", "user.email", "fixture@"+guardFixtureHost),
|
||||
want: []string{"user.email changed"},
|
||||
name: "worktree path set",
|
||||
act: git(inLinked, "config", "core.worktree", "elsewhere"),
|
||||
want: []string{"core.worktree added"},
|
||||
},
|
||||
{
|
||||
// Other worktrees of a shared clone set these while the suite
|
||||
// runs; the guard cannot tell their writes from a test's.
|
||||
name: "identity rewritten by another worktree",
|
||||
act: git(inMain, "config", "user.email", "fixture@"+guardFixtureHost),
|
||||
routine: true,
|
||||
want: []string{"user.email changed"},
|
||||
},
|
||||
{
|
||||
name: "bd role set by another worktree",
|
||||
act: git(inMain, "config", "beads.role", "maintainer"),
|
||||
routine: true,
|
||||
want: []string{"beads.role added"},
|
||||
},
|
||||
{
|
||||
// With no other checkout to blame, a top-level key change
|
||||
// is a test running git against this one.
|
||||
name: "identity rewritten in a clone no other checkout uses",
|
||||
soleClone: true,
|
||||
act: git(inMain, "config", "user.email", "fixture@"+guardFixtureHost),
|
||||
want: []string{"user.email changed"},
|
||||
},
|
||||
{
|
||||
name: "bd role set in a clone no other checkout uses",
|
||||
soleClone: true,
|
||||
act: git(inMain, "config", "beads.role", "maintainer"),
|
||||
want: []string{"beads.role added"},
|
||||
},
|
||||
{
|
||||
name: "branch tracking set up in a clone no other checkout uses",
|
||||
soleClone: true,
|
||||
act: git(inMain, "branch", "--track", "feature", "origin/main"),
|
||||
routine: true,
|
||||
want: []string{"branch.feature.remote added", "branch.feature.merge added"},
|
||||
},
|
||||
{
|
||||
name: "origin removed in a clone no other checkout uses",
|
||||
soleClone: true,
|
||||
act: git(inMain, "remote", "remove", "origin"),
|
||||
want: []string{"remote.origin.url removed", "remote.origin.fetch removed"},
|
||||
},
|
||||
{
|
||||
name: "hooks path rewritten",
|
||||
|
|
@ -227,7 +292,15 @@ func TestDiffRepoGitStateClassifiesGitWrites(t *testing.T) {
|
|||
git(inMain, "branch", "--track", "feature", "origin/main"),
|
||||
git(inLinked, "config", "core.bare", "true"),
|
||||
),
|
||||
want: []string{"core.bare changed", "also 2 branch/remote key change(s)"},
|
||||
want: []string{"core.bare changed", "also 2 routine key change(s)"},
|
||||
},
|
||||
{
|
||||
name: "clobber next to another worktree's identity change",
|
||||
act: both(
|
||||
git(inMain, "config", "user.email", "fixture@"+guardFixtureHost),
|
||||
git(inLinked, "config", "extensions.worktreeConfig", "true"),
|
||||
),
|
||||
want: []string{"extensions.worktreeconfig added", "also 1 routine key change(s)"},
|
||||
},
|
||||
{
|
||||
name: "hook written",
|
||||
|
|
@ -276,12 +349,20 @@ func TestDiffRepoGitStateClassifiesGitWrites(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mainDir, linkedDir := newGitGuardFixture(t)
|
||||
var mainDir, linkedDir string
|
||||
if tt.soleClone {
|
||||
mainDir = newGitGuardClone(t)
|
||||
} else {
|
||||
mainDir, linkedDir = newGitGuardFixture(t)
|
||||
}
|
||||
guarded := linkedDir
|
||||
if tt.guardMain {
|
||||
if tt.guardMain || tt.soleClone {
|
||||
guarded = mainDir
|
||||
}
|
||||
f := fixture{mainDir: mainDir, linkedDir: linkedDir, dirs: locateGitGuardFixture(t, guarded)}
|
||||
if f.dirs.shared == tt.soleClone {
|
||||
t.Fatalf("fixture shared = %v, want %v", f.dirs.shared, !tt.soleClone)
|
||||
}
|
||||
if tt.setup != nil {
|
||||
tt.setup(t, f)
|
||||
}
|
||||
|
|
@ -322,7 +403,7 @@ func TestDiffGitConfigText(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
after string
|
||||
shared bool
|
||||
scope gitConfigScope
|
||||
routine bool
|
||||
want string
|
||||
}{
|
||||
|
|
@ -330,46 +411,59 @@ func TestDiffGitConfigText(t *testing.T) {
|
|||
name: "comments and layout only",
|
||||
after: "# reformatted\n[core]\nbare=false\n[remote \"origin\"]\n" +
|
||||
"url = https://" + guardFixtureHost + "/upstream.git\nfetch = +refs/heads/*:refs/remotes/origin/*\n",
|
||||
shared: true,
|
||||
scope: soleCloneConfig,
|
||||
routine: true,
|
||||
want: "rewritten with no key or value change",
|
||||
},
|
||||
{
|
||||
name: "empty section left behind by a removal",
|
||||
after: base + "[branch \"gone\"]\n",
|
||||
shared: true,
|
||||
scope: soleCloneConfig,
|
||||
routine: true,
|
||||
want: "rewritten with no key or value change",
|
||||
},
|
||||
{
|
||||
name: "not parseable",
|
||||
after: "[core\n\tbare = true\n",
|
||||
shared: true,
|
||||
want: "not parseable as git config",
|
||||
name: "not parseable",
|
||||
after: "[core\n\tbare = true\n",
|
||||
scope: sharedCloneConfig,
|
||||
want: "not parseable as git config",
|
||||
},
|
||||
{
|
||||
name: "existing remote gains a fetch refspec",
|
||||
after: base + "[remote \"origin\"]\n\tfetch = +refs/pull/*/head:refs/remotes/origin/pr/*\n",
|
||||
shared: true,
|
||||
want: "remote.origin.fetch changed",
|
||||
name: "existing remote gains a fetch refspec",
|
||||
after: base + "[remote \"origin\"]\n\tfetch = +refs/pull/*/head:refs/remotes/origin/pr/*\n",
|
||||
scope: sharedCloneConfig,
|
||||
want: "remote.origin.fetch changed",
|
||||
},
|
||||
{
|
||||
name: "remote with a dotted name added",
|
||||
after: base + "[remote \"my.fork\"]\n\turl = https://" + guardFixtureHost + "/fork.git\n",
|
||||
shared: true,
|
||||
scope: soleCloneConfig,
|
||||
routine: true,
|
||||
want: "remote.my.fork.url added",
|
||||
},
|
||||
{
|
||||
name: "branch key outside the shared config",
|
||||
after: base + "[branch \"feature\"]\n\tremote = origin\n",
|
||||
shared: false,
|
||||
want: "branch.feature.remote added",
|
||||
name: "top-level key in a shared clone's config",
|
||||
after: base + "[merge]\n\tconflictStyle = zdiff3\n",
|
||||
scope: sharedCloneConfig,
|
||||
routine: true,
|
||||
want: "merge.conflictstyle added",
|
||||
},
|
||||
{
|
||||
name: "top-level key in a sole clone's config",
|
||||
after: base + "[merge]\n\tconflictStyle = zdiff3\n",
|
||||
scope: soleCloneConfig,
|
||||
want: "merge.conflictstyle added",
|
||||
},
|
||||
{
|
||||
name: "branch key outside the common config",
|
||||
after: base + "[branch \"feature\"]\n\tremote = origin\n",
|
||||
scope: checkoutConfig,
|
||||
want: "branch.feature.remote added",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := diffGitConfig("config", base, tt.after, tt.shared)
|
||||
c := diffGitConfig("config", base, tt.after, tt.scope)
|
||||
if c.routine != tt.routine {
|
||||
t.Errorf("routine = %v, want %v (detail %q)", c.routine, tt.routine, c.detail)
|
||||
}
|
||||
|
|
@ -388,7 +482,7 @@ func TestDiffGitConfigText(t *testing.T) {
|
|||
for i := range 20 {
|
||||
fmt.Fprintf(&after, "[branch \"b%02d\"]\n\tremote = origin\n", i)
|
||||
}
|
||||
c := diffGitConfig("config", base, after.String(), true)
|
||||
c := diffGitConfig("config", base, after.String(), soleCloneConfig)
|
||||
if !c.routine || !strings.HasSuffix(c.detail, ", and 8 more") {
|
||||
t.Errorf("got routine=%v detail %q, want a routine change listing 12 keys and 8 more", c.routine, c.detail)
|
||||
}
|
||||
|
|
@ -439,8 +533,10 @@ func TestReportGitStateChanges(t *testing.T) {
|
|||
if failed {
|
||||
t.Error("a routine shared-clone change failed the run")
|
||||
}
|
||||
if !strings.HasPrefix(report, "NOTE: ") || !strings.Contains(report, routine.detail) || strings.Contains(report, "ERROR") {
|
||||
t.Errorf("report %q, want a NOTE naming %q and no ERROR", report, routine.detail)
|
||||
// The likely writer of a routine change is another process, so the
|
||||
// note says that before it says this suite could have.
|
||||
if !strings.HasPrefix(report, "NOTE: another process") || !strings.Contains(report, routine.detail) || strings.Contains(report, "ERROR") {
|
||||
t.Errorf("report %q, want a NOTE that names another process first, names %q, and has no ERROR", report, routine.detail)
|
||||
}
|
||||
if entries, err := os.ReadDir(saveDir); err != nil || len(entries) != 0 {
|
||||
t.Errorf("save dir holds %v (err %v), want nothing saved for routine changes", entries, err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue