# `Git.Commands.Rebase`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/commands/rebase.ex#L1)

Implements the `Git.Command` behaviour for `git rebase`.

Supports rebasing a branch onto an upstream ref, as well as aborting,
continuing, skipping, and quitting in-progress rebases.

## Unsupported options

The `--interactive` (`-i`) flag is intentionally not supported because it
requires an interactive editor session, which cannot be driven by a
non-interactive CLI wrapper.

## Autosquash

The `:autosquash` and `:no_autosquash` fields are inert during a normal
rebase. Git only honors `--autosquash` together with an interactive rebase
(`-i`), which this wrapper does not support, so setting these fields has no
effect on the produced history.

# `t`

```elixir
@type t() :: %Git.Commands.Rebase{
  abort: boolean(),
  autosquash: boolean(),
  autostash: boolean(),
  branch: String.t() | nil,
  continue_rebase: boolean(),
  empty: String.t() | nil,
  exec: String.t() | nil,
  force_rebase: boolean(),
  keep_empty: boolean(),
  no_autosquash: boolean(),
  no_autostash: boolean(),
  no_keep_empty: boolean(),
  no_stat: boolean(),
  onto: String.t() | nil,
  quiet: boolean(),
  quit: boolean(),
  rebase_merges: boolean(),
  root: boolean(),
  skip: boolean(),
  stat: boolean(),
  strategy: String.t() | nil,
  strategy_option: [String.t()],
  update_refs: boolean(),
  upstream: String.t() | nil,
  verbose: boolean()
}
```

# `args`

```elixir
@spec args(t()) :: [String.t()]
```

Returns the argument list for `git rebase`.

When `:abort`, `:continue_rebase`, `:skip`, or `:quit` is `true`, builds the
corresponding mutation command. Otherwise builds the full rebase command
with all applicable flags.

## Examples

    iex> Git.Commands.Rebase.args(%Git.Commands.Rebase{abort: true})
    ["rebase", "--abort"]

    iex> Git.Commands.Rebase.args(%Git.Commands.Rebase{continue_rebase: true})
    ["rebase", "--continue"]

    iex> Git.Commands.Rebase.args(%Git.Commands.Rebase{skip: true})
    ["rebase", "--skip"]

    iex> Git.Commands.Rebase.args(%Git.Commands.Rebase{quit: true})
    ["rebase", "--quit"]

    iex> Git.Commands.Rebase.args(%Git.Commands.Rebase{upstream: "main"})
    ["rebase", "main"]

    iex> Git.Commands.Rebase.args(%Git.Commands.Rebase{upstream: "main", branch: "feat"})
    ["rebase", "main", "feat"]

    iex> Git.Commands.Rebase.args(%Git.Commands.Rebase{onto: "main", upstream: "feature"})
    ["rebase", "--onto", "main", "feature"]

# `parse_output`

```elixir
@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, Git.RebaseResult.t()}
  | {:ok, :done}
  | {:error, {String.t(), non_neg_integer()}}
```

Parses the output of `git rebase`.

For mutation operations (abort, continue, skip) with exit code 0, returns
`{:ok, :done}`. For normal rebase operations, parses into a
`Git.RebaseResult` struct. On failure, returns
`{:error, {stdout, exit_code}}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
