Git.Commands.UpdateIndex (git v0.6.0)

Copy Markdown View Source

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}.

Summary

Functions

Returns the argument list for git update-index.

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

Parses the output of git update-index.

Types

cacheinfo()

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

t()

@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
}

Functions

args(command)

@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(update_index)

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

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

parse_output(stdout, exit_code)

@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}}.