Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/betterer/src/fs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ export class BettererGitΩ implements BettererVersionControl {
}

private async _init(git: SimpleGit): Promise<void> {
if (await git.checkIsRepo()) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is self explanatory here, would you mind removing the comments?

return;
}

const retries = 3;
for (let i = 0; i < retries; i++) {
try {
await git.init();
return;
} catch (error) {
if (i >= retries) {
if (i === retries - 1) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, oops šŸ˜…

throw error;
}
}
Expand Down
51 changes: 51 additions & 0 deletions test/worktree.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// eslint-disable-next-line require-extensions/require-extensions -- tests not ESM ready yet
import { createFixture } from './fixture';

import { simpleGit } from 'simple-git';

describe('betterer', () => {
it('should not reinitialise the repository when run inside a git worktree', async () => {
const { betterer } = await import('@betterer/betterer');

const { resolve, cleanup } = await createFixture('worktree', {
'source/.betterer.js': `
const { regexp } = require('@betterer/regexp');

module.exports = {
test: () => regexp(/(\\/\\/\\s*HACK)/i).include('./src/**/*.ts')
};
`,
'source/src/index.ts': `// HACK:`
});

const sourcePath = resolve('source');
const barePath = resolve('repo.git');
const worktreePath = resolve('worktree');

const source = simpleGit(sourcePath);
await source.init();
await source.addConfig('user.email', 'test@betterer.dev');
await source.addConfig('user.name', 'Betterer Test');
await source.add('.');
await source.commit('init');
const branch = (await source.revparse(['--abbrev-ref', 'HEAD'])).trim();

await simpleGit(resolve('.')).clone(sourcePath, barePath, ['--bare']);

const bare = simpleGit(barePath);
await bare.raw('worktree', 'add', worktreePath, branch);

expect((await bare.raw('config', '--get', 'core.bare')).trim()).toBe('true');

await betterer({
cwd: worktreePath,
configPaths: [resolve('worktree/.betterer.js')],
resultsPath: resolve('worktree/.betterer.results'),
workers: false
});

expect((await bare.raw('config', '--get', 'core.bare')).trim()).toBe('true');

await cleanup();
});
});