Commit Diff


commit - e06046c217e4dfa1f080c81fc9b30dd6706e1568
commit + 68ed9ba51a07849681a433ff303ae75cf68aa92d
blob - f2810cc167a8c04c76352024a0c2c3c679fdd103
blob + 755f467c2aa1a389cc6240409b367803b91565a5
--- got/got.c
+++ got/got.c
@@ -314,8 +314,8 @@ cmd_checkout(int argc, char *argv[])
 	argv += optind;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
-	    NULL) == -1)
+	if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
+	    "unveil", NULL) == -1)
 		err(1, "pledge");
 #endif
 	if (argc == 1) {
@@ -470,8 +470,8 @@ cmd_update(int argc, char *argv[])
 	argv += optind;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
-	    NULL) == -1)
+	if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
+	    "unveil", NULL) == -1)
 		err(1, "pledge");
 #endif
 	if (argc == 0) {
blob - e5d3988711eff141c95ff4ba833c68f65a8029c5
blob + 98fe111f5c88fb1354a069a1f503595f47a986af
--- lib/worktree.c
+++ lib/worktree.c
@@ -605,7 +605,7 @@ done:
 static const struct got_error *
 merge_blob(struct got_worktree *worktree, struct got_fileindex *fileindex,
    struct got_fileindex_entry *ie, const char *ondisk_path, const char *path,
-   struct got_blob_object *blob1, struct got_repository *repo,
+   uint16_t mode, struct got_blob_object *blob1, struct got_repository *repo,
    got_worktree_checkout_cb progress_cb, void *progress_arg)
 {
 	const struct got_error *err = NULL;
@@ -693,7 +693,7 @@ done:
 static const struct got_error *
 install_blob(struct got_worktree *worktree, struct got_fileindex *fileindex,
    struct got_fileindex_entry *entry, const char *ondisk_path, const char *path,
-   struct got_blob_object *blob,
+   uint16_t mode, struct got_blob_object *blob,
    struct got_repository *repo, got_worktree_checkout_cb progress_cb,
    void *progress_arg)
 {
@@ -702,6 +702,7 @@ install_blob(struct got_worktree *worktree, struct got
 	size_t len, hdrlen;
 	int update = 0;
 	char *tmppath = NULL;
+	struct stat sb;
 
 	fd = open(ondisk_path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW,
 	    GOT_DEFAULT_FILE_MODE);
@@ -719,7 +720,6 @@ install_blob(struct got_worktree *worktree, struct got
 			if (fd == -1)
 				return got_error_from_errno();
 		} else if (errno == EEXIST) {
-			struct stat sb;
 			if (lstat(ondisk_path, &sb) == -1) {
 				err = got_error_from_errno();
 				goto done;
@@ -765,9 +765,19 @@ install_blob(struct got_worktree *worktree, struct got
 
 	if (update) {
 		if (rename(tmppath, ondisk_path) != 0) {
+			err = got_error_from_errno();
+			goto done;
+		}
+	}
+	if (mode & S_IRWXU) {
+		if (!update && lstat(ondisk_path, &sb) == -1) {
 			err = got_error_from_errno();
 			goto done;
 		}
+		if (chmod(ondisk_path, sb.st_mode | S_IRWXU) == -1) {
+			err = got_error_from_errno();
+			goto done;
+		}
 	}
 
 	if (entry == NULL)
@@ -907,10 +917,10 @@ update_blob(struct got_worktree *worktree,
 
 	if (status == GOT_STATUS_MODIFY)
 		err = merge_blob(worktree, fileindex, ie, ondisk_path, path,
-		    blob, repo, progress_cb, progress_arg);
+		    te->mode, blob, repo, progress_cb, progress_arg);
 	else
 		err = install_blob(worktree, fileindex, ie, ondisk_path, path,
-		    blob, repo, progress_cb, progress_arg);
+		    te->mode, blob, repo, progress_cb, progress_arg);
 
 	got_object_blob_close(blob);
 done:
blob - 15e1d040e7b1d7cbb7108933351d7caa2c122fc0
blob + a8b9cefcc307030e04331f184e59aeca60c3a437
--- regress/cmdline/checkout.sh
+++ regress/cmdline/checkout.sh
@@ -53,4 +53,40 @@ function test_checkout_basic {
 	test_done "$testroot" "$ret"
 }
 
+function test_checkout_sets_xbit {
+	local testroot=`test_init checkout_sets_xbit 1`
+
+	touch $testroot/repo/xfile
+	chmod +x $testroot/repo/xfile
+	(cd $testroot/repo && git add .)
+	git_commit $testroot/repo -m "adding executable file"
+
+	echo "A  $testroot/wt/xfile" > $testroot/stdout.expected
+	echo "Now shut up and hack" >> $testroot/stdout.expected
+
+	got checkout $testroot/repo $testroot/wt > $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 '^-rwx'
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "file is not executable" >&2
+		ls -l $testroot/wt/xfile >&2
+	fi
+	test_done "$testroot" "$ret"
+}
+
 run_test test_checkout_basic
+run_test test_checkout_sets_xbit
blob - de6d7654c62255aae15280ee7a09d127ca06b949
blob + bc2db0821798e8c326e17ad850a2df373d7aea2f
--- regress/cmdline/update.sh
+++ regress/cmdline/update.sh
@@ -678,7 +678,54 @@ function test_update_merges_file_edits {
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		diff -u $testroot/content.expected $testroot/content
+	fi
+	test_done "$testroot" "$ret"
+}
+
+function test_update_keeps_xbit {
+	local testroot=`test_init update_keeps_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
+
+	echo foo > $testroot/repo/xfile
+	git_commit $testroot/repo -m "changed executable file"
+
+	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 '^-rwx'
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "file is not executable" >&2
+		ls -l $testroot/wt/xfile >&2
+	fi
 	test_done "$testroot" "$ret"
 }
 
@@ -696,3 +743,4 @@ run_test test_update_creates_missing_parent
 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
blob - 1c56479bdf8c8b25d1fc07e39cebc8ff1838d6c8
blob + 238c089037e6a5b76af616643dcfdc781fea6743
--- regress/worktree/worktree_test.c
+++ regress/worktree/worktree_test.c
@@ -400,8 +400,8 @@ main(int argc, char *argv[])
 	int ch;
 
 #ifndef PROFILE
-	if (pledge("stdio rpath wpath cpath flock proc exec sendfd unveil",
-	    NULL) == -1)
+	if (pledge("stdio rpath wpath cpath fattr flock proc exec sendfd "
+	    "unveil", NULL) == -1)
 		err(1, "pledge");
 #endif