Commit 73dce1f6 by Edward Thomson

checkout: allow baseline to be specified as index

Allow the baseline to be specified as an index, so that users
need not write their index to a tree just to checkout with that
as the baseline.
parent 9ebb5a3f
......@@ -273,6 +273,7 @@ typedef struct git_checkout_options {
git_strarray paths;
git_tree *baseline; /**< expected content of workdir, defaults to HEAD */
git_index *baseline_index; /**< expected content of workdir, expressed as an index. */
const char *target_directory; /**< alternative checkout path to workdir */
......
......@@ -2397,7 +2397,7 @@ static int checkout_data_init(
&data->can_symlink, repo, GIT_CVAR_SYMLINKS)) < 0)
goto cleanup;
if (!data->opts.baseline) {
if (!data->opts.baseline && !data->opts.baseline_index) {
data->opts_free_baseline = true;
error = checkout_lookup_head_tree(&data->opts.baseline, repo);
......@@ -2501,12 +2501,21 @@ int git_checkout_iterator(
(error = git_iterator_for_workdir_ext(
&workdir, data.repo, data.opts.target_directory, index, NULL,
iterflags | GIT_ITERATOR_DONT_AUTOEXPAND,
data.pfx, data.pfx)) < 0 ||
(error = git_iterator_for_tree(
&baseline, data.opts.baseline,
iterflags, data.pfx, data.pfx)) < 0)
data.pfx, data.pfx)) < 0)
goto cleanup;
if (data.opts.baseline_index) {
if ((error = git_iterator_for_index(
&baseline, data.opts.baseline_index,
iterflags, data.pfx, data.pfx)) < 0)
goto cleanup;
} else {
if ((error = git_iterator_for_tree(
&baseline, data.opts.baseline,
iterflags, data.pfx, data.pfx)) < 0)
goto cleanup;
}
/* Should not have case insensitivity mismatch */
assert(git_iterator_ignore_case(workdir) == git_iterator_ignore_case(baseline));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment