Unverified 提交 3646afbe authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

Fix git committer identity (#2092)

<!-- CURSOR_SUMMARY --> > [!NOTE] > Ensures native Git commits correctly set both author and committer identities. > > - Add `withGitAuthor` to prepend `-c user.name=...` and `-c user.email=...` to git args using settings-derived author > - Update `gitCommit` (native path) to replace `--author` with `withGitAuthor([..."commit", "-m", message])`, preserving `--amend` handling and commit hash retrieval > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 67b33e2c2165ae9ebd84549abf8129d9bd9c6bef. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes incorrect Git committer identity when creating commits with native Git. We now set user.name and user.email via -c flags so both author and committer match app settings. - **Bug Fixes** - Added withGitAuthor to prepend -c user.name and -c user.email to git args. - Updated gitCommit to use withGitAuthor instead of --author (works with --amend). <sup>Written for commit 67b33e2c2165ae9ebd84549abf8129d9bd9c6bef. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
上级 a5e191f1
...@@ -42,6 +42,27 @@ async function execOrThrow( ...@@ -42,6 +42,27 @@ async function execOrThrow(
} }
} }
/**
* Prepends git config args for user.name and user.email to the provided args.
* Automatically fetches the git author from settings.
* Usage: await withGitAuthor(["commit", "-m", "message"])
* Returns: ["-c", "user.name=...", "-c", "user.email=...", "commit", "-m", "message"]
*
* Do NOT do "--author" because this does not set the committer identity.
*
* Doing -c user.name/email sets both the committer and author identity.
*/
export async function withGitAuthor(args: string[]): Promise<string[]> {
const author = await getGitAuthor();
return [
"-c",
`user.name=${author.name}`,
"-c",
`user.email=${author.email}`,
...args,
];
}
export async function getCurrentCommitHash({ export async function getCurrentCommitHash({
path, path,
ref = "HEAD", ref = "HEAD",
...@@ -95,19 +116,12 @@ export async function gitCommit({ ...@@ -95,19 +116,12 @@ export async function gitCommit({
}: GitCommitParams): Promise<string> { }: GitCommitParams): Promise<string> {
const settings = readSettings(); const settings = readSettings();
if (settings.enableNativeGit) { if (settings.enableNativeGit) {
// Get author info to match isomorphic-git behavior // Perform the commit using dugite with -c user.name/email config
const author = await getGitAuthor(); const commitArgs = ["commit", "-m", message];
// Perform the commit using dugite with --author flag
const args = [
"commit",
"-m",
message,
"--author",
`${author.name} <${author.email}>`,
];
if (amend) { if (amend) {
args.push("--amend"); commitArgs.push("--amend");
} }
const args = await withGitAuthor(commitArgs);
await execOrThrow(args, path, "Failed to create commit"); await execOrThrow(args, path, "Failed to create commit");
// Get the new commit hash // Get the new commit hash
const result = await exec(["rev-parse", "HEAD"], path); const result = await exec(["rev-parse", "HEAD"], path);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论