Skip to content

Commit

Permalink
collapse the commit command into one, including author
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Hammond authored and Nathan Hammond committed May 15, 2023
1 parent e582288 commit 801712a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
11 changes: 3 additions & 8 deletions packages/create-turbo/__tests__/git.test.ts
Expand Up @@ -140,8 +140,7 @@ describe("git", () => {
const calls = [
"git init",
"git checkout -b main",
"git add -A",
'git commit -m "test commit"',
'git commit --author="Turbobot <turbobot@vercel.com>" -am "test commit"',
];
expect(mockExecSync).toHaveBeenCalledTimes(calls.length + 2);
calls.forEach((call) => {
Expand Down Expand Up @@ -195,11 +194,7 @@ describe("git", () => {
const result = tryGitInit(root, "test commit");
expect(result).toBe(false);

const calls: string[] = [
GIT_REPO_COMMAND,
HG_REPO_COMMAND,
"git init"
];
const calls: string[] = [GIT_REPO_COMMAND, HG_REPO_COMMAND, "git init"];

expect(mockExecSync).toHaveBeenCalledTimes(calls.length);
calls.forEach((call) => {
Expand Down Expand Up @@ -234,7 +229,7 @@ describe("git", () => {
const calls = [
"git init",
"git checkout -b main",
"git add -A",
'git commit --author="Turbobot <turbobot@vercel.com>" -am "test commit"',
];

expect(mockExecSync).toHaveBeenCalledTimes(calls.length + 2);
Expand Down
19 changes: 11 additions & 8 deletions packages/create-turbo/src/utils/git.ts
Expand Up @@ -60,10 +60,7 @@ export function tryGitInit(root: string, message: string): boolean {

execSync("git checkout -b main", { stdio: "ignore" });

execSync("git add -A", { stdio: "ignore" });
execSync(`git commit -m "${message}"`, {
stdio: "ignore",
});
gitCommit(message);
return true;
} catch (err) {
if (didInit) {
Expand All @@ -77,12 +74,18 @@ export function tryGitInit(root: string, message: string): boolean {

export function tryGitCommit(message: string): boolean {
try {
execSync("git add -A", { stdio: "ignore" });
execSync(`git commit -m "${message}"`, {
stdio: "ignore",
});
gitCommit(message);
return true;
} catch (err) {
return false;
}
}

function gitCommit(message: string) {
execSync(
`git commit --author="Turbobot <turbobot@vercel.com>" -am "${message}"`,
{
stdio: "ignore",
}
);
}

0 comments on commit 801712a

Please sign in to comment.