diff --git a/README.md b/README.md index 6d36cb5..49fba46 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ After that you can call `git am -i ` 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 ` (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 ` (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 diff --git a/send.go b/send.go index f27c8c7..225e0dc 100644 --- a/send.go +++ b/send.go @@ -13,7 +13,7 @@ import ( var send = &cli.Command{ Name: "send", - UsageText: "git str send ", + UsageText: "git str send ", Description: "", Flags: []cli.Flag{ &cli.StringFlag{ @@ -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)