summaryrefslogtreecommitdiff
path: root/src/checkout.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/checkout.c')
-rw-r--r--src/checkout.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/checkout.c b/src/checkout.c
index d72f227de..2a4e5c4a5 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -2412,16 +2412,25 @@ static int checkout_data_init(
* and those should not be overwritten.)
*/
if (data->index != git_iterator_index(target)) {
- if ((error = git_index_read_safely(data->index)) < 0)
- goto cleanup;
-
- /* cannot checkout if unresolved conflicts exist */
- if ((data->opts.checkout_strategy & GIT_CHECKOUT_FORCE) == 0 &&
- git_index_has_conflicts(data->index)) {
- error = GIT_ECONFLICT;
- giterr_set(GITERR_CHECKOUT,
- "unresolved conflicts exist in the index");
- goto cleanup;
+ if (data->opts.checkout_strategy & GIT_CHECKOUT_FORCE) {
+ /* When forcing, we can blindly re-read the index */
+ if ((error = git_index_read(data->index, false)) < 0)
+ goto cleanup;
+ } else {
+ /*
+ * When not being forced, we need to check for unresolved
+ * conflicts and unsaved changes in the index before
+ * proceeding.
+ */
+ if (git_index_has_conflicts(data->index)) {
+ error = GIT_ECONFLICT;
+ giterr_set(GITERR_CHECKOUT,
+ "unresolved conflicts exist in the index");
+ goto cleanup;
+ }
+
+ if ((error = git_index_read_safely(data->index)) < 0)
+ goto cleanup;
}
/* clean conflict data in the current index */