Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

worktree: handle nil CommitOptions in Commit()#1788

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
nathannewyen wants to merge1 commit intogo-git:main
base:main
Choose a base branch
Loading
fromnathannewyen:fix-commit-nil-options

Conversation

@nathannewyen
Copy link

@nathannewyennathannewyen commentedDec 5, 2025
edited
Loading

Summary

  • Fix(*Worktree).Commit() panic whenCommitOptions parameter is nil
  • Add test caseTestCommitWithNilOptions to verify the fix

Root Cause

When callingCommit() with a nilCommitOptions pointer, the function would immediately callopts.Validate() which causes a nil pointer dereference panic.

Solution

Check ifopts is nil before callingValidate(), and initialize it to an emptyCommitOptions{} struct. TheValidate() method already handles setting default values (Author from git config, Committer defaults to Author, Parents defaults to HEAD).

This follows the maintainer guidance from@pjbgf in the issue: "replacing nil to pointer to an empty struct" is fine when there's valid default options.

Test Plan

  • AddedTestCommitWithNilOptions test case
  • All existing tests pass (go test ./...)

Fixes#1051

The Commit() function now handles nil CommitOptions by using an emptyCommitOptions struct with default values, instead of panicking.Fixesgo-git#1051
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

(*Worktree).Commit will panic ifCommitOptions parameter is nil.

1 participant

@nathannewyen

[8]ページ先頭

©2009-2025 Movatter.jp