clear executable bit when updating files if necessary
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/lib/worktree.c b/lib/worktree.c
index 98fe111..2761439 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -768,13 +768,21 @@ install_blob(struct got_worktree *worktree, struct got_fileindex *fileindex,
err = got_error_from_errno();
goto done;
}
+ } else {
+ /* In case of an update stat buf has been loaded above. */
+ if (lstat(ondisk_path, &sb) == -1) {
+ err = got_error_from_errno();
+ goto done;
+ }
}
- if (mode & S_IRWXU) {
- if (!update && lstat(ondisk_path, &sb) == -1) {
+
+ if (mode & S_IXUSR) {
+ if (chmod(ondisk_path, sb.st_mode | S_IXUSR) == -1) {
err = got_error_from_errno();
goto done;
}
- if (chmod(ondisk_path, sb.st_mode | S_IRWXU) == -1) {
+ } else {
+ if (chmod(ondisk_path, sb.st_mode & ~S_IXUSR) == -1) {
err = got_error_from_errno();
goto done;
}
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index bc2db08..8e67c9a 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -729,6 +729,64 @@ function test_update_keeps_xbit {
test_done "$testroot" "$ret"
}
+function test_update_clears_xbit {
+ local testroot=`test_init update_clears_xbit 1`
+
+ touch $testroot/repo/xfile
+ chmod +x $testroot/repo/xfile
+ (cd $testroot/repo && git add .)
+ git_commit $testroot/repo -m "adding executable file"
+
+ got checkout $testroot/repo $testroot/wt > $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ ls -l $testroot/wt/xfile | grep -q '^-rwx'
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "file is not executable" >&2
+ ls -l $testroot/wt/xfile >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ # XXX git seems to require a file edit when flipping the x bit?
+ echo foo > $testroot/repo/xfile
+ chmod -x $testroot/repo/xfile
+ git_commit $testroot/repo -m "not an executable file anymore"
+
+ echo "U xfile" > $testroot/stdout.expected
+ echo -n "Updated to commit " >> $testroot/stdout.expected
+ git_show_head $testroot/repo >> $testroot/stdout.expected
+ echo >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got update > $testroot/stdout)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ ls -l $testroot/wt/xfile | grep -q '^-rw-'
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "file is unexpectedly executable" >&2
+ ls -l $testroot/wt/xfile >&2
+ fi
+ test_done "$testroot" "$ret"
+}
+
run_test test_update_basic
run_test test_update_adds_file
run_test test_update_deletes_file
@@ -744,3 +802,4 @@ run_test test_update_creates_missing_parent_with_subdir
run_test test_update_file_in_subsubdir
run_test test_update_merges_file_edits
run_test test_update_keeps_xbit
+run_test test_update_clears_xbit