Skip to content

Commit

Permalink
update test and handle diff status for legacy git
Browse files Browse the repository at this point in the history
  • Loading branch information
gatzjames committed Mar 7, 2025
1 parent 35f4669 commit 639ffdf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/insomnia/src/main/git-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export async function loadGitRepository({
fs: fsClient,
gitDirectory: GIT_INTERNAL_DIR,
gitCredentials: credentials,
legacyDiff: Boolean(workspaceId),
});
}

Expand Down Expand Up @@ -849,6 +850,7 @@ export const cloneGitRepoAction = async ({
fs: routableFS,
gitDirectory: GIT_INTERNAL_DIR,
gitCredentials: gitRepository.credentials,
legacyDiff: true,
});
}

Expand Down
6 changes: 6 additions & 0 deletions packages/insomnia/src/sync/git/__tests__/git-vcs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Git-VCS', () => {
repoId: '',
directory: GIT_CLONE_DIR,
fs: fsClient,
legacyDiff: true,
});
await GitVCS.setAuthor('Karen Brown', '[email protected]');

Expand Down Expand Up @@ -109,6 +110,7 @@ describe('Git-VCS', () => {
repoId: '',
directory: GIT_CLONE_DIR,
fs: fsClient,
legacyDiff: true,
});
await GitVCS.setAuthor('Karen Brown', '[email protected]');
expect(await GitVCS.log()).toEqual([]);
Expand All @@ -126,6 +128,7 @@ describe('Git-VCS', () => {
repoId: '',
directory: GIT_CLONE_DIR,
fs: fsClient,
legacyDiff: true,
});

await GitVCS.setAuthor('Karen Brown', '[email protected]');
Expand Down Expand Up @@ -212,6 +215,7 @@ First commit!
repoId: '',
directory: GIT_CLONE_DIR,
fs: fsClient,
legacyDiff: true,
});
await GitVCS.setAuthor('Karen Brown', '[email protected]');
const status = await GitVCS.status();
Expand Down Expand Up @@ -260,6 +264,7 @@ First commit!
repoId: '',
directory: GIT_CLONE_DIR,
fs: fsClient,
legacyDiff: true,
});
// Commit
await GitVCS.setAuthor('Karen Brown', '[email protected]');
Expand Down Expand Up @@ -318,6 +323,7 @@ First commit!
repoId: '',
directory: GIT_CLONE_DIR,
fs: fsClient,
legacyDiff: true,
});
// Write to all files
await Promise.all(files.map(f => fsClient.promises.writeFile(f, originalContent)));
Expand Down
12 changes: 11 additions & 1 deletion packages/insomnia/src/sync/git/git-vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ interface InitOptions {
gitCredentials?: GitCredentials | null;
uri?: string;
repoId: string;
legacyDiff?: boolean;
}

interface InitFromCloneOptions {
Expand Down Expand Up @@ -118,13 +119,14 @@ interface BaseOpts {
onAuth: git.AuthCallback;
uri: string;
repoId: string;
legacyDiff?: boolean;
}

export class GitVCS {
// @ts-expect-error -- TSCONVERSION not initialized with required properties
_baseOpts: BaseOpts = gitCallbacks();

async init({ directory, fs, gitDirectory, gitCredentials, uri = '', repoId }: InitOptions) {
async init({ directory, fs, gitDirectory, gitCredentials, uri = '', repoId, legacyDiff = false }: InitOptions) {
this._baseOpts = {
...this._baseOpts,
dir: directory,
Expand All @@ -134,6 +136,7 @@ export class GitVCS {
http: httpClient,
uri,
repoId,
legacyDiff,
};

if (await this.repoExists()) {
Expand Down Expand Up @@ -418,6 +421,13 @@ export class GitVCS {
git.STAGE(),
],
map: async function map(filepath, [head, workdir, stage]) {
if (baseOpts.legacyDiff) {
const isInsomniaFile = filepath.startsWith(GIT_INSOMNIA_DIR_NAME) || filepath.startsWith('insomnia.') || filepath === '.';
if (!isInsomniaFile) {
return null;
}
}

if (await git.isIgnored({
...baseOpts,
filepath,
Expand Down

0 comments on commit 639ffdf

Please sign in to comment.