Skip to content
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
CC: clang
CXX: clang++
npm_config_clang: 1
- os: windows-latest
- os: windows-2022
env: {}
- os: macos-latest
env:
Expand All @@ -40,5 +40,12 @@ jobs:
run: |
npm run prepare
npm install
# Diagnostic only. The specs build their repositories under `os.tmpdir()`,
# so this reports whether the runner hands us that path in 8.3 short form
# (e.g. `RUNNER~1`) or behind a symlink — the cases `relativize` has to
# resolve. Without this, a green run tells us nothing about whether those
# paths were ever exercised.
- name: Report path forms
run: node -e "const os=require('os'),fs=require('fs');const show=(l,p)=>{let r;try{r=fs.realpathSync.native(p)}catch(e){r='<'+e.code+'>'}console.log(l.padEnd(8),JSON.stringify(p),'->',JSON.stringify(r),/~[0-9]/.test(p)?'[8.3 SHORT NAME]':'',r!==p?'[DIFFERS]':'')};show('tmpdir',os.tmpdir());show('cwd',process.cwd());show('homedir',os.homedir())"
- name: Run tests
run: npm test
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ remote tracking branch exists.
Returns an object with `ahead` and `behind` keys pointing to integer values
that will always be >= 0.

### Repository.getCommitCount(fromCommit, toCommit)

Get the number of commits between `fromCommit` and `toCommit`.

`fromCommit` - The string commit SHA-1 to start the rev walk at.

`toCommit` - The string commit SHA-1 to end the rev walk at.

Returns the number of commits between the two, always >= 0.

### Repository.getConfigValue(key)

Get the config value of the given key.
Expand Down Expand Up @@ -170,17 +160,6 @@ object has `oldStart`, `oldLines`, `newStart`, `newLines`, `oldLineNumber` and
`newLineNumber` keys pointing to integer values, and a `line` key pointing to the
respective line content. May be `null` if the diff fails.

### Repository.getMergeBase(commit1, commit2)

Get the merge base of two commits.

`commit1` - The string SHA-1 of the first commit.

`commit2` - The string SHA-1 of the second commit.

Returns the string SHA-1 of the merge base of `commit1` and `commit2` or `null`
if there isn't one.

### Repository.getPath()

Get the path of the repository.
Expand Down
41 changes: 37 additions & 4 deletions spec/git-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const _ = require('underscore')
describe('git', () => {
let repo

afterEach(() => {
if (repo) repo.release()
})
afterEach(() => repo?.release())

describe('.open(path)', () => {
describe('when the path is a repository', () => {
Expand Down Expand Up @@ -992,6 +990,38 @@ describe('git', () => {
})
})

describe('when the path is resolved through a symlink it was not opened by', () => {
it('relativizes paths that do not exist on disk', () => {
// Creating a symlink on Windows requires administrator permission, so
// we just skip this test.
if (process.platform === 'win32') { return }

const repoDirectory = fs.realpathSync(temp.mkdirSync('node-git-repo-'))
const linkDirectory = path.join(fs.realpathSync(temp.mkdirSync('node-git-repo-')), 'link')
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures/master.git'), path.join(repoDirectory, '.git'))
fs.mkdirSync(path.join(repoDirectory, 'real-dir'))
fs.symlinkSync(repoDirectory, linkDirectory)

// Opening by the real path means `openedWorkingDirectory` is never
// set, so a query through the symlink cannot be satisfied by comparing
// strings — it has to be resolved against the filesystem.
repo = git.open(repoDirectory)
expect(repo.openedWorkingDirectory).toBeUndefined()

// None of these paths exist, which is the point: resolving a path
// can only be done against something that does exist, so this has to
// walk up to the nearest real ancestor and reattach the rest. That is
// the same machinery that expands 8.3 short names on Windows.
expect(repo.relativize(path.join(linkDirectory, 'ghost.txt'))).toBe('ghost.txt')
expect(repo.relativize(path.join(linkDirectory, 'real-dir/ghost.txt'))).toBe('real-dir/ghost.txt')
expect(repo.relativize(path.join(linkDirectory, 'a/b/c/ghost.txt'))).toBe('a/b/c/ghost.txt')

// The directory itself, and something genuinely outside the repo.
expect(repo.relativize(linkDirectory)).toBe('')
expect(repo.relativize('/not/in/working/dir')).toBe('/not/in/working/dir')
})
})

it('handles case insensitive filesystems', () => {
const repoDirectory = temp.mkdirSync('lower-case-repo-')
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures/master.git'), path.join(repoDirectory, '.git'))
Expand Down Expand Up @@ -1030,6 +1060,7 @@ describe('git', () => {
repo.caseInsensitiveFs = true
workingDirectory = repo.getWorkingDirectory()

expect(repo.isWorkingDirectory(repoDirectory)).toBe(true)
expect(repo.isWorkingDirectory(workingDirectory.toUpperCase())).toBe(true)
})
})
Expand Down Expand Up @@ -1116,7 +1147,9 @@ describe('git', () => {
expect(repo.submoduleForPath('sub1')).toBe(null)

let submoduleRepoPath = path.join(repo.getPath(), 'modules', 'sub/')
if (process.platform === 'win32') { submoduleRepoPath = submoduleRepoPath.replace(/\\/g, '/') }
if (process.platform === 'win32') {
submoduleRepoPath = submoduleRepoPath.replace(/\\/g, '/')
}

expect(repo.submoduleForPath('sub').getPath()).toBe(submoduleRepoPath)
expect(repo.submoduleForPath('sub/').getPath()).toBe(submoduleRepoPath)
Expand Down
Loading
Loading