Commit Diff


commit - 2ef81b9be01fe633f5b38dc96c848305b5a895a8
commit + ba8a0d4daae0952f0b83279b0ffc8ab29bcc9c6c
blob - 98fe111f5c88fb1354a069a1f503595f47a986af
blob + 2761439155ff48f2d450858f66e6aa71aabd5014
--- lib/worktree.c
+++ lib/worktree.c
@@ -768,13 +768,21 @@ install_blob(struct got_worktree *worktree, struct got
 			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;
 		}
blob - bc2db0821798e8c326e17ad850a2df373d7aea2f
blob + 8e67c9af7bea04caf110cd7cbb8b29793de59b17
--- regress/cmdline/update.sh
+++ regress/cmdline/update.sh
@@ -728,7 +728,65 @@ function test_update_keeps_xbit {
 	fi
 	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_subdi
 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