| ... | @@ -1982,6 +1982,59 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => { | ... | @@ -1982,6 +1982,59 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => { |
| 1982 | assert.equal(result.branch, current); | 1982 | assert.equal(result.branch, current); |
| 1983 | }), | 1983 | }), |
| 1984 | ); | 1984 | ); |
| | 1985 | |
| | 1986 | it.effect("rejects a missing branch without restoring a matching dirty file", () => |
| | 1987 | Effect.gen(function* () { |
| | 1988 | const cwd = yield* makeTmpDir(); |
| | 1989 | const { initialBranch } = yield* initRepoWithCommit(cwd); |
| | 1990 | const driver = yield* GitVcsDriver.GitVcsDriver; |
| | 1991 | yield* writeTextFile(cwd, "obsolete-branch", "original\n"); |
| | 1992 | yield* git(cwd, ["add", "obsolete-branch"]); |
| | 1993 | yield* git(cwd, ["commit", "-m", "tracked file"]); |
| | 1994 | yield* git(cwd, ["branch", "obsolete-branch"]); |
| | 1995 | yield* git(cwd, ["branch", "-D", "obsolete-branch"]); |
| | 1996 | yield* writeTextFile(cwd, "obsolete-branch", "uncommitted work\n"); |
| | 1997 | |
| | 1998 | const result = yield* driver |
| | 1999 | .switchRef({ cwd, refName: "obsolete-branch" }) |
| | 2000 | .pipe(Effect.result); |
| | 2001 | |
| | 2002 | assert.equal(result._tag, "Failure"); |
| | 2003 | const fileSystem = yield* FileSystem.FileSystem; |
| | 2004 | const path = yield* Path.Path; |
| | 2005 | assert.equal( |
| | 2006 | yield* fileSystem.readFileString(path.join(cwd, "obsolete-branch")), |
| | 2007 | "uncommitted work\n", |
| | 2008 | ); |
| | 2009 | assert.equal(yield* git(cwd, ["branch", "--show-current"]), initialBranch); |
| | 2010 | }), |
| | 2011 | ); |
| | 2012 | |
| | 2013 | it.effect("still creates and reuses remote tracking branches and allows detached refs", () => |
| | 2014 | Effect.gen(function* () { |
| | 2015 | const cwd = yield* makeTmpDir(); |
| | 2016 | const remote = yield* makeTmpDir("git-remote-"); |
| | 2017 | const { initialBranch } = yield* initRepoWithCommit(cwd); |
| | 2018 | const driver = yield* GitVcsDriver.GitVcsDriver; |
| | 2019 | yield* git(remote, ["init", "--bare"]); |
| | 2020 | yield* git(cwd, ["remote", "add", "origin", remote]); |
| | 2021 | yield* git(cwd, ["push", "origin", "HEAD:refs/heads/remote-only"]); |
| | 2022 | |
| | 2023 | for (let attempt = 0; attempt < 2; attempt += 1) { |
| | 2024 | const result = yield* driver.switchRef({ cwd, refName: "origin/remote-only" }); |
| | 2025 | assert.equal(result.refName, "remote-only"); |
| | 2026 | assert.equal( |
| | 2027 | yield* git(cwd, ["rev-parse", "--abbrev-ref", "@{upstream}"]), |
| | 2028 | "origin/remote-only", |
| | 2029 | ); |
| | 2030 | yield* driver.switchRef({ cwd, refName: initialBranch }); |
| | 2031 | } |
| | 2032 | const commit = yield* git(cwd, ["rev-parse", "HEAD"]); |
| | 2033 | const detached = yield* driver.switchRef({ cwd, refName: commit }); |
| | 2034 | assert.equal(detached.refName, null); |
| | 2035 | assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), commit); |
| | 2036 | }), |
| | 2037 | ); |
| 1985 | }); | 2038 | }); |
| 1986 | | 2039 | |
| 1987 | describe("worktree operations", () => { | 2040 | describe("worktree operations", () => { |