Skip to content

Commit

Permalink
🚩 Set release builds to apply commits by default
Browse files Browse the repository at this point in the history
Default release builds now apply commits by default. A dry run flag has
been added to simulate commits.

In development, the existing functionality remains which is to disable
commits by default.
  • Loading branch information
mikelorant committed Dec 27, 2022
1 parent 479626b commit 857ecb1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ builds:
goarch:
- amd64
- arm64
tags:
- release

release:
github:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ Usage:
committed [flags]
Flags:
-a, --amend Replace the tip of the current branch by creating a new commit
-h, --help help for committed
-y, --yes Specify --yes to apply the commit
-a, --amend Replace the tip of the current branch by creating a new commit
--dry-run Simulate applying a commit
-h, --help help for committed
```

To apply a commit use `committed --yes `. Shell or Git aliases can be used to
tailor this to your preferred workflow.
To create and apply a commit run `committed ` without any arguments. Shell or
Git aliases can be used to tailor this to your preferred workflow.

To amend an existing commit use `committed --yes --amend`. There are certain
To amend an existing commit use `committed --amend`. There are certain
limitations when amending commits and it is recommended only for use with
commits created with Committed. The limitations are:

Expand Down
27 changes: 26 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ import (
"github.com/spf13/cobra"
)

var hideApplyFlag bool

func NewRootCmd() *cobra.Command {
var opts commit.Options
var dryRun bool

cmd := &cobra.Command{
Use: "committed",
Short: "Committed is a WYSIWYG Git commit editor",
RunE: func(cmd *cobra.Command, args []string) error {
opts.Apply = apply(opts.Apply, dryRun)

c, err := commit.New(opts)
switch {
case err == nil:
Expand All @@ -48,9 +53,13 @@ func NewRootCmd() *cobra.Command {
},
}

cmd.Flags().BoolVarP(&opts.Apply, "yes", "y", false, "Specify --yes to apply the commit")
cmd.Flags().BoolVarP(&dryRun, "dry-run", "", false, "Simulate applying a commit")
cmd.Flags().BoolVarP(&opts.Amend, "amend", "a", false, "Replace the tip of the current branch by creating a new commit")

if !hideApplyFlag {
cmd.Flags().BoolVarP(&opts.Apply, "yes", "y", false, "Specify --yes to apply the commit")
}

cc.Init(&cc.Config{
RootCmd: cmd,
Headings: cc.HiGreen + cc.Bold,
Expand Down Expand Up @@ -86,3 +95,19 @@ func Commit(c *commit.Commit, res ui.Result) error {

return nil
}

func apply(a bool, dr bool) bool {
if a {
return true
}

if hideApplyFlag {
a = true
}

if dr {
a = false
}

return a
}
7 changes: 7 additions & 0 deletions cmd/root_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build release

package cmd

func init() {
hideApplyFlag = true
}

0 comments on commit 857ecb1

Please sign in to comment.