| ... | @@ -125,7 +125,7 @@ describe("git integration", () => { | ... | @@ -125,7 +125,7 @@ describe("git integration", () => { |
| 125 | expect(current!.current).toBe(true); | 125 | expect(current!.current).toBe(true); |
| 126 | }); | 126 | }); |
| 127 | | 127 | |
| 128 | it("sorts branches by most recent commit first", async () => { | 128 | it("keeps current branch first and sorts the remaining branches by recency", async () => { |
| 129 | await using tmp = await makeTmpDir(); | 129 | await using tmp = await makeTmpDir(); |
| 130 | await initRepoWithCommit(tmp.path); | 130 | await initRepoWithCommit(tmp.path); |
| 131 | const initialBranch = (await listGitBranches({ cwd: tmp.path })).branches.find( | 131 | const initialBranch = (await listGitBranches({ cwd: tmp.path })).branches.find( |
| ... | @@ -153,11 +153,54 @@ describe("git integration", () => { | ... | @@ -153,11 +153,54 @@ describe("git integration", () => { |
| 153 | "newer branch change", | 153 | "newer branch change", |
| 154 | ); | 154 | ); |
| 155 | | 155 | |
| 156 | // Switch away to show sort order is recency-based, not "current"-based. | 156 | // Switch away to show current branch is pinned, then remaining branches are recency-sorted. |
| 157 | await checkoutGitBranch({ cwd: tmp.path, branch: "older-branch" }); | 157 | await checkoutGitBranch({ cwd: tmp.path, branch: "older-branch" }); |
| 158 | | 158 | |
| 159 | const result = await listGitBranches({ cwd: tmp.path }); | 159 | const result = await listGitBranches({ cwd: tmp.path }); |
| 160 | expect(result.branches[0]!.name).toBe("newer-branch"); | 160 | expect(result.branches[0]!.name).toBe("older-branch"); |
| | 161 | expect(result.branches[1]!.name).toBe("newer-branch"); |
| | 162 | }); |
| | 163 | |
| | 164 | it("keeps default branch right after current branch", async () => { |
| | 165 | await using tmp = await makeTmpDir(); |
| | 166 | await using remote = await makeTmpDir(); |
| | 167 | await initRepoWithCommit(tmp.path); |
| | 168 | const defaultBranch = (await listGitBranches({ cwd: tmp.path })).branches.find( |
| | 169 | (branch) => branch.current, |
| | 170 | )!.name; |
| | 171 | |
| | 172 | await git(remote.path, "init --bare"); |
| | 173 | await git(tmp.path, `remote add origin ${JSON.stringify(remote.path)}`); |
| | 174 | await git(tmp.path, `push -u origin ${defaultBranch}`); |
| | 175 | await git(tmp.path, `remote set-head origin ${defaultBranch}`); |
| | 176 | |
| | 177 | await createGitBranch({ cwd: tmp.path, branch: "current-branch" }); |
| | 178 | await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" }); |
| | 179 | await commitWithDate( |
| | 180 | tmp.path, |
| | 181 | "current.txt", |
| | 182 | "current change\n", |
| | 183 | "Thu, 1 Jan 2037 00:00:00 +0000", |
| | 184 | "current change", |
| | 185 | ); |
| | 186 | |
| | 187 | await checkoutGitBranch({ cwd: tmp.path, branch: defaultBranch }); |
| | 188 | await createGitBranch({ cwd: tmp.path, branch: "newer-branch" }); |
| | 189 | await checkoutGitBranch({ cwd: tmp.path, branch: "newer-branch" }); |
| | 190 | await commitWithDate( |
| | 191 | tmp.path, |
| | 192 | "newer.txt", |
| | 193 | "newer change\n", |
| | 194 | "Fri, 1 Jan 2038 00:00:00 +0000", |
| | 195 | "newer change", |
| | 196 | ); |
| | 197 | |
| | 198 | await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" }); |
| | 199 | |
| | 200 | const result = await listGitBranches({ cwd: tmp.path }); |
| | 201 | expect(result.branches[0]!.name).toBe("current-branch"); |
| | 202 | expect(result.branches[1]!.name).toBe(defaultBranch); |
| | 203 | expect(result.branches[2]!.name).toBe("newer-branch"); |
| 161 | }); | 204 | }); |
| 162 | | 205 | |
| 163 | it("lists multiple branches after creating them", async () => { | 206 | it("lists multiple branches after creating them", async () => { |