mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-21 16:56:53 +00:00
checkout: allow workdir to contain checkout target
When checking out some file 'foo' that has been modified in the working directory, allow the checkout to proceed (do not conflict) if 'foo' is identical to the target of the checkout.
This commit is contained in:
parent
fef5344c50
commit
892abf9315
@ -150,6 +150,15 @@ static int checkout_notify(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GIT_INLINE(bool) is_workdir_base_or_new(
|
||||||
|
const git_oid *workdir_id,
|
||||||
|
const git_diff_file *baseitem,
|
||||||
|
const git_diff_file *newitem)
|
||||||
|
{
|
||||||
|
return (git_oid__cmp(&baseitem->id, workdir_id) == 0 ||
|
||||||
|
git_oid__cmp(&newitem->id, workdir_id) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
static bool checkout_is_workdir_modified(
|
static bool checkout_is_workdir_modified(
|
||||||
checkout_data *data,
|
checkout_data *data,
|
||||||
const git_diff_file *baseitem,
|
const git_diff_file *baseitem,
|
||||||
@ -193,8 +202,7 @@ static bool checkout_is_workdir_modified(
|
|||||||
if (wditem->mtime.seconds == ie->mtime.seconds &&
|
if (wditem->mtime.seconds == ie->mtime.seconds &&
|
||||||
wditem->mtime.nanoseconds == ie->mtime.nanoseconds &&
|
wditem->mtime.nanoseconds == ie->mtime.nanoseconds &&
|
||||||
wditem->file_size == ie->file_size)
|
wditem->file_size == ie->file_size)
|
||||||
return (git_oid__cmp(&baseitem->id, &ie->id) != 0 &&
|
return !is_workdir_base_or_new(&ie->id, baseitem, newitem);
|
||||||
git_oid_cmp(&newitem->id, &ie->id) != 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* depending on where base is coming from, we may or may not know
|
/* depending on where base is coming from, we may or may not know
|
||||||
@ -206,7 +214,10 @@ static bool checkout_is_workdir_modified(
|
|||||||
if (git_diff__oid_for_entry(&oid, data->diff, wditem, NULL) < 0)
|
if (git_diff__oid_for_entry(&oid, data->diff, wditem, NULL) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return (git_oid__cmp(&baseitem->id, &oid) != 0);
|
/* Allow the checkout if the workdir is not modified *or* if the checkout
|
||||||
|
* target's contents are already in the working directory.
|
||||||
|
*/
|
||||||
|
return !is_workdir_base_or_new(&oid, baseitem, newitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECKOUT_ACTION_IF(FLAG,YES,NO) \
|
#define CHECKOUT_ACTION_IF(FLAG,YES,NO) \
|
||||||
|
Loading…
Reference in New Issue
Block a user