Skip to content

Commit fec443c

Browse files
authored
Merge pull request #43 from SKalt/implement-allow-empty
fix: allow empty commits
2 parents b39bbde + 132a38a commit fec443c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

cmd/cli.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func mainMode(cmd *cobra.Command, args []string, cfg *config.Cfg) {
9696

9797
commitParams := getGitCommitCmd(cmd)
9898
committingAllChanges, _ := cmd.Flags().GetBool("all")
99+
allowEmpty, _ := cmd.Flags().GetBool("allow-empty")
99100
if !cfg.DryRun && !committingAllChanges {
100101
buf := &bytes.Buffer{}
101102
process := exec.Command("git", "diff", "--name-only", "--cached")
@@ -104,7 +105,7 @@ func mainMode(cmd *cobra.Command, args []string, cfg *config.Cfg) {
104105
if err != nil {
105106
log.Fatalf("fatal: not a git repository (or any of the parent directories): .git; %+v", err)
106107
}
107-
if buf.String() == "" {
108+
if buf.String() == "" && !allowEmpty {
108109
log.Fatal("No files staged")
109110
}
110111
}
@@ -294,6 +295,7 @@ func init() {
294295
flags.StringArrayP("message", "m", []string{}, "pass a complete conventional commit. If valid, it'll be committed without editing.")
295296
flags.Bool("version", false, "print the version")
296297
flags.Bool("show-config", false, "print the path to the config file and the relevant config ")
298+
flags.Bool("allow-empty", false, "delegated to git-commit")
297299
// TODO: accept more of git commit's flags; see https://git-scm.com/docs/git-commit
298300
// likely: --cleanup=<mode>
299301
// more difficult, and possibly better done manually: --amend, -C <commit>

cmd/tui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
"no-post-rewrite",
3333
"no-gpg-sign",
3434
"no-verify", // https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-verify
35+
"allow-empty",
3536
}
3637
)
3738

0 commit comments

Comments
 (0)