Skip to content
Merged
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
13 changes: 7 additions & 6 deletions apps/desktop/src/lib/trpc/routers/projects/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "main/lib/project-icons";
import { getWorkspaceRuntimeRegistry } from "main/lib/workspace-runtime";
import { PROJECT_COLOR_VALUES } from "shared/constants/project-colors";
import type { SimpleGitProgressEvent } from "simple-git";
import simpleGit, { type SimpleGitProgressEvent } from "simple-git";
import { z } from "zod";
import { publicProcedure, router } from "../..";
import { resolveDefaultEditor } from "../external";
Expand All @@ -45,11 +45,11 @@ import {
refreshDefaultBranch,
sanitizeAuthorPrefix,
} from "../workspaces/utils/git";
import { getSimpleGitWithShellPath } from "../workspaces/utils/git-client";
import {
createSimpleGitWithShellPath,
getSimpleGitWithShellPath,
} from "../workspaces/utils/git-client";
import { execWithShellEnv } from "../workspaces/utils/shell-env";
execWithShellEnv,
getProcessEnvWithShellPath,
} from "../workspaces/utils/shell-env";
import { getDefaultProjectColor } from "./utils/colors";
import { discoverAndSaveProjectIcon } from "./utils/favicon-discovery";
import { fetchGitHubOwner, getGitHubAvatarUrl } from "./utils/github";
Expand Down Expand Up @@ -1493,7 +1493,7 @@ export const createProjectsRouter = (getWindow: () => BrowserWindow | null) => {
`Preparing clone into ${basename(clonePath)}`,
);
try {
const gitWithProgress = await createSimpleGitWithShellPath({
const gitWithProgress = simpleGit({
abort: abortController.signal,
progress: (event: SimpleGitProgressEvent) => {
emitCloneEvent({
Expand All @@ -1507,6 +1507,7 @@ export const createProjectsRouter = (getWindow: () => BrowserWindow | null) => {
});
},
});
gitWithProgress.env(await getProcessEnvWithShellPath());
emitCloneLog(
cloneId,
`Cloning ${redactGitCredentials(input.url)}`,
Expand Down
57 changes: 4 additions & 53 deletions apps/desktop/src/lib/trpc/routers/workspaces/utils/git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,15 @@ import {
type ExecFileOptionsWithStringEncoding,
execFile,
} from "node:child_process";
import {
buildSimpleGitUnsafeOptions,
type SimpleGitUnsafeOptions,
} from "@superset/shared/simple-git-unsafe";
import simpleGit, { type SimpleGit, type SimpleGitProgressEvent } from "simple-git";
import simpleGit, { type SimpleGit } from "simple-git";
import { getProcessEnvWithShellPath } from "./shell-env";

interface CreateSimpleGitWithShellPathOptions {
abort?: AbortSignal;
baseEnv?: NodeJS.ProcessEnv;
progress?: (event: SimpleGitProgressEvent) => void;
repoPath?: string;
}

function createSimpleGitWithEnv(
env: Record<string, string>,
options: Omit<CreateSimpleGitWithShellPathOptions, "baseEnv"> = {},
): SimpleGit {
const unsafe = buildSimpleGitUnsafeOptions(env);
const gitOptions: {
abort?: AbortSignal;
baseDir?: string;
progress?: (event: SimpleGitProgressEvent) => void;
unsafe?: SimpleGitUnsafeOptions;
} = {};

if (options.abort) {
gitOptions.abort = options.abort;
}
if (options.progress) {
gitOptions.progress = options.progress;
}
if (options.repoPath) {
gitOptions.baseDir = options.repoPath;
}
if (unsafe) {
gitOptions.unsafe = unsafe;
}

const git =
Object.keys(gitOptions).length > 0
? simpleGit(gitOptions as never)
: simpleGit();
git.env(env);
return git;
}

export async function createSimpleGitWithShellPath(
options: CreateSimpleGitWithShellPathOptions = {},
): Promise<SimpleGit> {
const env = await getProcessEnvWithShellPath(options.baseEnv ?? process.env);
return createSimpleGitWithEnv(env, options);
}

export async function getSimpleGitWithShellPath(
repoPath?: string,
): Promise<SimpleGit> {
return createSimpleGitWithShellPath({ repoPath });
const git = repoPath ? simpleGit(repoPath) : simpleGit();
git.env(await getProcessEnvWithShellPath());
return git;
}

export async function execGitWithShellPath(
Expand Down
16 changes: 5 additions & 11 deletions packages/host-service/src/runtime/git/git.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import simpleGit from "simple-git";

import type { GitCredentialProvider, GitFactory } from "./types";
import { createSimpleGitWithEnv } from "./simple-git";
import { getRemoteUrl } from "./utils";

export function createGitFactory(provider: GitCredentialProvider): GitFactory {
return async (repoPath: string) => {
const initialCredentials = await provider.getCredentials(null);
const git = createSimpleGitWithEnv({
baseDir: repoPath,
env: initialCredentials.env,
});
const git = simpleGit(repoPath).env(initialCredentials.env);
const remoteUrl = await getRemoteUrl(git);
const credentials = await provider.getCredentials(remoteUrl);
const env = {

return git.env({
...initialCredentials.env,
...credentials.env,
GIT_OPTIONAL_LOCKS: "0",
};

return createSimpleGitWithEnv({
baseDir: repoPath,
env,
});
};
}
48 changes: 0 additions & 48 deletions packages/host-service/src/runtime/git/simple-git.ts

This file was deleted.

14 changes: 5 additions & 9 deletions packages/host-service/src/trpc/router/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { existsSync, rmSync, statSync } from "node:fs";
import { basename, join, resolve } from "node:path";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
import simpleGit from "simple-git";
import { z } from "zod";
import { createSimpleGitWithEnv } from "../../../runtime/git/simple-git";
import { projects, workspaces } from "../../../db/schema";
import { parseGitHubRemote } from "../../../runtime/pull-requests/utils/parse-github-remote";
import { protectedProcedure, router } from "../../index";
Expand Down Expand Up @@ -162,7 +162,7 @@ async function importExistingRepo(
});
}

const git = createSimpleGitWithEnv({ baseDir: localPath });
const git = simpleGit(localPath);

let gitRoot: string;
try {
Expand All @@ -174,9 +174,7 @@ async function importExistingRepo(
});
}

const remotes = await getGitHubRemotes(
createSimpleGitWithEnv({ baseDir: gitRoot }),
);
const remotes = await getGitHubRemotes(simpleGit(gitRoot));
const matchingRemote = findMatchingRemote(remotes, expectedSlug);

if (!matchingRemote) {
Expand Down Expand Up @@ -232,7 +230,7 @@ async function cloneRepo(
}

try {
await createSimpleGitWithEnv().clone(repoCloneUrl, targetPath);
await simpleGit().clone(repoCloneUrl, targetPath);
} catch (err) {
if (existsSync(targetPath)) {
rmSync(targetPath, { recursive: true, force: true });
Expand All @@ -243,9 +241,7 @@ async function cloneRepo(
});
}

const remotes = await getGitHubRemotes(
createSimpleGitWithEnv({ baseDir: targetPath }),
);
const remotes = await getGitHubRemotes(simpleGit(targetPath));
const matchingRemote = findMatchingRemote(remotes, expectedSlug);

if (!matchingRemote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { dirname, join, resolve, sep } from "node:path";
import { getDeviceName, getHashedDeviceId } from "@superset/shared/device-info";
import { TRPCError } from "@trpc/server";
import { and, eq } from "drizzle-orm";
import simpleGit from "simple-git";
import { z } from "zod";
import { projects, workspaces } from "../../../db/schema";
import { createSimpleGitWithEnv } from "../../../runtime/git/simple-git";
import {
asLocalRef,
asRemoteRef,
Expand Down Expand Up @@ -732,10 +732,7 @@ export const workspaceCreationRouter = router({

if (!existsSync(repoPath)) {
mkdirSync(dirname(repoPath), { recursive: true });
await createSimpleGitWithEnv().clone(
cloudProject.repoCloneUrl,
repoPath,
);
await simpleGit().clone(cloudProject.repoCloneUrl, repoPath);
}

localProject = ctx.db
Expand Down Expand Up @@ -1076,10 +1073,7 @@ export const workspaceCreationRouter = router({
const repoPath = join(homeDir, ".superset", "repos", input.projectId);
if (!existsSync(repoPath)) {
mkdirSync(dirname(repoPath), { recursive: true });
await createSimpleGitWithEnv().clone(
cloudProject.repoCloneUrl,
repoPath,
);
await simpleGit().clone(cloudProject.repoCloneUrl, repoPath);
}
localProject = ctx.db
.insert(projects)
Expand Down
4 changes: 2 additions & 2 deletions packages/host-service/src/trpc/router/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { dirname, join } from "node:path";
import { getDeviceName, getHashedDeviceId } from "@superset/shared/device-info";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
import simpleGit from "simple-git";
import { z } from "zod";
import { projects, workspaces } from "../../../db/schema";
import { createSimpleGitWithEnv } from "../../../runtime/git/simple-git";
import { protectedProcedure, router } from "../../index";

export const workspaceRouter = router({
Expand Down Expand Up @@ -64,7 +64,7 @@ export const workspaceRouter = router({

if (!existsSync(repoPath)) {
mkdirSync(dirname(repoPath), { recursive: true });
await createSimpleGitWithEnv().clone(cloudProject.repoCloneUrl, repoPath);
await simpleGit().clone(cloudProject.repoCloneUrl, repoPath);
}

const inserted = ctx.db
Expand Down
4 changes: 0 additions & 4 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@
"./shell-ready-scanner": {
"types": "./src/shell-ready-scanner.ts",
"default": "./src/shell-ready-scanner.ts"
},
"./simple-git-unsafe": {
"types": "./src/simple-git-unsafe.ts",
"default": "./src/simple-git-unsafe.ts"
}
},
"scripts": {
Expand Down
Loading
Loading