mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Stop automatically appending .git to git repository URLs (#3054)
This commit is contained in:
parent
4edff40319
commit
09e910df57
@ -443,6 +443,50 @@ describe('_repairDatabase()', () => {
|
||||
expect((await models.apiSpec.getByParentId(w2._id)).fileName).toBe('Workspace 2'); // Should fix
|
||||
expect((await models.apiSpec.getByParentId(w3._id)).fileName).toBe('Unique name'); // should not fix
|
||||
});
|
||||
|
||||
it('fixes old git uris', async () => {
|
||||
const oldRepoWithSuffix = await models.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar.git',
|
||||
uriNeedsMigration: true,
|
||||
});
|
||||
const oldRepoWithoutSuffix = await models.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar',
|
||||
uriNeedsMigration: true,
|
||||
});
|
||||
const newRepoWithSuffix = await models.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar.git',
|
||||
});
|
||||
const newRepoWithoutSuffix = await models.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar',
|
||||
});
|
||||
|
||||
await db._repairDatabase();
|
||||
|
||||
expect(await db.get(models.gitRepository.type, oldRepoWithSuffix._id)).toEqual(
|
||||
expect.objectContaining({
|
||||
uri: 'https://github.com/foo/bar.git',
|
||||
uriNeedsMigration: false,
|
||||
}),
|
||||
);
|
||||
expect(await db.get(models.gitRepository.type, oldRepoWithoutSuffix._id)).toEqual(
|
||||
expect.objectContaining({
|
||||
uri: 'https://github.com/foo/bar.git',
|
||||
uriNeedsMigration: false,
|
||||
}),
|
||||
);
|
||||
expect(await db.get(models.gitRepository.type, newRepoWithSuffix._id)).toEqual(
|
||||
expect.objectContaining({
|
||||
uri: 'https://github.com/foo/bar.git',
|
||||
uriNeedsMigration: false,
|
||||
}),
|
||||
);
|
||||
expect(await db.get(models.gitRepository.type, newRepoWithoutSuffix._id)).toEqual(
|
||||
expect.objectContaining({
|
||||
uri: 'https://github.com/foo/bar',
|
||||
uriNeedsMigration: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('duplicate()', () => {
|
||||
|
@ -696,6 +696,10 @@ export async function _repairDatabase() {
|
||||
await _fixMultipleCookieJars(workspace);
|
||||
await _applyApiSpecName(workspace);
|
||||
}
|
||||
|
||||
for (const gitRepository of await find(models.gitRepository.type)) {
|
||||
await _fixOldGitURIs(gitRepository);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -789,3 +793,20 @@ async function _fixMultipleCookieJars(workspace) {
|
||||
|
||||
console.log(`[fix] Merged ${cookieJars.length} cookie jars under ${workspace.name}`);
|
||||
}
|
||||
|
||||
// Append .git to old git URIs to mimic previous isomorphic-git behaviour
|
||||
async function _fixOldGitURIs(doc: GitRepository) {
|
||||
if (!doc.uriNeedsMigration) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!doc.uri.endsWith('.git')) {
|
||||
doc.uri += '.git';
|
||||
}
|
||||
|
||||
doc.uriNeedsMigration = false;
|
||||
|
||||
await update(doc);
|
||||
|
||||
console.log(`[fix] Fixed git URI for ${doc._id}`);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ type BaseGitRepository = {
|
||||
name: string,
|
||||
email: string,
|
||||
},
|
||||
uriNeedsMigration: boolean,
|
||||
};
|
||||
|
||||
export type GitRepository = BaseModel & BaseGitRepository;
|
||||
@ -31,15 +32,19 @@ export function init(): BaseGitRepository {
|
||||
name: '',
|
||||
email: '',
|
||||
},
|
||||
uriNeedsMigration: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function migrate<T>(doc: T): T {
|
||||
export function migrate(doc: GitRepository): GitRepository {
|
||||
return doc;
|
||||
}
|
||||
|
||||
export function create(patch: $Shape<GitRepository> = {}): Promise<GitRepository> {
|
||||
return db.docCreate(type, patch);
|
||||
return db.docCreate(type, {
|
||||
uriNeedsMigration: false,
|
||||
...patch,
|
||||
});
|
||||
}
|
||||
|
||||
export function update(repo: GitRepository, patch: $Shape<GitRepository>): Promise<GitRepository> {
|
||||
|
@ -56,7 +56,7 @@ export const GIT_INSOMNIA_DIR = path.join(GIT_CLONE_DIR, GIT_INSOMNIA_DIR_NAME);
|
||||
|
||||
export default class GitVCS {
|
||||
_git: Object;
|
||||
_baseOpts: { dir: string, gitdir?: string };
|
||||
_baseOpts: { dir: string, gitdir?: string, noGitSuffix: boolean };
|
||||
_initialized: boolean;
|
||||
|
||||
constructor() {
|
||||
@ -74,7 +74,11 @@ export default class GitVCS {
|
||||
console.log(`[git-event] ${message}`);
|
||||
});
|
||||
|
||||
this._baseOpts = { dir: directory, gitdir: gitDirectory };
|
||||
this._baseOpts = {
|
||||
dir: directory,
|
||||
gitdir: gitDirectory,
|
||||
noGitSuffix: true,
|
||||
};
|
||||
|
||||
if (await this._repoExists()) {
|
||||
console.log(`[git] Opened repo for ${gitDirectory}`);
|
||||
@ -96,7 +100,11 @@ export default class GitVCS {
|
||||
this._git = git;
|
||||
git.plugins.set('fs', fsPlugin);
|
||||
|
||||
this._baseOpts = { dir: directory, gitdir: gitDirectory };
|
||||
this._baseOpts = {
|
||||
dir: directory,
|
||||
gitdir: gitDirectory,
|
||||
noGitSuffix: true,
|
||||
};
|
||||
|
||||
await git.clone({ ...this._baseOpts, ...creds, url, singleBranch: true });
|
||||
|
||||
|
@ -138,6 +138,7 @@ class WrapperHome extends React.PureComponent<Props, State> {
|
||||
url,
|
||||
...credentials,
|
||||
depth: 1,
|
||||
noGitSuffix: true,
|
||||
});
|
||||
} catch (err) {
|
||||
showError({ title: 'Error Cloning Repository', message: err.message, error: err });
|
||||
|
Loading…
Reference in New Issue
Block a user