Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.md

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It would be nice to also have some explanation in the readme for what this flag (and the other new one) actually does

Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,40 @@ The content should be in the following format:
"commitTitleCharLimit": 60,
"commitBodyCharLimit": 60,
"commitBodyLineLength": 40,
"readContributorsFromGit": true
"readContributorsFromGit": true,
"addAll": true
}
```

### Co-authors

If you want to add co-authors to your commits, add the following to your
config:

```json
{
"coauthors": [
{ "name": "John Doe", "email": "john.doe@email.com" },
{ "name": "Jane Doe", "email": "jane.doe@email.com" }
]
}
```

You can choose from those while constructing your commit message. If you add `readContributorsFromGit` to your config,
Meteor will read the contributors from your repository history.

### addAll

If you want to add all unstaged changes to your commit, add the following to your config:

```json
{
"addAll": true
}
```

This basically runs `git add --all :/` before committing.

### Boards

![Demo with boards](demos/demo-with-boards.gif)
Expand Down
9 changes: 9 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type LoadConfigReturn struct {
CommitBodyLineLength int
ShowIntro bool
ReadContributorsFromGit bool
AddAll bool
}

// loadConfig loads the config file from the current directory or any parent
Expand All @@ -48,6 +49,7 @@ func loadConfig(fs afero.Fs) (LoadConfigReturn, error) {
CommitBodyLineLength: defaultCommitBodyLineLength,
ShowIntro: true,
ReadContributorsFromGit: false,
AddAll: false,
}, nil
}

Expand All @@ -65,9 +67,15 @@ func loadConfig(fs afero.Fs) (LoadConfigReturn, error) {
CommitBodyLineLength: defaultCommitBodyLineLength,
ShowIntro: true,
ReadContributorsFromGit: false,
AddAll: false,
}, fmt.Errorf("error parsing config file: %w", err)
}

if c.AddAll == nil {
all := false
c.AddAll = &all
}

if c.ShowIntro == nil {
showIntro := true
c.ShowIntro = &showIntro
Expand Down Expand Up @@ -125,5 +133,6 @@ func loadConfig(fs afero.Fs) (LoadConfigReturn, error) {
CommitBodyLineLength: *c.CommitBodyLineLength,
ShowIntro: *c.ShowIntro,
ReadContributorsFromGit: *c.ReadContributorsFromGit,
AddAll: *c.AddAll,
}, nil
}
6 changes: 6 additions & 0 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ func getComitters(osArgs []string) ([]string, error) {
return result, nil
}

// buildAddAllCommitCommand builds the git commit command to stage all files
func buildAddAllCommitCommand() ([]string, string) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If we merge the other PR first, we can use the executeGitCommand function to wrap this instead

args := append([]string{"add", "--all", ":/"})
return args, fmt.Sprintf("git %v", shellescape.QuoteCommand(args))
}

// commit commits the changes to git
func commit(command []string) error {
cmd := exec.Command("git", command...)
Expand Down
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/charmbracelet/log"
"github.com/fatih/color"

"github.com/stefanlogue/meteor/internal/util"

"github.com/atotto/clipboard"
Expand Down Expand Up @@ -45,6 +46,7 @@ var (
debugMode bool
skipIntro bool
skipBreakingChange bool
addAll bool
FS afero.Fs = afero.NewOsFs()
AFS *afero.Afero = &afero.Afero{Fs: FS}
)
Expand All @@ -61,6 +63,7 @@ func init() {
flag.BoolVarP(&skipIntro, "skip-intro", "s", false, "skip intro splash")
flag.BoolVarP(&debugMode, "debug", "D", false, "enable debug mode")
flag.BoolVarP(&skipBreakingChange, "skip-breaking-change", "b", false, "skip breaking change prompt")
flag.BoolVarP(&addAll, "add-all", "a", false, "add all unstaged changes to commit")
flag.Parse()
if isFlagPassed("version") {
fmt.Printf("meteor version %s\n", version)
Expand Down Expand Up @@ -101,6 +104,10 @@ func main() {
fail(ErrorString, err)
}

if !config.AddAll && addAll {
config.AddAll = true
}

var newCommit Commit
theme := huh.ThemeCatppuccin()
if config.ShowIntro && (isFlagPassed("skip-intro") && !skipIntro) {
Expand Down Expand Up @@ -304,6 +311,20 @@ func main() {
args = args[1:]
}

if config.AddAll {
rawCommitCommand, printableCommitCommand := buildAddAllCommitCommand()
err = commit(rawCommitCommand)
if err != nil {
writeToClipboard(printableCommitCommand)
fail(
"\n%s\n%s\n\n%s\n\n",
color.RedString(fmt.Sprintf("It looks like the add all failed.\nError: %s", err)),
color.YellowString("To run it again without going through meteor's wizard, simply run the following command (I've copied it to your clipboard!):"),
color.BlueString(printableCommitCommand),
)
return
}
}
Comment on lines +314 to +327

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Have you called the wrong build function here? buildAddAllCommitCommand is never used and the usage of buildCommitCommand here is identical to the code below this block, leaving this code unnecessary as-is

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

also, osargs are probably tailored to the commit functinality and make no sense in buildAddAllCommitCommand

rawCommitCommand, printableCommitCommand := buildCommitCommand(newCommit.Message, newCommit.Body, args)

if isFlagPassed(AsGitEditor) {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

type Config struct {
AddAll *bool `json:"addAll"`
ShowIntro *bool `json:"showIntro"`
CommitTitleCharLimit *int `json:"commitTitleCharLimit"`
CommitBodyCharLimit *int `json:"commitBodyCharLimit"`
Expand Down
Loading