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

Implements the `Git.Command` behaviour for `git update-index`.

Populates and modifies the index directly. `:cacheinfo` inserts a
`{mode, object, path}` entry without a working-tree file (pairs with
`write-tree`/`mktree` to assemble arbitrary trees), and the
`:assume_unchanged` / `:skip_worktree` bits hide local changes to tracked
files.

`:index_info` reads the bulk index-info format on stdin, so that mode needs
the default `Git.Runner.Forcola` runner; under `Git.Runner.SystemCmd` it
returns `{:error, :stdin_unsupported}`.

# `cacheinfo`

```elixir
@type cacheinfo() :: {String.t(), String.t(), String.t()}
```

# `t`

```elixir
@type t() :: %Git.Commands.UpdateIndex{
  add: boolean(),
  assume_unchanged: boolean(),
  cacheinfo: [cacheinfo()],
  chmod: String.t() | nil,
  files: [String.t()],
  index_info: boolean(),
  refresh: boolean(),
  remove: boolean(),
  skip_worktree: boolean(),
  stdin: iodata() | nil
}
```

# `args`

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

Returns the argument list for `git update-index`.

## Examples

    iex> Git.Commands.UpdateIndex.args(%Git.Commands.UpdateIndex{add: true, files: ["a.txt"]})
    ["update-index", "--add", "--", "a.txt"]

    iex> Git.Commands.UpdateIndex.args(%Git.Commands.UpdateIndex{cacheinfo: [{"100644", "abc123", "f.txt"}]})
    ["update-index", "--cacheinfo", "100644,abc123,f.txt"]

    iex> Git.Commands.UpdateIndex.args(%Git.Commands.UpdateIndex{skip_worktree: true, files: ["cfg"]})
    ["update-index", "--skip-worktree", "--", "cfg"]

    iex> Git.Commands.UpdateIndex.args(%Git.Commands.UpdateIndex{index_info: true})
    ["update-index", "--index-info"]

# `input`

```elixir
@spec input(t()) :: iodata() | nil
```

Returns the `--index-info` stdin payload when set, otherwise `nil`.

# `parse_output`

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

Parses the output of `git update-index`.

On success (exit code 0), returns `{:ok, :done}`. On failure, returns
`{:error, {stdout, exit_code}}`.

---

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