Skip to content

Add "Allow empty commit" option to commit options context menu#21771

Merged
niik merged 4 commits intodevelopmentfrom
copilot/add-allow-empty-commit-option
Mar 12, 2026
Merged

Add "Allow empty commit" option to commit options context menu#21771
niik merged 4 commits intodevelopmentfrom
copilot/add-allow-empty-commit-option

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

Adds a toggleable "Allow empty commit" option to the commit options gear menu, enabling git commit --allow-empty from within GitHub Desktop. The option is per-repository and resets to false after each commit.

Description

  • app-state.ts / repository-state-cache.ts: Added allowEmptyCommit: boolean to IRepositoryState (default false) and included it in the CommitOptions pick type.
  • git/commit.ts: Added allowEmpty?: boolean option to createCommit() → passes --allow-empty to git commit.
  • app-store.ts: Forwards allowEmpty: state.allowEmptyCommit to createCommit(); resets allowEmptyCommit to false on successful commit. _updateCommitOptions now accepts Partial<CommitOptions> and merges the partial options over current state, so callers only need to pass the option(s) they want to change.
  • dispatcher.ts: updateCommitOptions updated to accept Partial<CommitOptions>.
  • commit-message.tsx:
    • Added allowEmptyCommit prop.
    • Added optional showAllowEmptyCommitOption?: boolean prop — the "Allow empty commit" checkbox in the gear context menu is only shown when this is true.
    • canCommit() now returns true when allowEmptyCommit is set and a summary exists, even with no files staged.
    • Gear button no longer shows default-options styling when allowEmptyCommit is active.
    • "Select one or more files to commit" tooltip suppressed when allowEmptyCommit is on.
    • Each context menu action now passes only the single option it is toggling (e.g. { skipCommitHooks: !this.props.skipCommitHooks }).
  • filter-changes-list.tsx: Passes showAllowEmptyCommitOption={true} to CommitMessage — the main commit panel where the option is applicable.
  • sidebar.tsx, repository.tsx, app.tsx: allowEmptyCommit prop and Partial<CommitOptions> callback type threaded through the component chain.
  • commit-message-dialog.tsx: Added optional showAllowEmptyCommitOption?: boolean prop (defaults to false) and forwards it to CommitMessage. Since CommitMessageDialog is currently only used for squash commits, the "Allow empty commit" option is hidden by default.
  • commit-test.ts: Tests that allowEmpty: true produces an empty commit and that omitting it rejects with nothing to commit.

Screenshots

Release notes

Notes: [Added] Allow empty commits via the commit options menu


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI linked an issue Mar 10, 2026 that may be closed by this pull request
Co-authored-by: niik <634063+niik@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to allow empty commits in commit menu Add "Allow empty commit" option to commit options context menu Mar 10, 2026
Copilot finished work on behalf of niik March 10, 2026 14:15
Copy link
Member

@niik niik left a comment

Choose a reason for hiding this comment

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

When the CommitMessage component is used inside of the CommitMessageDialog it should be configurable (via props on CommitMessageDialog) whether it should be possible to toggle allowing empty commits. Since the CommitMesssageDialog is currently only used when squashing commits it should default to false. If showAllowEmptyCommitOption (or whatever you name this new prop) is false the context menu item should not be included in the context menu.

Co-authored-by: niik <634063+niik@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 11, 2026

When the CommitMessage component is used inside of the CommitMessageDialog it should be configurable (via props on CommitMessageDialog) whether it should be possible to toggle allowing empty commits. ...

Done in b8ff77c. Added an optional showAllowEmptyCommitOption prop (defaults to false) to both CommitMessage and CommitMessageDialog. The menu item is only included when showAllowEmptyCommitOption is true. In the main commit flow (filter-changes-list.tsx) it's hardcoded to true; in CommitMessageDialog it defaults to false so the squash dialog is unaffected.

Copilot finished work on behalf of niik March 11, 2026 09:20
Copy link
Member

@niik niik left a comment

Choose a reason for hiding this comment

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

One last thing. Can we make it so that the updateCommitOptions method in AppStore (and all the places it's called or forwarded to) accept a Partial such that we don't have to pass the entire CommitOptions object just to change allowEmptyCommit? Do that then update all callsities in commit-message.tsx so only pass the commit option they're changing.

…hain

Co-authored-by: niik <634063+niik@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 11, 2026

One last thing. Can we make it so that the updateCommitOptions method in AppStore (and all the places it's called or forwarded to) accept a Partial such that we don't have to pass the e...

Done in 842efdb. _updateCommitOptions in AppStore (and updateCommitOptions in the dispatcher, plus all onUpdateCommitOptions prop types along the chain) now accept Partial<CommitOptions>. The store method merges the partial options over the current state. Each of the three call sites in commit-message.tsx now only passes the single option it's toggling.

Copilot finished work on behalf of niik March 11, 2026 11:10
@niik niik marked this pull request as ready for review March 11, 2026 11:24
Copy link
Contributor

@tidy-dev tidy-dev left a comment

Choose a reason for hiding this comment

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

✨ Works like a charm!

@niik niik merged commit 47ead1c into development Mar 12, 2026
14 checks passed
@niik niik deleted the copilot/add-allow-empty-commit-option branch March 12, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow empty commits

3 participants