Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/friendly-birds-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

added explicit error handling for the specified issue
5 changes: 5 additions & 0 deletions .changeset/weak-cats-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

Improve error handling for git dubious ownership errors. Now provides clear explanations and exact fix commands when git operations fail due to dubious ownership on FAT32/exFAT/network drives.
41 changes: 33 additions & 8 deletions cli/src/helpers/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ export const isInsideGitRepo = async (dir: string): Promise<boolean> => {
stdout: "ignore",
});
return true;
} catch {
} catch (error) {
// Check for dubious ownership error and warn the user
const errorMessage = error instanceof Error ? error.message : String(error);
if (errorMessage.includes("dubious ownership")) {
logger.warn(
`Git detected dubious ownership in repository at '${dir}'.\n` +
`This occurs on file systems that don't record ownership (FAT32, exFAT, network drives).\n` +
`Common on external drives, USB drives, and Windows network shares.\n\n` +
`To fix this, run: ${chalk.cyan(`git config --global --add safe.directory "${dir}"`)}\n`
);
}
// Else, it will throw a git-error and we return false
return false;
}
Expand Down Expand Up @@ -125,12 +135,27 @@ export const initializeGit = async (projectDir: string) => {
"git"
)}\n`
);
} catch {
// Safeguard, should be unreachable
spinner.fail(
`${chalk.bold.red(
"Failed:"
)} could not initialize git. Update git to the latest version!\n`
);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);

// Check for dubious ownership error and provide helpful guidance
if (errorMessage.includes("dubious ownership")) {
spinner.fail(
`${chalk.bold.red("Failed:")} Git detected dubious ownership in repository.\n\n` +
`${chalk.yellow("Cause:")} The file system doesn't record ownership (FAT32, exFAT, network drive).\n` +
`${chalk.dim("This is common on external drives, USB drives, and Windows network shares.")}\n\n` +
`${chalk.bold("To fix this, run:")}\n` +
` ${chalk.cyan(`git config --global --add safe.directory "${projectDir}"`)}\n\n` +
`${chalk.dim("Or to trust all repositories:")}\n` +
` ${chalk.cyan("git config --global --add safe.directory '*'")}\n`
);
} else {
// Show the actual error message instead of generic text
spinner.fail(
`${chalk.bold.red("Failed:")} could not initialize git.\n` +
`${chalk.yellow("Error:")} ${errorMessage}\n` +
`${chalk.dim("Make sure git is updated to the latest version.")}\n`
);
}
}
};
91 changes: 0 additions & 91 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions test-dubious-ownership.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* Test script to reproduce the "dubious ownership" error bug
*
* This simulates what happens when Git throws a "dubious ownership" error
* on Windows drives (F:/, E:/) or network shares.
*/

console.log("🔍 REPRODUCING THE BUG\n");
console.log("=".repeat(60));

// Simulate the current buggy code
async function testBuggyVersion() {
console.log("\n❌ CURRENT BUGGY BEHAVIOR:");
console.log("-".repeat(60));

try {
// This simulates what happens when git throws dubious ownership error
throw new Error(`Command failed with exit code 128: git init
fatal: detected dubious ownership in repository at 'F:/test/ct3a'
'F:/test/ct3a' is on a file system that does not record ownership
To add an exception for this directory, call:

git config --global --add safe.directory F:/test/ct3a`);
} catch {
// THIS IS THE BUG - catches error but doesn't look at it!
console.log(
"❌ Failed: could not initialize git. Update git to the latest version!",
);
console.log(" ↑ USELESS MESSAGE - doesn't tell user the real problem!\n");
}
}

// Proposed fixed version
async function testFixedVersion() {
console.log("\n✅ PROPOSED FIX:");
console.log("-".repeat(60));

try {
// This simulates what happens when git throws dubious ownership error
throw new Error(`Command failed with exit code 128: git init
fatal: detected dubious ownership in repository at 'F:/test/ct3a'
'F:/test/ct3a' is on a file system that does not record ownership
To add an exception for this directory, call:

git config --global --add safe.directory F:/test/ct3a`);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);

if (errorMessage.includes("dubious ownership")) {
console.log("❌ Failed: Git detected dubious ownership in repository.\n");
console.log(
"Cause: The file system doesn't record ownership (FAT32, exFAT, network drive).",
);
console.log(
"This is common on external drives, USB drives, and Windows network shares.\n",
);
console.log("To fix this, run:");
console.log(
' git config --global --add safe.directory "F:/test/ct3a"\n',
);
console.log("Or to trust all repositories:");
console.log(" git config --global --add safe.directory '*'\n");
console.log(
" ↑ HELPFUL MESSAGE - clearly explains FAT32/exFAT ownership issue!",
);
} else {
console.log(`❌ Failed: could not initialize git.`);
console.log(`Error: ${errorMessage}`);
}
}
}

// Show where in the code this happens
console.log("\n📍 WHERE THE BUG IS IN THE CODE:");
console.log("-".repeat(60));
console.log("File: cli/src/helpers/git.ts");
console.log("\n🐛 Line 26-38 - isInsideGitRepo() function:");
console.log(`
} catch { // ❌ Ignores error silently
return false;
}
`);

console.log("\n🐛 Line 127-136 - initializeGit() function:");
console.log(`
} catch { // ❌ Catches error but doesn't examine it!
spinner.fail(
"Failed: could not initialize git. Update git to the latest version!"
);
}
`);

console.log("\n" + "=".repeat(60));
console.log("DEMONSTRATION:\n");

await testBuggyVersion();
await testFixedVersion();

console.log("=".repeat(60));
Loading