fix: preserve git common dir for adoption locks · Entire

fix: preserve git common dir for adoption locks

0698d69·

Sessions

0ed46044b4c8View transcript

Changes

2

269 unmodified lines

270
271
272
273
274
275
273
274
275

269 unmodified lines

commonDir = filepath.Join(absWorktree, commonDir)
    }
    commonDir = filepath.Clean(commonDir)
    if resolved, err := filepath.EvalSymlinks(commonDir); err == nil {
        commonDir = resolved
    }

return session.NewStateStoreWithDir(filepath.Join(commonDir, session.SessionStateDirName)), sourceRoot, commonDir, nil
}

Mcmd/entire/cli/session_adopt.go-3

1056 unmodified lines

1057
1058
1059
1060
1060
1061
1062
1063
25 unmodified lines

1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130

1056 unmodified lines

}

func TestStateStoreForWorktreeIgnoresGitStderrOnSuccess(t *testing.T) {
    if runtime.GOOS == "windows" {
        if runtime.GOOS == windowsGOOS {
            t.Skip("uses a POSIX shell script fake git")
        }

25 unmodified lines

}
}

func TestStateStoreForWorktreePreservesGitCommonDirSymlink(t *testing.T) {
    if runtime.GOOS == windowsGOOS {
            t.Skip("uses a POSIX shell script fake git")
    }

fakeBin := t.TempDir()
    fakeGit := filepath.Join(fakeBin, "git")
    script := `#!/bin/sh
printf '%s\n%s\n' "$FAKE_WORKTREE_ROOT" "$FAKE_GIT_COMMON_DIR"
`
    if err := os.WriteFile(fakeGit, []byte(script), 0o755); err != nil {
        t.Fatal(err)
    }

sourceRoot := filepath.Join(t.TempDir(), "source")
    realCommonDir := filepath.Join(t.TempDir(), "real-common.git")
    if err := os.MkdirAll(realCommonDir, 0o750); err != nil {
        t.Fatal(err)
    }
    commonDirLink := filepath.Join(t.TempDir(), "common-link.git")
    if err := os.Symlink(realCommonDir, commonDirLink); err != nil {
            t.Skipf("symlinks unavailable: %v", err)
    }
    t.Setenv("PATH", fakeBin+string(os.PathListSeparator)+os.Getenv("PATH"))
    t.Setenv("FAKE_WORKTREE_ROOT", sourceRoot)
    t.Setenv("FAKE_GIT_COMMON_DIR", commonDirLink)

_, _, gotCommonDir, err := stateStoreForWorktree(context.Background(), ".")
    if err != nil {
        t.Fatalf("stateStoreForWorktree failed: %v", err)
    }
    if gotCommonDir != filepath.Clean(commonDirLink) {
        t.Fatalf("commonDir = %q, want git-reported symlink path %q", gotCommonDir, filepath.Clean(commonDirLink))
    }
}

func TestSessionAdopt_SameStoreReloadsSourceStateUnderLock(t *testing.T) {
    sourceRepo := setupAdoptRepo(t)
    targetWorktree := filepath.Join(t.TempDir(), "target-worktree")