| @@ -125,6 +125,7 @@ type passOpts struct { |
| 125 | 125 | stdinOK bool // wire local stdin through when --file - asks for it |
| 126 | 126 | alwaysStdin bool // stdin is the payload, named by no flag: a bare redirect |
| 127 | 127 | editor string // open $EDITOR for a body when none given |
| 128 | inferSource bool // --source defaults to the checked-out branch inside a clone |
| 128 | 129 | } |
| 129 | 130 | |
| 130 | 131 | // pass builds a passthrough command. Flags are parsed by the server, which |
| @@ -182,6 +183,7 @@ func runPass(o passOpts, args []string) int { |
| 182 | 183 | fmt.Fprintln(os.Stderr, "gitbay:", err) |
| 183 | 184 | return protocol.ExitFailure |
| 184 | 185 | } |
| 186 | explicitRepo := len(args) > 0 && !strings.HasPrefix(args[0], "-") && strings.Contains(args[0], "/") |
| 185 | 187 | if o.needsRepo { |
| 186 | 188 | args, err = withRepo(t, args) |
| 187 | 189 | if err != nil { |
| @@ -189,6 +191,14 @@ func runPass(o passOpts, args []string) int { |
| 189 | 191 | return protocol.ExitUsage |
| 190 | 192 | } |
| 191 | 193 | } |
| 194 | // Inside a clone, the branch you are on is the one you mean (#101). |
| 195 | // Only when the repository was inferred from the clone too: naming |
| 196 | // another repository and meaning this checkout's branch is unlikely. |
| 197 | if o.inferSource && !explicitRepo && !hasFlag(args, "--source") { |
| 198 | if branch := currentBranch(); branch != "" { |
| 199 | args = append(args, "--source", branch) |
| 200 | } |
| 201 | } |
| 192 | 202 | |
| 193 | 203 | var stdin io.Reader = strings.NewReader("") |
| 194 | 204 | if o.editor != "" { |
| @@ -447,7 +457,7 @@ func milestoneCmd() *cobra.Command { |
| 447 | 457 | func mrCmd() *cobra.Command { |
| 448 | 458 | return group("mr", "merge requests", |
| 449 | 459 | pass("create", "open a merge request: --source <branch> --target <branch> --title <t>", |
| 450 | | passOpts{server: []string{"mr", "create"}, needsRepo: true, stdinOK: true, editor: "merge request"}), |
| 460 | passOpts{server: []string{"mr", "create"}, needsRepo: true, stdinOK: true, editor: "merge request", inferSource: true}), |
| 451 | 461 | pass("list", "list merge requests [--state ...] [--author u] [--milestone m|none] [--limit n] [--cursor c]", passOpts{server: []string{"mr", "list"}, needsRepo: true}), |
| 452 | 462 | pass("show", "show a merge request", passOpts{server: []string{"mr", "show"}, needsRepo: true}), |
| 453 | 463 | pass("diff", "show the diff", passOpts{server: []string{"mr", "diff"}, needsRepo: true}), |