Skip to content

Commit

Permalink
accept patch file paths on git str send.
Browse files Browse the repository at this point in the history
fixes #1
  • Loading branch information
fiatjaf committed Jan 24, 2024
1 parent 22af21e commit 8ccccb6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ After that you can call `git am -i <patch-file>` to apply the patch.

First you need to know the `naddr1...` code that corresponds to the target upstream repository you're sending the patch to. Until someone makes an explorer of git repositories or something like that, you'll have to get that manually from the repository owner.

Then you just call `git send <commit>` (you can use `HEAD^` for the last commit and other git tricks here). You'll be asked some questions (which you can also answer with flags, see `git str send --help`) and the patch will be sent.
Then call `git send <commit>` (you can use `HEAD^` for the last commit and other git tricks here). You'll be asked some questions (which you can also answer with flags, see `git str send --help`) and the patch will be sent. You can also give a path to a patch file generated with `git format-patch` too instead.

## Contributing to this repository

Expand Down
20 changes: 13 additions & 7 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var send = &cli.Command{
Name: "send",
UsageText: "git str send <commit>",
UsageText: "git str send <commit or patch-file>",
Description: "",
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -45,15 +45,21 @@ var send = &cli.Command{
},
},
Action: func(ctx context.Context, c *cli.Command) error {
// commit
// commit or file
commit := c.Args().First()
if commit == "" {
return fmt.Errorf("no commit specified")
return fmt.Errorf("no commit or file specified")
}

patch, err := git("format-patch", "--stdout", commit)
if err != nil {
return fmt.Errorf("error getting patch: %w", err)
var patch string
if contents, err := os.ReadFile(commit); os.IsNotExist(err) {
patch, err = git("format-patch", "--stdout", commit)
if err != nil {
return fmt.Errorf("error getting patch: %w", err)
}
} else if err == nil {
patch = string(contents)
} else {
return fmt.Errorf("error reading file '%s': %w", commit, err)
}
if patch == "" {
return fmt.Errorf("the patch for '%s' is empty", commit)
Expand Down

0 comments on commit 8ccccb6

Please sign in to comment.