diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-03-16 18:57:57 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2015-05-11 14:12:01 -0400 |
commit | 73dce1f688ca6ec8f5c56697dc57af36d15a1fe5 (patch) | |
tree | 6a8e0612efaba3e046325127bf0f77b2e07591da | |
parent | 9ebb5a3ff31a58a25714fbc98704b0fda0982cdb (diff) | |
download | libgit2-73dce1f688ca6ec8f5c56697dc57af36d15a1fe5.tar.gz |
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.
-rw-r--r-- | include/git2/checkout.h | 1 | ||||
-rw-r--r-- | src/checkout.c | 19 |
2 files changed, 15 insertions, 5 deletions
diff --git a/include/git2/checkout.h b/include/git2/checkout.h index ed39bd3cb..58f190719 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -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 */ diff --git a/src/checkout.c b/src/checkout.c index a647ce0b9..6a1d28136 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -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)); |