summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-09-16 05:44:27 +0000
committerCarlos Martín Nieto <cmn@dwim.me>2015-11-04 16:59:09 -0800
commit59ac22422b02bed4c1c782ec5bdc58c937135a9a (patch)
treecbb65c1cec3122f0d441bf94776c3180805f4caf
parent097c5bc7c50c2c7343e829072953da8faa26e97c (diff)
downloadlibgit2-59ac22422b02bed4c1c782ec5bdc58c937135a9a.tar.gz
checkout: overwrite files with differing modes
When a file exists on disk and we're checking out a file that differs in executableness, remove the old file. This allows us to recreate the new file with p_open, which will take the new mode into account and handle setting the umask properly. Remove any notion of chmod'ing existing files, since it is now handled by the aforementioned removal and was incorrect, as it did not take umask into account.
-rw-r--r--src/checkout.c15
-rw-r--r--tests/checkout/tree.c3
2 files changed, 8 insertions, 10 deletions
diff --git a/src/checkout.c b/src/checkout.c
index e7699d95f..12e308257 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -244,6 +244,12 @@ static int checkout_action_common(
if (delta->new_file.mode == GIT_FILEMODE_LINK && wd != NULL)
*action |= CHECKOUT_ACTION__REMOVE;
+ /* if the file is on disk and doesn't match our mode, force update */
+ if (wd &&
+ GIT_PERMS_IS_EXEC(wd->mode) !=
+ GIT_PERMS_IS_EXEC(delta->new_file.mode))
+ *action |= CHECKOUT_ACTION__REMOVE;
+
notify = GIT_CHECKOUT_NOTIFY_UPDATED;
}
@@ -1501,15 +1507,6 @@ static int blob_content_to_file(
if (error < 0)
return error;
- if (GIT_PERMS_IS_EXEC(mode)) {
- data->perfdata.chmod_calls++;
-
- if ((error = p_chmod(path, mode)) < 0) {
- giterr_set(GITERR_OS, "Failed to set permissions on '%s'", path);
- return error;
- }
- }
-
if (st) {
data->perfdata.stat_calls++;
diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c
index 5692e1f25..5680b86df 100644
--- a/tests/checkout/tree.c
+++ b/tests/checkout/tree.c
@@ -996,7 +996,8 @@ mode_t read_filemode(const char *path)
git_buf_joinpath(&fullpath, "testrepo", path);
cl_must_pass(p_stat(fullpath.ptr, &st));
- result = GIT_PERMS_IS_EXEC(st.st_mode) ? 0100755 : 0100644;
+ result = GIT_PERMS_IS_EXEC(st.st_mode) ?
+ GIT_FILEMODE_BLOB_EXECUTABLE : GIT_FILEMODE_BLOB;
git_buf_free(&fullpath);