Skip to content
Draft
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: 12 additions & 1 deletion tools/tsp-client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,18 @@ export async function syncCommand(argv: any) {
await addSpecFiles(cloneDir, dir);
}
await checkoutCommit(cloneDir, tspLocation.commit);
await cp(joinPaths(cloneDir, tspLocation.directory), srcDir, { recursive: true });
const clonedTspProject = joinPaths(cloneDir, tspLocation.directory);
try {
// Check if the cloned TypeSpec project exists
await stat(clonedTspProject);
} catch (err) {
Logger.error(
`Unexpected error reading the TypeSpec project directory after cloning the repository: '${clonedTspProject}'. Please verify that the TypeSpec directory path is correct and that it exists at the specified commit: '${tspLocation.commit}'.\n${err}`,
);
await removeDirectory(cloneDir);
process.exit(1);
}
await cp(clonedTspProject, srcDir, { recursive: true });
for (const dir of tspLocation.additionalDirectories!) {
Logger.info(`Syncing additional directory: ${dir}`);
await cp(joinPaths(cloneDir, dir), joinPaths(tempRoot, getAdditionalDirectoryName(dir)), {
Expand Down
10 changes: 7 additions & 3 deletions tools/tsp-client/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { spawn } from "child_process";
import { simpleGit } from "simple-git";

export async function getRepoRoot(repoPath: string): Promise<string> {
return simpleGit(repoPath).revparse(["--show-toplevel"]);
return simpleGit(repoPath)
.revparse(["--show-toplevel"])
.catch((err) => {
throw new Error(`Failed to get repo root: ${err}`);
});
}

export async function cloneRepo(rootUrl: string, cloneDir: string, repo: string): Promise<void> {
return new Promise((resolve, reject) => {
simpleGit(rootUrl).clone(repo, cloneDir, ["--no-checkout", "--filter=tree:0"], (err) => {
if (err) {
reject(err);
reject(new Error(`git clone failed with error: ${err}`));
}
resolve();
});
Expand Down Expand Up @@ -58,7 +62,7 @@ export async function checkoutCommit(cloneDir: string, commit: string): Promise<
return new Promise((resolve, reject) => {
simpleGit(cloneDir).checkout(commit, undefined, (err) => {
if (err) {
reject(err);
reject(new Error(`git checkout failed with error: ${err}`));
}
resolve();
});
Expand Down