summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-06-15 17:37:37 -0500
committerEdward Thomson <ethomson@github.com>2016-06-25 18:05:44 -0400
commitcf7206f8d32a46b348c2b48bea47583c9bd9929d (patch)
treeb814db98ff77d43fb47c55cbdbe09d7be0d32036 /src
parent45405a74fc7f6684ae83be4c16b76b84986c6113 (diff)
downloadlibgit2-ethomson/checkout_conflict_respect_index.tar.gz
checkout: dirty index should conflict on typechangeethomson/checkout_conflict_respect_index
When the target of a checkout has a typechange of an item, a modified index entry should cause a conflict even when the workdir has been reverted to the baseline.
Diffstat (limited to 'src')
-rw-r--r--src/checkout.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 0663bb612..a6d7df0a6 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -236,6 +236,7 @@ static bool is_index_modified(
const git_index_entry *wditem)
{
const git_index_entry *ie;
+ const char *lookup_path;
/* Don't bother investigate if we're checking out the current
* index, it is canonical.
@@ -243,7 +244,16 @@ static bool is_index_modified(
if (data->index == git_iterator_index(data->target))
return false;
- if ((ie = git_index_get_bypath(data->index, wditem->path, 0)) == NULL)
+ if (!S_ISDIR(baseitem->mode))
+ lookup_path = baseitem->path;
+ else if (!S_ISDIR(newitem->mode))
+ lookup_path = newitem->path;
+ else if (!S_ISDIR(wditem->mode))
+ lookup_path = wditem->path;
+ else
+ return true;
+
+ if ((ie = git_index_get_bypath(data->index, lookup_path, 0)) == NULL)
return true;
/* consider the index entry modified if it's different than both
@@ -552,7 +562,7 @@ static int checkout_action_with_wd(
} else
*action = CHECKOUT_ACTION_IF(FORCE, REMOVE, CONFLICT);
}
- else if (is_workdir_modified(data, &delta->old_file, &delta->new_file, wd))
+ else if (is_workdir_or_index_modified(data, &delta->old_file, &delta->new_file, wd))
*action = CHECKOUT_ACTION_IF(FORCE, REMOVE_AND_UPDATE, CONFLICT);
else
*action = CHECKOUT_ACTION_IF(SAFE, REMOVE_AND_UPDATE, NONE);