Skip to content

Commit

Permalink
fix: allow empty commits
Browse files Browse the repository at this point in the history
  • Loading branch information
SKalt committed Nov 11, 2024
1 parent b39bbde commit 132a38a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func mainMode(cmd *cobra.Command, args []string, cfg *config.Cfg) {

commitParams := getGitCommitCmd(cmd)
committingAllChanges, _ := cmd.Flags().GetBool("all")
allowEmpty, _ := cmd.Flags().GetBool("allow-empty")
if !cfg.DryRun && !committingAllChanges {
buf := &bytes.Buffer{}
process := exec.Command("git", "diff", "--name-only", "--cached")
Expand All @@ -104,7 +105,7 @@ func mainMode(cmd *cobra.Command, args []string, cfg *config.Cfg) {
if err != nil {
log.Fatalf("fatal: not a git repository (or any of the parent directories): .git; %+v", err)
}
if buf.String() == "" {
if buf.String() == "" && !allowEmpty {
log.Fatal("No files staged")
}
}
Expand Down Expand Up @@ -294,6 +295,7 @@ func init() {
flags.StringArrayP("message", "m", []string{}, "pass a complete conventional commit. If valid, it'll be committed without editing.")
flags.Bool("version", false, "print the version")
flags.Bool("show-config", false, "print the path to the config file and the relevant config ")
flags.Bool("allow-empty", false, "delegated to git-commit")
// TODO: accept more of git commit's flags; see https://git-scm.com/docs/git-commit
// likely: --cleanup=<mode>
// more difficult, and possibly better done manually: --amend, -C <commit>
Expand Down
1 change: 1 addition & 0 deletions cmd/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
"no-post-rewrite",
"no-gpg-sign",
"no-verify", // https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-verify
"allow-empty",
}
)

Expand Down

0 comments on commit 132a38a

Please sign in to comment.