Skip to content

Commit

Permalink
fix: git spinner (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-ehrlich authored Oct 17, 2022
1 parent 84d275c commit 1cc6735
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-toys-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

fix git spinner
17 changes: 10 additions & 7 deletions cli/src/helpers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ const isRootGitRepo = (dir: string): boolean => {
};

/** If dir is inside a git worktree, meaning a parent directory has `.git` */
const isInsideGitRepo = (dir: string): boolean => {
const isInsideGitRepo = async (dir: string): Promise<boolean> => {
try {
const stdout = execSync("git rev-parse --is-inside-work-tree", {
// If this command succeeds, we're inside a git repo
await execa("git", ["rev-parse", "--is-inside-work-tree"], {
cwd: dir,
}).toString();
return stdout.trim() === "true";
stdout: "ignore",
});
return true;
} catch (_e) {
// Else, it will throw a git-error and we return false
return false;
}
};
Expand All @@ -53,12 +56,12 @@ export const initializeGit = async (projectDir: string) => {
const spinner = ora("Creating a new git repo...\n").start();

const isRoot = isRootGitRepo(projectDir);
const isInside = isInsideGitRepo(projectDir);
const isInside = await isInsideGitRepo(projectDir);
const dirName = path.parse(projectDir).name; // skip full path for logging

if (isInside && isRoot) {
// Dir is a root git repo
spinner.stopAndPersist();
spinner.stop();
const { overwriteGit } = await inquirer.prompt<{
overwriteGit: boolean;
}>({
Expand All @@ -77,7 +80,7 @@ export const initializeGit = async (projectDir: string) => {
fs.removeSync(path.join(projectDir, ".git"));
} else if (isInside && !isRoot) {
// Dir is inside a git worktree
spinner.stopAndPersist();
spinner.stop();
const { initializeChildGitRepo } = await inquirer.prompt<{
initializeChildGitRepo: boolean;
}>({
Expand Down

1 comment on commit 1cc6735

@vercel
Copy link

@vercel vercel bot commented on 1cc6735 Oct 17, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.