gitforest 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +24 -4
- package/src/github/auth.ts +3 -3
- package/src/utils/debug.ts +4 -4
- package/.bunignore +0 -7
- package/.github/workflows/ci.yml +0 -73
- package/CLAUDE.md +0 -111
- package/CONTRIBUTING.md +0 -145
- package/bun.lock +0 -267
- package/bunfig.toml +0 -15
- package/cli +0 -0
- package/docs/ai/IMPROVEMENT_PLAN.md +0 -341
- package/docs/ai/VERIFICATION_REPORT.md +0 -87
- package/docs/ai/architecture.md +0 -169
- package/docs/ai/checks/check-2025-12-02-tests.md +0 -40
- package/docs/ai/checks/check-2025-12-02.md +0 -55
- package/docs/ai/checks/test-verification-report.md +0 -85
- package/docs/ai/implementation-guide.md +0 -776
- package/docs/ai/research/gitty-codebase-analysis.md +0 -221
- package/docs/ai/tickets/GENERAL-sitrep.md +0 -30
- package/docs/ai/tickets/TASK-database-tests-sitrep.md +0 -25
- package/docs/ai/tickets/TASK-deprecated-functions-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-detail-modal-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-filter-overlay-sitrep.md +0 -24
- package/docs/ai/tickets/TASK-github-service-sitrep.md +0 -32
- package/docs/ai/tickets/TASK-github-token-sitrep.md +0 -51
- package/docs/ai/tickets/TASK-hascommits-sitrep.md +0 -35
- package/docs/ai/tickets/TASK-keybindings-sitrep.md +0 -26
- package/docs/ai/tickets/TASK-layout-sitrep.md +0 -25
- package/docs/ai/tickets/TASK-markdown-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-project-item-sitrep.md +0 -79
- package/docs/ai/tickets/TASK-sitrep.md +0 -28
- package/docs/ai/tickets/TASK-state-sitrep.md +0 -26
- package/docs/ai/tickets/TASK-types-sitrep.md +0 -25
- package/docs/ai/tickets/TASK-unified-item-fix-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-001-sitrep.md +0 -24
- package/docs/ai/tickets/TKT-002-sitrep.md +0 -25
- package/docs/ai/tickets/TKT-003-git-service-refactoring-complete.md +0 -46
- package/docs/ai/tickets/TKT-003-git-service-refactoring-plan.md +0 -135
- package/docs/ai/tickets/TKT-003-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-004-sitrep.md +0 -27
- package/docs/ai/tickets/TKT-005-sitrep.md +0 -25
- package/docs/ai/tickets/TKT-006-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-007-sitrep.md +0 -30
- package/docs/ai/tickets/TKT-008-sitrep.md +0 -32
- package/docs/ai/tickets/TKT-009-sitrep.md +0 -27
- package/docs/ai/tickets/TKT-010-sitrep.md +0 -27
- package/docs/ai/tickets/TKT-011-sitrep.md +0 -26
- package/docs/ai/tickets/TKT-012-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-actions-sitrep.md +0 -28
- package/docs/ai/tickets/sitreps/TASK-actions-test-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-app-integration-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-background-fetch-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-background-fetch-test-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-batch-tests-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-bun-test-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-cache-tests-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-cli-tests-sitrep.md +0 -28
- package/docs/ai/tickets/sitreps/TASK-clone-error-handling-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-commands-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-component-tests-1-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-configloader-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-confirm-dialog-test-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-coverage-sitrep.md +0 -95
- package/docs/ai/tickets/sitreps/TASK-database-tests-summary.md +0 -61
- package/docs/ai/tickets/sitreps/TASK-error-boundary-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-error-tests-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-errors-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-extract-reducer-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-filter-overlay-test-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-final-verification-sitrep.md +0 -28
- package/docs/ai/tickets/sitreps/TASK-fix-all-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-fix-hooks-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-fix-remaining-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-fix-test-failures-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-fix-tests-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-formatters-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-git-timeouts-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-github-cache-test-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-githubcli-tests-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-gitstatus-tests-sitrep.md +0 -24
- package/docs/ai/tickets/sitreps/TASK-hooks-isolation-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-keybindings-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-layout-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-mock-factories-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-modal-tests-sitrep.md +0 -32
- package/docs/ai/tickets/sitreps/TASK-processbatch-fix-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-projectlist-tests-sitrep.md +0 -30
- package/docs/ai/tickets/sitreps/TASK-projectutils-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-scanner-tests-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-select-all-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-shell-error-handling-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-store-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-test-fixes-sitrep.md +0 -26
- package/docs/ai/tickets/sitreps/TASK-test-summary-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-test-verification-sitrep.md +0 -27
- package/docs/ai/tickets/sitreps/TASK-testsuite-sitrep.md +0 -75
- package/docs/ai/tickets/sitreps/TASK-unified-reducer-tests-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-unified-repos-test-sitrep.md +0 -29
- package/docs/ai/tickets/sitreps/TASK-unified-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-useprojects-tests-sitrep.md +0 -25
- package/docs/ai/tickets/sitreps/TASK-utility-tests-sitrep.md +0 -32
- package/docs/ai/tickets/sitreps/TKT-003-git-service-refactoring-sitrep.md +0 -64
- package/docs/ai/tkt-001-fix-database-error.md +0 -217
- package/docs/ai/ui-enhancement-plan.md +0 -562
- package/test/integration/app.isolated.tsx +0 -240
- package/test/integration/cli-commands.test.ts +0 -287
- package/test/integration/cli-validation.test.ts +0 -264
- package/test/integration/git-operations.test.ts +0 -218
- package/test/integration/scanner.test.ts +0 -228
- package/test/preload.ts +0 -18
- package/test/unit/cli/commands.test.ts +0 -13
- package/test/unit/cli/formatters.test.ts +0 -1116
- package/test/unit/cli/github-commands.test.ts +0 -12
- package/test/unit/components/CloneDialog.test.tsx +0 -240
- package/test/unit/components/ColumnHeader.test.tsx +0 -128
- package/test/unit/components/CommandPalette.test.tsx +0 -355
- package/test/unit/components/ConfirmDialog.test.tsx +0 -111
- package/test/unit/components/ErrorBoundary.test.tsx +0 -139
- package/test/unit/components/FilterBar.test.tsx +0 -43
- package/test/unit/components/FilterOptionsOverlay.test.tsx +0 -197
- package/test/unit/components/HelpOverlay.test.tsx +0 -90
- package/test/unit/components/Layout.test.tsx +0 -328
- package/test/unit/components/MarkdownRenderer.test.tsx +0 -45
- package/test/unit/components/ProgressBar.test.tsx +0 -138
- package/test/unit/components/ProjectItem.test.tsx +0 -182
- package/test/unit/components/ProjectList.test.tsx +0 -311
- package/test/unit/components/RepoDetailModal.test.tsx +0 -445
- package/test/unit/components/StatusBar.test.tsx +0 -112
- package/test/unit/components/UnifiedProjectItem.test.tsx +0 -618
- package/test/unit/components/ViewModeIndicator.test.tsx +0 -137
- package/test/unit/components/test-utils.tsx +0 -63
- package/test/unit/config/loader.test.ts +0 -692
- package/test/unit/db/database.test.ts +0 -978
- package/test/unit/db/index.test.ts +0 -314
- package/test/unit/fixtures/setup.ts +0 -186
- package/test/unit/git/commands-untested.test.ts +0 -205
- package/test/unit/git/commands.test.ts +0 -269
- package/test/unit/git/operations.test.ts +0 -322
- package/test/unit/git/status.test.ts +0 -219
- package/test/unit/github/auth.test.ts +0 -317
- package/test/unit/github/cache.test.ts +0 -1028
- package/test/unit/github/cli.test.ts +0 -135
- package/test/unit/github/unified.test.ts +0 -1201
- package/test/unit/graceful-shutdown.test.ts +0 -83
- package/test/unit/hooks/useBackgroundFetch.test.tsx +0 -239
- package/test/unit/hooks/useConfirmDialogActions.test.tsx +0 -81
- package/test/unit/hooks/useKeyBindings.isolated.ts +0 -715
- package/test/unit/hooks/useProjects.test.tsx +0 -186
- package/test/unit/hooks/useUnifiedRepos-simple.test.tsx +0 -115
- package/test/unit/hooks/useUnifiedRepos.test.tsx +0 -177
- package/test/unit/mocks/config.ts +0 -109
- package/test/unit/mocks/git-service.ts +0 -274
- package/test/unit/mocks/github-service.ts +0 -250
- package/test/unit/mocks/index.ts +0 -72
- package/test/unit/mocks/project.ts +0 -148
- package/test/unit/mocks/state-mocks.ts +0 -187
- package/test/unit/mocks/unified.ts +0 -169
- package/test/unit/operations/batch.test.ts +0 -216
- package/test/unit/operations/commands.test.ts +0 -550
- package/test/unit/scanner/errors.test.ts +0 -297
- package/test/unit/scanner/index.test.ts +0 -1011
- package/test/unit/scanner/markers.test.ts +0 -150
- package/test/unit/scanner/submodules.test.ts +0 -99
- package/test/unit/services/git-errors.test.ts +0 -190
- package/test/unit/services/git.test.ts +0 -442
- package/test/unit/services/github-errors.test.ts +0 -293
- package/test/unit/services/github.test.ts +0 -200
- package/test/unit/state/actions.test.ts +0 -217
- package/test/unit/state/reducer.test.ts +0 -745
- package/test/unit/state/store.test.tsx +0 -711
- package/test/unit/types/commands.test.ts +0 -220
- package/test/unit/types/schema.test.ts +0 -179
- package/test/unit/utils/array.test.ts +0 -73
- package/test/unit/utils/debug.test.ts +0 -23
- package/test/unit/utils/errors.test.ts +0 -295
- package/test/unit/utils/markdown.test.ts +0 -163
- package/test/unit/utils/project-utils.test.ts +0 -756
- package/test/unit/utils/rate-limiter.test.ts +0 -256
- package/test/unit/utils/retry.test.ts +0 -165
- package/test/unit/utils/strip-ansi.ts +0 -13
- package/test/unit/utils/timeout.test.ts +0 -93
- package/tsconfig.json +0 -29
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
2
|
-
import {
|
|
3
|
-
isGitRepo,
|
|
4
|
-
getGitRoot,
|
|
5
|
-
getGitStatusPorcelain,
|
|
6
|
-
getCurrentBranch,
|
|
7
|
-
getRemoteUrl,
|
|
8
|
-
getLastCommitDate,
|
|
9
|
-
initGit,
|
|
10
|
-
listSubmodules,
|
|
11
|
-
isSubmodule,
|
|
12
|
-
} from "../../../src/git/commands.ts";
|
|
13
|
-
import {
|
|
14
|
-
createTempDir,
|
|
15
|
-
cleanupTempDir,
|
|
16
|
-
createMockGitRepo,
|
|
17
|
-
createMockProject,
|
|
18
|
-
createMockRepoWithSubmodule,
|
|
19
|
-
} from "../fixtures/setup.ts";
|
|
20
|
-
|
|
21
|
-
describe("isGitRepo", () => {
|
|
22
|
-
let tempDir: string;
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
tempDir = createTempDir("git-commands-test");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
cleanupTempDir(tempDir);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("returns true for git repository", async () => {
|
|
33
|
-
const repoPath = await createMockGitRepo(tempDir, "test-repo");
|
|
34
|
-
const result = await isGitRepo(repoPath);
|
|
35
|
-
expect(result).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("returns false for non-git directory", async () => {
|
|
39
|
-
const projectPath = createMockProject(tempDir, "non-git", "package.json");
|
|
40
|
-
const result = await isGitRepo(projectPath);
|
|
41
|
-
expect(result).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("returns false for non-existent directory", async () => {
|
|
45
|
-
const result = await isGitRepo("/non/existent/path");
|
|
46
|
-
expect(result).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe("getGitRoot", () => {
|
|
51
|
-
let tempDir: string;
|
|
52
|
-
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
tempDir = createTempDir("git-root-test");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
cleanupTempDir(tempDir);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test("returns git root path", async () => {
|
|
62
|
-
const repoPath = await createMockGitRepo(tempDir, "test-repo");
|
|
63
|
-
const result = await getGitRoot(repoPath);
|
|
64
|
-
expect(result).toBe(repoPath);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("returns null for non-git directory", async () => {
|
|
68
|
-
const projectPath = createMockProject(tempDir, "non-git", "package.json");
|
|
69
|
-
const result = await getGitRoot(projectPath);
|
|
70
|
-
expect(result).toBeNull();
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe("getGitStatusPorcelain", () => {
|
|
75
|
-
let tempDir: string;
|
|
76
|
-
|
|
77
|
-
beforeEach(() => {
|
|
78
|
-
tempDir = createTempDir("git-status-test");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
afterEach(() => {
|
|
82
|
-
cleanupTempDir(tempDir);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("returns empty string for clean repo", async () => {
|
|
86
|
-
const repoPath = await createMockGitRepo(tempDir, "clean-repo");
|
|
87
|
-
const result = await getGitStatusPorcelain(repoPath);
|
|
88
|
-
expect(result.trim()).toBe("");
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("returns modified status for changed files", async () => {
|
|
92
|
-
const repoPath = await createMockGitRepo(tempDir, "dirty-repo", {
|
|
93
|
-
withChanges: true,
|
|
94
|
-
});
|
|
95
|
-
const result = await getGitStatusPorcelain(repoPath);
|
|
96
|
-
expect(result).toContain("M");
|
|
97
|
-
expect(result).toContain("README.md");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("returns untracked status for new files", async () => {
|
|
101
|
-
const repoPath = await createMockGitRepo(tempDir, "untracked-repo", {
|
|
102
|
-
withUntracked: true,
|
|
103
|
-
});
|
|
104
|
-
const result = await getGitStatusPorcelain(repoPath);
|
|
105
|
-
expect(result).toContain("??");
|
|
106
|
-
expect(result).toContain("untracked.txt");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("returns staged status for staged files", async () => {
|
|
110
|
-
const repoPath = await createMockGitRepo(tempDir, "staged-repo", {
|
|
111
|
-
withStaged: true,
|
|
112
|
-
});
|
|
113
|
-
const result = await getGitStatusPorcelain(repoPath);
|
|
114
|
-
expect(result).toContain("A");
|
|
115
|
-
expect(result).toContain("staged.txt");
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("getCurrentBranch", () => {
|
|
120
|
-
let tempDir: string;
|
|
121
|
-
|
|
122
|
-
beforeEach(() => {
|
|
123
|
-
tempDir = createTempDir("git-branch-test");
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
afterEach(() => {
|
|
127
|
-
cleanupTempDir(tempDir);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("returns main/master branch for new repo", async () => {
|
|
131
|
-
const repoPath = await createMockGitRepo(tempDir, "test-repo");
|
|
132
|
-
const result = await getCurrentBranch(repoPath);
|
|
133
|
-
// Git version dependent - could be main or master
|
|
134
|
-
expect(["main", "master"]).toContain(result);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test("returns unknown for non-git directory", async () => {
|
|
138
|
-
const projectPath = createMockProject(tempDir, "non-git", "package.json");
|
|
139
|
-
const result = await getCurrentBranch(projectPath);
|
|
140
|
-
expect(result).toBe("unknown");
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe("getRemoteUrl", () => {
|
|
145
|
-
let tempDir: string;
|
|
146
|
-
|
|
147
|
-
beforeEach(() => {
|
|
148
|
-
tempDir = createTempDir("git-remote-test");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
afterEach(() => {
|
|
152
|
-
cleanupTempDir(tempDir);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test("returns null when no remote configured", async () => {
|
|
156
|
-
const repoPath = await createMockGitRepo(tempDir, "no-remote-repo");
|
|
157
|
-
const result = await getRemoteUrl(repoPath);
|
|
158
|
-
expect(result).toBeNull();
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe("getLastCommitDate", () => {
|
|
163
|
-
let tempDir: string;
|
|
164
|
-
|
|
165
|
-
beforeEach(() => {
|
|
166
|
-
tempDir = createTempDir("git-date-test");
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
afterEach(() => {
|
|
170
|
-
cleanupTempDir(tempDir);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test("returns Date object for repo with commits", async () => {
|
|
174
|
-
const repoPath = await createMockGitRepo(tempDir, "dated-repo");
|
|
175
|
-
const result = await getLastCommitDate(repoPath);
|
|
176
|
-
expect(result).toBeInstanceOf(Date);
|
|
177
|
-
expect(result!.getTime()).toBeLessThanOrEqual(Date.now());
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("returns null for non-git directory", async () => {
|
|
181
|
-
const projectPath = createMockProject(tempDir, "non-git", "package.json");
|
|
182
|
-
const result = await getLastCommitDate(projectPath);
|
|
183
|
-
expect(result).toBeNull();
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe("initGit", () => {
|
|
188
|
-
let tempDir: string;
|
|
189
|
-
|
|
190
|
-
beforeEach(() => {
|
|
191
|
-
tempDir = createTempDir("git-init-test");
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
afterEach(() => {
|
|
195
|
-
cleanupTempDir(tempDir);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("initializes git in directory", async () => {
|
|
199
|
-
const projectPath = createMockProject(tempDir, "init-test", "package.json");
|
|
200
|
-
|
|
201
|
-
// Verify not a git repo before
|
|
202
|
-
expect(await isGitRepo(projectPath)).toBe(false);
|
|
203
|
-
|
|
204
|
-
// Initialize git
|
|
205
|
-
const result = await initGit(projectPath);
|
|
206
|
-
expect(result).toBe(true);
|
|
207
|
-
|
|
208
|
-
// Verify it's now a git repo
|
|
209
|
-
expect(await isGitRepo(projectPath)).toBe(true);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe("listSubmodules", () => {
|
|
214
|
-
let tempDir: string;
|
|
215
|
-
|
|
216
|
-
beforeEach(() => {
|
|
217
|
-
tempDir = createTempDir("git-submodule-test");
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
afterEach(() => {
|
|
221
|
-
cleanupTempDir(tempDir);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("returns empty array for repo without submodules", async () => {
|
|
225
|
-
const repoPath = await createMockGitRepo(tempDir, "no-submodules");
|
|
226
|
-
const result = await listSubmodules(repoPath);
|
|
227
|
-
expect(result).toEqual([]);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test("returns submodule info for repo with submodules", async () => {
|
|
231
|
-
const { parentPath } = await createMockRepoWithSubmodule(
|
|
232
|
-
tempDir,
|
|
233
|
-
"parent",
|
|
234
|
-
"submodule"
|
|
235
|
-
);
|
|
236
|
-
const result = await listSubmodules(parentPath);
|
|
237
|
-
|
|
238
|
-
expect(result).toHaveLength(1);
|
|
239
|
-
expect(result[0]?.path).toBe("submodule");
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
describe("isSubmodule", () => {
|
|
244
|
-
let tempDir: string;
|
|
245
|
-
|
|
246
|
-
beforeEach(() => {
|
|
247
|
-
tempDir = createTempDir("git-is-submodule-test");
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
afterEach(() => {
|
|
251
|
-
cleanupTempDir(tempDir);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test("returns false for regular git repo", async () => {
|
|
255
|
-
const repoPath = await createMockGitRepo(tempDir, "regular-repo");
|
|
256
|
-
const result = await isSubmodule(repoPath);
|
|
257
|
-
expect(result).toBe(false);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
test("returns true for submodule", async () => {
|
|
261
|
-
const { submodulePath } = await createMockRepoWithSubmodule(
|
|
262
|
-
tempDir,
|
|
263
|
-
"parent",
|
|
264
|
-
"submodule"
|
|
265
|
-
);
|
|
266
|
-
const result = await isSubmodule(submodulePath);
|
|
267
|
-
expect(result).toBe(true);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for git operations module
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
6
|
-
import {
|
|
7
|
-
initGitInProject,
|
|
8
|
-
pullProject,
|
|
9
|
-
pushProject,
|
|
10
|
-
fetchProject,
|
|
11
|
-
addRemoteToProject,
|
|
12
|
-
refreshProjectStatuses,
|
|
13
|
-
} from "../../../src/git/operations.ts";
|
|
14
|
-
import { createTempDir, cleanupTempDir, createMockGitRepo } from "../fixtures/setup.ts";
|
|
15
|
-
import { writeFile } from "fs/promises";
|
|
16
|
-
import { join } from "path";
|
|
17
|
-
import { $ } from "bun";
|
|
18
|
-
import type { Project } from "../../../src/types/index.ts";
|
|
19
|
-
|
|
20
|
-
describe("Git Operations", () => {
|
|
21
|
-
let tempDir: string;
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
tempDir = createTempDir("git-operations");
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
cleanupTempDir(tempDir);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe("initGitInProject", () => {
|
|
32
|
-
test("initializes git repository successfully", async () => {
|
|
33
|
-
const repoPath = join(tempDir, "new-repo");
|
|
34
|
-
|
|
35
|
-
// Create directory first - initGit doesn't create it
|
|
36
|
-
await $`mkdir -p ${repoPath}`.quiet();
|
|
37
|
-
|
|
38
|
-
const result = await initGitInProject(repoPath);
|
|
39
|
-
|
|
40
|
-
expect(result.success).toBe(true);
|
|
41
|
-
expect(result.operation).toBe("init");
|
|
42
|
-
expect(result.projectPath).toBe(repoPath);
|
|
43
|
-
expect(result.message).toBe("Git repository initialized");
|
|
44
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("handles initialization failure", async () => {
|
|
48
|
-
// Use a file instead of directory to cause failure
|
|
49
|
-
const invalidPath = join(tempDir, "not-a-dir.txt");
|
|
50
|
-
await writeFile(invalidPath, "This is a file, not a directory");
|
|
51
|
-
|
|
52
|
-
const result = await initGitInProject(invalidPath);
|
|
53
|
-
|
|
54
|
-
expect(result.success).toBe(false);
|
|
55
|
-
expect(result.operation).toBe("init");
|
|
56
|
-
expect(result.projectPath).toBe(invalidPath);
|
|
57
|
-
expect(result.error).toBeDefined();
|
|
58
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("pullProject", () => {
|
|
63
|
-
test("pulls changes successfully", async () => {
|
|
64
|
-
const repoPath = await createMockGitRepo(tempDir, "pull-test");
|
|
65
|
-
|
|
66
|
-
// Pull will fail because there's no remote configured yet
|
|
67
|
-
// So we expect success to be false
|
|
68
|
-
const result = await pullProject(repoPath);
|
|
69
|
-
|
|
70
|
-
expect(result.success).toBe(false);
|
|
71
|
-
expect(result.operation).toBe("pull");
|
|
72
|
-
expect(result.projectPath).toBe(repoPath);
|
|
73
|
-
expect(result.error).toBeDefined();
|
|
74
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("handles pull failure", async () => {
|
|
78
|
-
const repoPath = await createMockGitRepo(tempDir, "pull-fail");
|
|
79
|
-
|
|
80
|
-
// Pull will fail because there's no remote configured
|
|
81
|
-
const result = await pullProject(repoPath);
|
|
82
|
-
|
|
83
|
-
expect(result.success).toBe(false);
|
|
84
|
-
expect(result.operation).toBe("pull");
|
|
85
|
-
expect(result.projectPath).toBe(repoPath);
|
|
86
|
-
expect(result.error).toBeDefined();
|
|
87
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("pushProject", () => {
|
|
92
|
-
test("pushes changes successfully", async () => {
|
|
93
|
-
const repoPath = await createMockGitRepo(tempDir, "push-test");
|
|
94
|
-
|
|
95
|
-
// Add a remote and make a commit
|
|
96
|
-
await writeFile(join(repoPath, "test.txt"), "content");
|
|
97
|
-
await $`git -C ${repoPath} add test.txt`.quiet();
|
|
98
|
-
await $`git -C ${repoPath} commit -m "test"`.quiet();
|
|
99
|
-
|
|
100
|
-
const result = await pushProject(repoPath);
|
|
101
|
-
|
|
102
|
-
// Push will fail because remote doesn't actually exist
|
|
103
|
-
expect(result.success).toBe(false);
|
|
104
|
-
expect(result.operation).toBe("push");
|
|
105
|
-
expect(result.projectPath).toBe(repoPath);
|
|
106
|
-
expect(result.error).toBeDefined();
|
|
107
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test("pushes with setUpstream flag", async () => {
|
|
111
|
-
const repoPath = await createMockGitRepo(tempDir, "push-upstream");
|
|
112
|
-
|
|
113
|
-
// Add a remote and make a commit
|
|
114
|
-
await writeFile(join(repoPath, "test.txt"), "content");
|
|
115
|
-
await $`git -C ${repoPath} add test.txt`.quiet();
|
|
116
|
-
await $`git -C ${repoPath} commit -m "test"`.quiet();
|
|
117
|
-
|
|
118
|
-
const result = await pushProject(repoPath, true);
|
|
119
|
-
|
|
120
|
-
// Push will fail because remote doesn't actually exist
|
|
121
|
-
expect(result.success).toBe(false);
|
|
122
|
-
expect(result.operation).toBe("push");
|
|
123
|
-
expect(result.projectPath).toBe(repoPath);
|
|
124
|
-
expect(result.error).toBeDefined();
|
|
125
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("handles push failure", async () => {
|
|
129
|
-
const repoPath = await createMockGitRepo(tempDir, "push-fail");
|
|
130
|
-
|
|
131
|
-
// Push will fail because there's no remote configured
|
|
132
|
-
const result = await pushProject(repoPath);
|
|
133
|
-
|
|
134
|
-
expect(result.success).toBe(false);
|
|
135
|
-
expect(result.operation).toBe("push");
|
|
136
|
-
expect(result.projectPath).toBe(repoPath);
|
|
137
|
-
expect(result.error).toBeDefined();
|
|
138
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe("fetchProject", () => {
|
|
143
|
-
test("fetches clean repo successfully", async () => {
|
|
144
|
-
const repoPath = await createMockGitRepo(tempDir, "fetch-success");
|
|
145
|
-
|
|
146
|
-
const result = await fetchProject(repoPath);
|
|
147
|
-
|
|
148
|
-
expect(result.success).toBe(true);
|
|
149
|
-
expect(result.operation).toBe("fetch-all");
|
|
150
|
-
expect(result.projectPath).toBe(repoPath);
|
|
151
|
-
expect(result.message).toBe("Fetch all successful");
|
|
152
|
-
expect(result.duration).toBeGreaterThan(0);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe("addRemoteToProject", () => {
|
|
157
|
-
test("adds remote successfully", async () => {
|
|
158
|
-
const repoPath = await createMockGitRepo(tempDir, "add-remote");
|
|
159
|
-
|
|
160
|
-
const result = await addRemoteToProject(
|
|
161
|
-
repoPath,
|
|
162
|
-
"https://github.com/test/repo.git",
|
|
163
|
-
"origin"
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
expect(result.success).toBe(true);
|
|
167
|
-
expect(result.operation).toBe("add-remote");
|
|
168
|
-
expect(result.projectPath).toBe(repoPath);
|
|
169
|
-
expect(result.message).toBe("Remote 'origin' added");
|
|
170
|
-
expect(result.duration).toBeGreaterThan(0);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test("adds remote with custom name", async () => {
|
|
174
|
-
const repoPath = await createMockGitRepo(tempDir, "add-custom-remote");
|
|
175
|
-
|
|
176
|
-
const result = await addRemoteToProject(
|
|
177
|
-
repoPath,
|
|
178
|
-
"https://github.com/test/upstream.git",
|
|
179
|
-
"upstream"
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
expect(result.success).toBe(true);
|
|
183
|
-
expect(result.operation).toBe("add-remote");
|
|
184
|
-
expect(result.projectPath).toBe(repoPath);
|
|
185
|
-
expect(result.message).toBe("Remote 'upstream' added");
|
|
186
|
-
expect(result.duration).toBeGreaterThan(0);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test("handles add remote failure - invalid URL", async () => {
|
|
190
|
-
const repoPath = await createMockGitRepo(tempDir, "add-remote-fail");
|
|
191
|
-
|
|
192
|
-
const result = await addRemoteToProject(
|
|
193
|
-
repoPath,
|
|
194
|
-
"invalid-url",
|
|
195
|
-
"origin"
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
// Git accepts invalid URLs - it only fails when trying to fetch/push
|
|
199
|
-
expect(result.success).toBe(true);
|
|
200
|
-
expect(result.operation).toBe("add-remote");
|
|
201
|
-
expect(result.projectPath).toBe(repoPath);
|
|
202
|
-
expect(result.message).toBe("Remote 'origin' added");
|
|
203
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test("handles add remote failure - remote exists", async () => {
|
|
207
|
-
const repoPath = await createMockGitRepo(tempDir, "add-remote-exists");
|
|
208
|
-
|
|
209
|
-
// Add a remote first
|
|
210
|
-
await writeFile(join(repoPath, "test.txt"), "content");
|
|
211
|
-
await $`git -C ${repoPath} remote add origin https://github.com/test/repo.git`.quiet();
|
|
212
|
-
|
|
213
|
-
const result = await addRemoteToProject(
|
|
214
|
-
repoPath,
|
|
215
|
-
"https://github.com/test/repo2.git",
|
|
216
|
-
"origin"
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
// addRemote returns false on failure but doesn't throw
|
|
220
|
-
expect(result.success).toBe(false);
|
|
221
|
-
expect(result.operation).toBe("add-remote");
|
|
222
|
-
expect(result.projectPath).toBe(repoPath);
|
|
223
|
-
expect(result.error).toBeDefined(); // No error string, just success: false
|
|
224
|
-
expect(result.duration).toBeGreaterThanOrEqual(0);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe("refreshProjectStatuses", () => {
|
|
229
|
-
test("refreshes statuses for multiple projects", async () => {
|
|
230
|
-
const projects: Project[] = [];
|
|
231
|
-
|
|
232
|
-
// Create multiple mock repos
|
|
233
|
-
for (let i = 0; i < 3; i++) {
|
|
234
|
-
const repoPath = await createMockGitRepo(tempDir, `repo-${i}`);
|
|
235
|
-
projects.push({
|
|
236
|
-
id: `repo-${i}`,
|
|
237
|
-
name: `repo-${i}`,
|
|
238
|
-
path: repoPath,
|
|
239
|
-
type: "git",
|
|
240
|
-
projectMarker: null,
|
|
241
|
-
status: null,
|
|
242
|
-
submodule: null,
|
|
243
|
-
lastScanned: new Date(),
|
|
244
|
-
lastModified: null,
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const results = await refreshProjectStatuses(projects);
|
|
249
|
-
|
|
250
|
-
expect(results.size).toBe(3);
|
|
251
|
-
|
|
252
|
-
// Check that each project was updated
|
|
253
|
-
for (const project of projects) {
|
|
254
|
-
const updated = results.get(project.id);
|
|
255
|
-
expect(updated).toBeTruthy();
|
|
256
|
-
expect(updated?.lastScanned.getTime()).toBeGreaterThan(
|
|
257
|
-
project.lastScanned.getTime()
|
|
258
|
-
);
|
|
259
|
-
expect(updated?.status).toBeTruthy();
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
test("handles non-git projects gracefully", async () => {
|
|
264
|
-
const projects: Project[] = [
|
|
265
|
-
{
|
|
266
|
-
id: "non-git-1",
|
|
267
|
-
name: "non-git-1",
|
|
268
|
-
path: tempDir,
|
|
269
|
-
type: "non-git",
|
|
270
|
-
projectMarker: "package.json",
|
|
271
|
-
status: null,
|
|
272
|
-
submodule: null,
|
|
273
|
-
lastScanned: new Date(),
|
|
274
|
-
lastModified: null,
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
id: "non-git-2",
|
|
278
|
-
name: "non-git-2",
|
|
279
|
-
path: join(tempDir, "empty"),
|
|
280
|
-
type: "non-git",
|
|
281
|
-
projectMarker: null,
|
|
282
|
-
status: null,
|
|
283
|
-
submodule: null,
|
|
284
|
-
lastScanned: new Date(),
|
|
285
|
-
lastModified: null,
|
|
286
|
-
},
|
|
287
|
-
];
|
|
288
|
-
|
|
289
|
-
const results = await refreshProjectStatuses(projects);
|
|
290
|
-
|
|
291
|
-
// refreshProjectStatuses filters out non-git projects
|
|
292
|
-
expect(results.size).toBe(0);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
test("handles errors gracefully", async () => {
|
|
296
|
-
const projects: Project[] = [
|
|
297
|
-
{
|
|
298
|
-
id: "error-repo",
|
|
299
|
-
name: "error-repo",
|
|
300
|
-
path: "/invalid/path",
|
|
301
|
-
type: "git",
|
|
302
|
-
projectMarker: null,
|
|
303
|
-
status: null,
|
|
304
|
-
submodule: null,
|
|
305
|
-
lastScanned: new Date(),
|
|
306
|
-
lastModified: null,
|
|
307
|
-
},
|
|
308
|
-
];
|
|
309
|
-
|
|
310
|
-
const results = await refreshProjectStatuses(projects);
|
|
311
|
-
|
|
312
|
-
expect(results.size).toBe(1);
|
|
313
|
-
|
|
314
|
-
// Error should be handled, project returned unchanged
|
|
315
|
-
const errorRepo = results.get("error-repo");
|
|
316
|
-
expect(errorRepo).toBeTruthy();
|
|
317
|
-
// Status should be set even on error (hasCommits returns false)
|
|
318
|
-
expect(errorRepo?.status).toBeDefined();
|
|
319
|
-
expect(errorRepo?.status?.hasCommits).toBe(false);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
});
|