forked from chdsbd/vscode-githubinator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.test.ts
More file actions
55 lines (47 loc) · 1.71 KB
/
git.test.ts
File metadata and controls
55 lines (47 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { dir } from "../../git"
import * as assert from "assert"
import * as path from "path"
import * as fs from "fs"
suite("git", async () => {
test("dir", () => {
const repoPath = path.normalize(path.join(__dirname, "../../.."))
const gitPath = path.join(repoPath, ".git")
assert.deepStrictEqual(dir(__dirname), {
git: gitPath,
commonGit: gitPath,
repository: repoPath,
})
assert.deepStrictEqual(dir(repoPath), {
git: gitPath,
commonGit: gitPath,
repository: repoPath,
})
const contents = "gitdir: ../../../../.git/modules/test_submodule"
const submodulePath = path.join(__dirname, "test_submodule")
fs.mkdirSync(submodulePath, { recursive: true })
fs.writeFileSync(path.join(submodulePath, ".git"), contents)
assert.deepStrictEqual(dir(submodulePath), {
git: path.join(repoPath, ".git/modules/test_submodule"),
commonGit: path.join(repoPath, ".git/modules/test_submodule"),
repository: submodulePath,
})
// worktree: gitdir redirect with a commondir file
const worktreeGitDir = path.join(repoPath, ".git/worktrees/my-feature")
fs.mkdirSync(worktreeGitDir, { recursive: true })
fs.writeFileSync(path.join(worktreeGitDir, "commondir"), "../..")
const worktreePath = path.join(__dirname, "test_worktree")
fs.mkdirSync(worktreePath, { recursive: true })
fs.writeFileSync(
path.join(worktreePath, ".git"),
`gitdir: ${worktreeGitDir}`,
)
assert.deepStrictEqual(dir(worktreePath), {
git: worktreeGitDir,
commonGit: gitPath,
repository: worktreePath,
})
// cleanup
fs.rmSync(worktreePath, { recursive: true })
fs.rmSync(worktreeGitDir, { recursive: true })
})
})