From: Stefan Sperling Subject: Re: commit executable bit change To: gameoftrees@openbsd.org Date: Wed, 16 Oct 2019 14:05:16 +0200 On Tue, Oct 15, 2019 at 05:06:08PM +0200, Stefan Sperling wrote: > I have accidentally committed regress/cmdline/integrate.sh without the > executable bit because of a bug in 'got revert' where the reverted > file's permissions were overwritten with those of a temporary file. > > This diff fixes that bug, makes xbit changes show up in 'got status', and > allows 'got commit' to create new commits which contain only xbit changes. > > 'got diff' will currently produce an empty diff for such commits, but that > is a separate issue. It is possible to create such commits with Git, too. > > No new regression test is added for the 'revert' bug because showing the > bogus mode change in 'status' already made test_revert_patch_one_change fail. > > Also, Got was only setting the owner's x bit, but not group/other as Git > would do. This gets fixed here as well. Here is a follow-up diff which applies on top of the previous diff. With this, chmod +x/-x changes are properly handled during 'got update'. diff 74d76bcfc3e666ec6ba12ae24ec754b6bdd7f4fc f57d86d87012b20b13d9ea2269f28a0afd072dcd 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 @@ -1556,6 +1556,93 @@ function test_update_tag { 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" +} + run_test test_update_basic run_test test_update_adds_file run_test test_update_deletes_file @@ -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