mirror of https://github.com/atom/atom.git
🐛 Recognize git worktree directories as valid git repositories
fixes #8168
This commit is contained in:
parent
0398a2eccf
commit
15c7ea0c72
|
@ -7,3 +7,5 @@
|
|||
[remote "origin"]
|
||||
url = https://github.com/example-user/example-repo.git
|
||||
fetch = +refs/heads/*:refs/remotes/origin/*
|
||||
[gc]
|
||||
worktreePruneExpire = never
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ef046e9eecaa5255ea5e9817132d4001724d6ae1
|
|
@ -0,0 +1 @@
|
|||
../..
|
Binary file not shown.
|
@ -97,6 +97,25 @@ describe('GitRepositoryProvider', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('when specified a Directory with a commondir file for a worktree', () => {
|
||||
it('returns a Promise that resolves to a GitRepository', async () => {
|
||||
const directory = new Directory(
|
||||
path.join(
|
||||
__dirname,
|
||||
'fixtures',
|
||||
'git',
|
||||
'master.git',
|
||||
'worktrees',
|
||||
'worktree-dir'
|
||||
)
|
||||
);
|
||||
const result = await provider.repositoryForDirectory(directory);
|
||||
expect(result).toBeInstanceOf(GitRepository);
|
||||
expect(provider.pathToRepository[result.getPath()]).toBeTruthy();
|
||||
expect(result.getType()).toBe('git');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when specified a Directory without exists()', () => {
|
||||
let directory;
|
||||
|
||||
|
@ -193,6 +212,25 @@ describe('GitRepositoryProvider', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('when specified a Directory with a commondir file for a worktree', () => {
|
||||
it('returns a Promise that resolves to a GitRepository', () => {
|
||||
const directory = new Directory(
|
||||
path.join(
|
||||
__dirname,
|
||||
'fixtures',
|
||||
'git',
|
||||
'master.git',
|
||||
'worktrees',
|
||||
'worktree-dir'
|
||||
)
|
||||
);
|
||||
const result = provider.repositoryForDirectorySync(directory);
|
||||
expect(result).toBeInstanceOf(GitRepository);
|
||||
expect(provider.pathToRepository[result.getPath()]).toBeTruthy();
|
||||
expect(result.getType()).toBe('git');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when specified a Directory without existsSync()', () => {
|
||||
let directory;
|
||||
|
||||
|
|
|
@ -99,10 +99,22 @@ function isValidGitDirectorySync(directory) {
|
|||
// To decide whether a directory has a valid .git folder, we use
|
||||
// the heuristic adopted by the valid_repository_path() function defined in
|
||||
// node_modules/git-utils/deps/libgit2/src/repository.c.
|
||||
const commonDirFile = directory.getSubdirectory('commondir');
|
||||
let commonDir;
|
||||
if (commonDirFile.existsSync()) {
|
||||
const commonDirPathBuff = fs.readFileSync(commonDirFile.getPath());
|
||||
const commonDirPathString = commonDirPathBuff.toString().trim();
|
||||
commonDir = new Directory(directory.resolve(commonDirPathString));
|
||||
if (!commonDir.existsSync()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
commonDir = directory;
|
||||
}
|
||||
return (
|
||||
directory.getSubdirectory('objects').existsSync() &&
|
||||
directory.getFile('HEAD').existsSync() &&
|
||||
directory.getSubdirectory('refs').existsSync()
|
||||
commonDir.getSubdirectory('objects').existsSync() &&
|
||||
commonDir.getSubdirectory('refs').existsSync()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -114,10 +126,22 @@ async function isValidGitDirectory(directory) {
|
|||
// To decide whether a directory has a valid .git folder, we use
|
||||
// the heuristic adopted by the valid_repository_path() function defined in
|
||||
// node_modules/git-utils/deps/libgit2/src/repository.c.
|
||||
const commonDirFile = directory.getSubdirectory('commondir');
|
||||
let commonDir;
|
||||
if (await commonDirFile.exists()) {
|
||||
const commonDirPathBuff = await fs.readFile(commonDirFile.getPath());
|
||||
const commonDirPathString = commonDirPathBuff.toString().trim();
|
||||
commonDir = new Directory(directory.resolve(commonDirPathString));
|
||||
if (!(await commonDir.exists())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
commonDir = directory;
|
||||
}
|
||||
return (
|
||||
(await directory.getSubdirectory('objects').exists()) &&
|
||||
(await directory.getFile('HEAD').exists()) &&
|
||||
directory.getSubdirectory('refs').exists()
|
||||
(await commonDir.getSubdirectory('objects').exists()) &&
|
||||
commonDir.getSubdirectory('refs').exists()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue