Commit Diff


commit - 1ebedb77e0d68bff22163a9aafc13db5f3f706df
commit + 523b8417c1fee8faa1a1732ffb036e97ae2ebb4a
blob - 62fe20f7905b2378140690fcaec185c0abae22d3
blob + edb81fa00de43c1b50eba8f7ba30d5959593e344
--- lib/worktree.c
+++ lib/worktree.c
@@ -1253,7 +1253,8 @@ update_blob(struct got_worktree *worktree,
 		goto done;
 	}
 
-	if (ie && status != GOT_STATUS_MISSING) {
+	if (ie && status != GOT_STATUS_MISSING &&
+	    (te->mode & S_IXUSR) == (sb.st_mode & S_IXUSR)) {
 		if (got_fileindex_entry_has_commit(ie) &&
 		    memcmp(ie->commit_sha1, worktree->base_commit_id->sha1,
 		    SHA1_DIGEST_LENGTH) == 0) {
blob - e6d70015b1a31739a3a1e5e9030d441b97f92102 (mode 744)
blob + 4aa56793bd1b5831b7a8e3680b244722e712a0dd (mode 755)
--- regress/cmdline/update.sh
+++ regress/cmdline/update.sh
@@ -1552,7 +1552,94 @@ function test_update_tag {
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		diff -u $testroot/content.expected $testroot/content
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_update_toggles_xbit {
+	local testroot=`test_init update_toggles_xbit 1`
+
+	touch $testroot/repo/xfile
+	chmod +x $testroot/repo/xfile
+	(cd $testroot/repo && git add .)
+	git_commit $testroot/repo -m "adding executable file"
+	local commit_id1=`git_show_head $testroot/repo`
+
+	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
+
+	chmod -x $testroot/wt/xfile
+	(cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
+	local commit_id2=`git_show_head $testroot/repo`
+
+	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 -c $commit_id1 > $testroot/stdout)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "U  xfile" > $testroot/stdout.expected
+	echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
+	cmp -s $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 '^-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
+
+	(cd $testroot/wt && got update > $testroot/stdout)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo "U  xfile" > $testroot/stdout.expected
+	echo "Updated to commit $commit_id2" >> $testroot/stdout.expected
+	cmp -s $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"
 }
 
@@ -1586,3 +1673,4 @@ run_test test_update_to_another_branch
 run_test test_update_to_commit_on_wrong_branch
 run_test test_update_bumps_base_commit_id
 run_test test_update_tag
+run_test test_update_toggles_xbit