Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(create-turbo): add before commiting #5914

Merged
merged 1 commit into from
Sep 11, 2023
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
5 changes: 4 additions & 1 deletion packages/create-turbo/src/commands/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
DownloadError,
logger,
} from "@turbo/utils";
import { tryGitCommit, tryGitInit } from "../../utils/git";
import { tryGitCommit, tryGitInit, tryGitAdd } from "../../utils/git";
import { isOnline } from "../../utils/isOnline";
import { transforms } from "../../transforms";
import { TransformError } from "../../transforms/errors";
Expand Down Expand Up @@ -137,7 +137,10 @@ export async function create(
},
opts,
});

if (transformResult.result === "success") {
// add first to ensure any transforms that add new files are included
tryGitAdd();
tryGitCommit(
`feat(create-turbo): apply ${transformResult.name} transform`
);
Expand Down
12 changes: 12 additions & 0 deletions packages/create-turbo/src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ export function tryGitCommit(message: string): boolean {
}
}

export function tryGitAdd(): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export function tryGitAdd(): void {
export function tryGitAddAll(): void {

try {
gitAddAll();
} catch (err) {
// do nothing
}
}

function gitAddAll() {
execSync("git add -A", { stdio: "ignore" });
}

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

Choose a reason for hiding this comment

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

-a here is add all? Is this actually necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

As you pointed out below, this needs to handle the case where a file has been added (not just modified / deleted) as well.

Expand Down