"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
"Lorenz (xha)" <me@xha.li>
Subject:
require -R when staging/unstaging directories
To:
gameoftrees@openbsd.org
Date:
Sun, 14 Apr 2024 13:32:57 +0200

Download raw body.

Thread
it's kind of weird that -R is needed on almost all commands but stage
and unstage. here's a diff that makes this behavior more consistent.

thoughts?

-----------------------------------------------
commit 97f243faf8ad12e6c12b6433aa7b5c5b90fe1ea9 (main)
from: Lorenz (xha) <me@xha.li>
date: Sun Apr 14 11:32:14 2024 UTC
 
 require -R when staging/unstaging directories
 
 this makes the stage and unstage commands more consistent with the
 other commands. in addition, add some regression tests for this and
 de-duplicate the logic for detecting this in the other commands.
 
diff 6cd04c7054a96d0025d9a12fc17c8ffbc5085925 97f243faf8ad12e6c12b6433aa7b5c5b90fe1ea9
commit - 6cd04c7054a96d0025d9a12fc17c8ffbc5085925
commit + 97f243faf8ad12e6c12b6433aa7b5c5b90fe1ea9
blob - c97e00bb2566dad517be2b6512d52b15801a331d
blob + 6ea66e9302fe6f556ed9c9ddb30fe733a3be7008
--- got/got.1
+++ got/got.1
@@ -3431,7 +3431,7 @@ Alternatively, the merge may be aborted with
 .Tg sg
 .It Xo
 .Cm stage
-.Op Fl lpS
+.Op Fl lpRS
 .Op Fl F Ar response-script
 .Op Ar path ...
 .Xc
@@ -3511,6 +3511,13 @@ If a file is in modified status, individual patches de
 modified file content can be staged.
 Files in added or deleted status may only be staged or rejected in
 their entirety.
+.It Fl R
+Permit recursion into directories.
+If this option is not specified,
+.Cm got stage
+will refuse to run if a specified
+.Ar path
+is a directory.
 .It Fl S
 Allow staging of symbolic links which point outside of the path space
 that is under version control.
@@ -3553,7 +3560,7 @@ and may then be staged again if necessary.
 .Tg ug
 .It Xo
 .Cm unstage
-.Op Fl p
+.Op Fl pR
 .Op Fl F Ar response-script
 .Op Ar path ...
 .Xc
@@ -3602,6 +3609,13 @@ select or reject changes for unstaging based on
 If a file is staged in modified status, individual patches derived from the
 staged file content can be unstaged.
 Files staged in added or deleted status may only be unstaged in their entirety.
+.It Fl R
+Permit recursion into directories.
+If this option is not specified,
+.Cm got unstage
+will refuse to run if a specified
+.Ar path
+is a directory.
 .El
 .It Xo
 .Cm cat
blob - 4486b08390756e709d18c25cbfc370d75101ecc2
blob + 464a3537fbcd6679ea2187873e5b5f9978353e1a
--- got/got.c
+++ got/got.c
@@ -8021,6 +8021,42 @@ add_progress(void *arg, unsigned char status, const ch
 }
 
 static const struct got_error *
+check_paths_contains_dir(int *contains_dir, struct got_worktree *worktree,
+    struct got_pathlist_head *paths)
+{
+	const struct got_error *error = NULL;
+	struct got_pathlist_entry *pe;
+	struct stat sb;
+	char *ondisk_path;
+
+	*contains_dir = 0;
+
+	TAILQ_FOREACH(pe, paths, entry) {
+		if (asprintf(&ondisk_path, "%s/%s",
+		    got_worktree_get_root_path(worktree),
+		    pe->path) == -1) {
+			return got_error_from_errno("asprintf");
+		}
+		if (lstat(ondisk_path, &sb) == -1) {
+			if (errno == ENOENT) {
+				free(ondisk_path);
+				continue;
+			}
+			error = got_error_from_errno2("lstat",
+			    ondisk_path);
+			free(ondisk_path);
+			return error;
+		}
+		free(ondisk_path);
+		if (S_ISDIR(sb.st_mode)) {
+			*contains_dir = 1;
+			return NULL;
+		}
+	}
+	return NULL;
+}
+
+static const struct got_error *
 cmd_add(int argc, char *argv[])
 {
 	const struct got_error *error = NULL;
@@ -8028,8 +8064,7 @@ cmd_add(int argc, char *argv[])
 	struct got_worktree *worktree = NULL;
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
-	int ch, can_recurse = 0, no_ignores = 0;
+	int ch, contains_dir, can_recurse = 0, no_ignores = 0;
 	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
@@ -8092,31 +8127,14 @@ cmd_add(int argc, char *argv[])
 		goto done;
 
 	if (!can_recurse) {
-		char *ondisk_path;
-		struct stat sb;
-		TAILQ_FOREACH(pe, &paths, entry) {
-			if (asprintf(&ondisk_path, "%s/%s",
-			    got_worktree_get_root_path(worktree),
-			    pe->path) == -1) {
-				error = got_error_from_errno("asprintf");
-				goto done;
-			}
-			if (lstat(ondisk_path, &sb) == -1) {
-				if (errno == ENOENT) {
-					free(ondisk_path);
-					continue;
-				}
-				error = got_error_from_errno2("lstat",
-				    ondisk_path);
-				free(ondisk_path);
-				goto done;
-			}
-			free(ondisk_path);
-			if (S_ISDIR(sb.st_mode)) {
-				error = got_error_msg(GOT_ERR_BAD_PATH,
-				    "adding directories requires -R option");
-				goto done;
-			}
+		error = check_paths_contains_dir(&contains_dir, worktree, &paths);
+		if (error != NULL)
+			goto done;
+
+		if (contains_dir) {
+			error = got_error_msg(GOT_ERR_BAD_PATH,
+			    "adding directories requires -R option");
+			goto done;
 		}
 	}
 
@@ -8172,9 +8190,8 @@ cmd_remove(int argc, char *argv[])
 	const char *status_codes = NULL;
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
-	int ch, delete_local_mods = 0, can_recurse = 0, keep_on_disk = 0, i;
-	int ignore_missing_paths = 0;
+	int contains_dir, ch, i, delete_local_mods = 0, can_recurse = 0;
+	int ignore_missing_paths = 0, keep_on_disk = 0;
 	int *pack_fds = NULL;
 
 	TAILQ_INIT(&paths);
@@ -8257,31 +8274,14 @@ cmd_remove(int argc, char *argv[])
 		goto done;
 
 	if (!can_recurse) {
-		char *ondisk_path;
-		struct stat sb;
-		TAILQ_FOREACH(pe, &paths, entry) {
-			if (asprintf(&ondisk_path, "%s/%s",
-			    got_worktree_get_root_path(worktree),
-			    pe->path) == -1) {
-				error = got_error_from_errno("asprintf");
-				goto done;
-			}
-			if (lstat(ondisk_path, &sb) == -1) {
-				if (errno == ENOENT) {
-					free(ondisk_path);
-					continue;
-				}
-				error = got_error_from_errno2("lstat",
-				    ondisk_path);
-				free(ondisk_path);
-				goto done;
-			}
-			free(ondisk_path);
-			if (S_ISDIR(sb.st_mode)) {
-				error = got_error_msg(GOT_ERR_BAD_PATH,
-				    "removing directories requires -R option");
-				goto done;
-			}
+		error = check_paths_contains_dir(&contains_dir, worktree, &paths);
+		if (error != NULL)
+			goto done;
+
+		if (contains_dir) {
+			error = got_error_msg(GOT_ERR_BAD_PATH,
+			    "removing directories requires -R option");
+			goto done;
 		}
 	}
 
@@ -8905,8 +8905,7 @@ cmd_revert(int argc, char *argv[])
 	struct got_repository *repo = NULL;
 	char *cwd = NULL, *path = NULL;
 	struct got_pathlist_head paths;
-	struct got_pathlist_entry *pe;
-	int ch, can_recurse = 0, pflag = 0;
+	int ch, contains_dir, can_recurse = 0, pflag = 0;
 	FILE *patch_script_file = NULL;
 	const char *patch_script_path = NULL;
 	struct choose_patch_arg cpa;
@@ -8989,31 +8988,14 @@ cmd_revert(int argc, char *argv[])
 		goto done;
 
 	if (!can_recurse) {
-		char *ondisk_path;
-		struct stat sb;
-		TAILQ_FOREACH(pe, &paths, entry) {
-			if (asprintf(&ondisk_path, "%s/%s",
-			    got_worktree_get_root_path(worktree),
-			    pe->path) == -1) {
-				error = got_error_from_errno("asprintf");
-				goto done;
-			}
-			if (lstat(ondisk_path, &sb) == -1) {
-				if (errno == ENOENT) {
-					free(ondisk_path);
-					continue;
-				}
-				error = got_error_from_errno2("lstat",
-				    ondisk_path);
-				free(ondisk_path);
-				goto done;
-			}
-			free(ondisk_path);
-			if (S_ISDIR(sb.st_mode)) {
-				error = got_error_msg(GOT_ERR_BAD_PATH,
-				    "reverting directories requires -R option");
-				goto done;
-			}
+		error = check_paths_contains_dir(&contains_dir, worktree, &paths);
+		if (error != NULL)
+			goto done;
+
+		if (contains_dir) {
+			error = got_error_msg(GOT_ERR_BAD_PATH,
+			    "reverting directories requires -R option");
+			goto done;
 		}
 	}
 
@@ -13799,7 +13781,7 @@ done:
 __dead static void
 usage_stage(void)
 {
-	fprintf(stderr, "usage: %s stage [-lpS] [-F response-script] "
+	fprintf(stderr, "usage: %s stage [-lpRS] [-F response-script] "
 	    "[path ...]\n", getprogname());
 	exit(1);
 }
@@ -13839,7 +13821,8 @@ cmd_stage(int argc, char *argv[])
 	struct got_worktree *worktree = NULL;
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
-	int ch, list_stage = 0, pflag = 0, allow_bad_symlinks = 0;
+	int ch, contains_dir;
+	int can_recurse = 0, list_stage = 0, pflag = 0, allow_bad_symlinks = 0;
 	FILE *patch_script_file = NULL;
 	const char *patch_script_path = NULL;
 	struct choose_patch_arg cpa;
@@ -13853,7 +13836,7 @@ cmd_stage(int argc, char *argv[])
 		err(1, "pledge");
 #endif
 
-	while ((ch = getopt(argc, argv, "F:lpS")) != -1) {
+	while ((ch = getopt(argc, argv, "F:lpRS")) != -1) {
 		switch (ch) {
 		case 'F':
 			patch_script_path = optarg;
@@ -13864,6 +13847,9 @@ cmd_stage(int argc, char *argv[])
 		case 'p':
 			pflag = 1;
 			break;
+		case 'R':
+			can_recurse = 1;
+			break;
 		case 'S':
 			allow_bad_symlinks = 1;
 			break;
@@ -13928,6 +13914,18 @@ cmd_stage(int argc, char *argv[])
 		error = got_worktree_status(worktree, &paths, repo, 0,
 		    print_stage, NULL, check_cancelled, NULL);
 	else {
+		if (!can_recurse) {
+			error = check_paths_contains_dir(&contains_dir,
+			    worktree, &paths);
+			if (error != NULL)
+				goto done;
+
+			if (contains_dir) {
+				error = got_error_msg(GOT_ERR_BAD_PATH,
+				    "staging directories requires -R option");
+				goto done;
+			}
+		}
 		cpa.patch_script_file = patch_script_file;
 		cpa.action = "stage";
 		error = got_worktree_stage(worktree, &paths,
@@ -13960,7 +13958,7 @@ done:
 __dead static void
 usage_unstage(void)
 {
-	fprintf(stderr, "usage: %s unstage [-p] [-F response-script] "
+	fprintf(stderr, "usage: %s unstage [-pR] [-F response-script] "
 	    "[path ...]\n", getprogname());
 	exit(1);
 }
@@ -13974,7 +13972,7 @@ cmd_unstage(int argc, char *argv[])
 	struct got_worktree *worktree = NULL;
 	char *cwd = NULL;
 	struct got_pathlist_head paths;
-	int ch, pflag = 0;
+	int ch, contains_dir, can_recurse = 0, pflag = 0;
 	struct got_update_progress_arg upa;
 	FILE *patch_script_file = NULL;
 	const char *patch_script_path = NULL;
@@ -13989,11 +13987,14 @@ cmd_unstage(int argc, char *argv[])
 		err(1, "pledge");
 #endif
 
-	while ((ch = getopt(argc, argv, "F:p")) != -1) {
+	while ((ch = getopt(argc, argv, "F:Rp")) != -1) {
 		switch (ch) {
 		case 'F':
 			patch_script_path = optarg;
 			break;
+		case 'R':
+			can_recurse = 1;
+			break;
 		case 'p':
 			pflag = 1;
 			break;
@@ -14049,6 +14050,19 @@ cmd_unstage(int argc, char *argv[])
 	if (error)
 		goto done;
 
+	if (!can_recurse) {
+		error = check_paths_contains_dir(&contains_dir,
+		    worktree, &paths);
+		if (error != NULL)
+			goto done;
+
+		if (contains_dir) {
+			error = got_error_msg(GOT_ERR_BAD_PATH,
+			    "unstaging directories requires -R option");
+			goto done;
+		}
+	}
+
 	cpa.patch_script_file = patch_script_file;
 	cpa.action = "unstage";
 	memset(&upa, 0, sizeof(upa));
blob - 3c2cfbb76859df180a86e0ad56d976c5f0327eb8
blob + 3574d07a0fe6f57793fe8dbfe5997c032aa0b710
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
@@ -37,7 +37,7 @@ test_stage_basic() {
 	echo ' M alpha' > $testroot/stdout.expected
 	echo ' D beta' >> $testroot/stdout.expected
 	echo ' A foo' >> $testroot/stdout.expected
-	(cd $testroot/wt && got stage > $testroot/stdout)
+	(cd $testroot/wt && got stage -R > $testroot/stdout)
 
 	cmp -s $testroot/stdout.expected $testroot/stdout
 	ret=$?
@@ -47,6 +47,41 @@ test_stage_basic() {
 	test_done "$testroot" "$ret"
 }
 
+test_stage_directory() {
+	local testroot=`test_init stage_directory`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && echo -n > test && got add test > /dev/null)
+	(cd $testroot/wt && got stage . > $testroot/stdout 2> $testroot/stderr)
+	ret=$?
+	echo "got: staging directories requires -R option" \
+		> $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got stage -R . > $testroot/stdout)
+
+	echo 'G  test' >> $testroot/stdout.expected
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+}
+
 test_stage_no_changes() {
 	local testroot=`test_init stage_no_changes`
 
@@ -109,7 +144,7 @@ test_stage_unversioned() {
 		return 1
 	fi
 
-	(cd $testroot/wt && got stage > $testroot/stdout)
+	(cd $testroot/wt && got stage -R > $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got stage command failed unexpectedly" >&2
@@ -189,7 +224,7 @@ test_stage_list() {
 	echo ' A foo' >> $testroot/stdout.expected
 	(cd $testroot/wt && got stage alpha beta foo > /dev/null)
 
-	(cd $testroot/wt && got stage -l > $testroot/stdout)
+	(cd $testroot/wt && got stage -Rl > $testroot/stdout)
 	(cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
 		cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
 	echo " M alpha" >> $testroot/stdout.expected
@@ -1276,7 +1311,7 @@ test_stage_commit_out_of_date() {
 		return 1
 	fi
 
-	(cd $testroot/wt && got unstage > /dev/null)
+	(cd $testroot/wt && got unstage -R > /dev/null)
 	(cd $testroot/wt && got update > $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
@@ -1300,7 +1335,7 @@ test_stage_commit_out_of_date() {
 	# resolve conflict
 	echo "resolved file" > $testroot/wt/alpha
 
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 
 	(cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
 	ret=$?
@@ -1623,7 +1658,7 @@ EOF
 		return 1
 	fi
 
-	(cd $testroot/wt && got unstage >/dev/null)
+	(cd $testroot/wt && got unstage -R >/dev/null)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got stage command failed unexpectedly" >&2
@@ -2252,7 +2287,7 @@ test_stage_patch_quit() {
 	# stage first hunk and quit; and don't pass a path argument to
 	# ensure that we don't skip asking about the 'zzz' file after 'quit'
 	printf "y\nq\nn\n" > $testroot/patchscript
-	(cd $testroot/wt && got stage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got stage -R -F $testroot/patchscript -p \
 		> $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
@@ -2362,7 +2397,7 @@ test_stage_patch_incomplete_script() {
 
 	# stage first hunk and then stop responding; got should error out
 	printf "y\n" > $testroot/patchscript
-	(cd $testroot/wt && got stage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got stage -R -F $testroot/patchscript -p \
 		> $testroot/stdout 2> $testroot/stderr)
 	ret=$?
 	if [ $ret -eq 0 ]; then
@@ -2464,7 +2499,7 @@ test_stage_symlink() {
 	(cd $testroot/wt && ln -sf gamma/delta zeta.link)
 	(cd $testroot/wt && got add zeta.link > /dev/null)
 
-	(cd $testroot/wt && got stage > $testroot/stdout 2> $testroot/stderr)
+	(cd $testroot/wt && got stage -R > $testroot/stdout 2> $testroot/stderr)
 	ret=$?
 	if [ $ret -eq 0 ]; then
 		echo "got stage succeeded unexpectedly" >&2
@@ -2482,7 +2517,7 @@ test_stage_symlink() {
 		return 1
 	fi
 
-	(cd $testroot/wt && got stage -S > $testroot/stdout)
+	(cd $testroot/wt && got stage -RS > $testroot/stdout)
 
 	cat > $testroot/stdout.expected <<EOF
  M alpha.link
@@ -2778,7 +2813,7 @@ test_stage_patch_symlink() {
 	(cd $testroot/wt && got add zeta.link > /dev/null)
 
 	printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
-	(cd $testroot/wt && got stage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got stage -R -F $testroot/patchscript -p \
 		> $testroot/stdout)
 
 	cat > $testroot/stdout.expected <<EOF
blob - 5f9b7bb3b3a19f838ac5afc1984ab0cc09919ed9
blob + 6df4584400e19777a765cdf69092e4a5b0c86662
--- regress/cmdline/unstage.sh
+++ regress/cmdline/unstage.sh
@@ -36,7 +36,7 @@ test_unstage_basic() {
 	echo ' A foo' >> $testroot/stdout.expected
 	(cd $testroot/wt && got stage alpha beta foo > /dev/null)
 
-	(cd $testroot/wt && got unstage > $testroot/stdout)
+	(cd $testroot/wt && got unstage -R > $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got unstage command failed unexpectedly" >&2
@@ -67,6 +67,44 @@ test_unstage_basic() {
 	test_done "$testroot" "$ret"
 }
 
+test_unstage_directory() {
+	local testroot=`test_init unstage_directory`
+
+	got checkout $testroot/repo $testroot/wt > /dev/null
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && echo -n > test && got add test > /dev/null \
+		&& got stage test > /dev/null)
+
+	(cd $testroot/wt && got unstage . > $testroot/stdout 2> $testroot/stderr)
+	ret=$?
+	echo "got: unstaging directories requires -R option" \
+		> $testroot/stderr.expected
+	cmp -s $testroot/stderr.expected $testroot/stderr
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	(cd $testroot/wt && got unstage -R . > $testroot/stdout)
+
+	echo 'G  test' >> $testroot/stdout.expected
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+}
+
 test_unstage_unversioned() {
 	local testroot=`test_init unstage_unversioned`
 
@@ -85,7 +123,7 @@ test_unstage_unversioned() {
 	echo ' M alpha' > $testroot/stdout.expected
 	echo ' D beta' >> $testroot/stdout.expected
 	echo ' A foo' >> $testroot/stdout.expected
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 
 	touch $testroot/wt/unversioned-file
 
@@ -102,7 +140,7 @@ test_unstage_unversioned() {
 		return 1
 	fi
 
-	(cd $testroot/wt && got unstage > $testroot/stdout)
+	(cd $testroot/wt && got unstage -R > $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got unstage command failed unexpectedly" >&2
@@ -121,7 +159,7 @@ test_unstage_unversioned() {
 		return 1
 	fi
 
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 
 	# unstaging an unversioned path is a no-op
 	(cd $testroot/wt && got unstage unversioned > $testroot/stdout)
@@ -163,7 +201,7 @@ test_unstage_nonexistent() {
 	echo ' M alpha' > $testroot/stdout.expected
 	echo ' D beta' >> $testroot/stdout.expected
 	echo ' A foo' >> $testroot/stdout.expected
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 
 	# unstaging a non-existent file is a no-op
 	(cd $testroot/wt && got unstage nonexistent-file > $testroot/stdout)
@@ -205,7 +243,7 @@ test_unstage_patch() {
 	w
 	EOF
 
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got stage command failed unexpectedly" >&2
@@ -215,7 +253,7 @@ test_unstage_patch() {
 
 	# don't unstage any hunks
 	printf "n\nn\nn\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		numbers > $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
@@ -279,7 +317,7 @@ EOF
 
 	# unstage middle hunk
 	printf "n\ny\nn\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		numbers > $testroot/stdout)
 
 	cat > $testroot/stdout.expected <<EOF
@@ -404,7 +442,7 @@ EOF
 		return 1
 	fi
 
-	(cd $testroot/wt && got stage >/dev/null)
+	(cd $testroot/wt && got stage -R >/dev/null)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got stage command failed unexpectedly" >&2
@@ -424,7 +462,7 @@ EOF
 
 	# unstage last hunk
 	printf "n\nn\ny\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		numbers > $testroot/stdout)
 
 	cat > $testroot/stdout.expected <<EOF
@@ -546,7 +584,7 @@ EOF
 		return 1
 	fi
 
-	(cd $testroot/wt && got stage >/dev/null)
+	(cd $testroot/wt && got stage -R >/dev/null)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got stage command failed unexpectedly" >&2
@@ -566,7 +604,7 @@ EOF
 
 	# unstage all hunks
 	printf "y\ny\ny\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		numbers > $testroot/stdout)
 
 	cat > $testroot/stdout.expected <<EOF
@@ -690,10 +728,10 @@ test_unstage_patch_added() {
 	echo "new" > $testroot/wt/epsilon/new
 	(cd $testroot/wt && got add epsilon/new > /dev/null)
 
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 
 	printf "y\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		epsilon/new > $testroot/stdout)
 
 	echo "A  epsilon/new" > $testroot/stdout.expected
@@ -758,10 +796,10 @@ test_unstage_patch_removed() {
 	fi
 
 	(cd $testroot/wt && got rm beta > /dev/null)
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 
 	printf "y\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		beta > $testroot/stdout)
 
 	echo "D  beta" > $testroot/stdout.expected
@@ -839,12 +877,12 @@ test_unstage_patch_quit() {
 	w
 	EOF
 	(cd $testroot/wt && got rm zzz > /dev/null)
-	(cd $testroot/wt && got stage > /dev/null)
+	(cd $testroot/wt && got stage -R > /dev/null)
 
 	# unstage first hunk and quit; and don't pass a path argument to
 	# ensure that we don't skip asking about the 'zzz' file after 'quit'
 	printf "y\nq\nn\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		> $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
@@ -1003,7 +1041,7 @@ test_unstage_symlink() {
 	(cd $testroot/wt && ln -sf gamma/delta zeta.link)
 	(cd $testroot/wt && got add zeta.link > /dev/null)
 
-	(cd $testroot/wt && got stage -S > /dev/null)
+	(cd $testroot/wt && got stage -RS > /dev/null)
 
 	(cd $testroot/wt && got status > $testroot/stdout)
 	cat > $testroot/stdout.expected <<EOF
@@ -1023,7 +1061,7 @@ EOF
 		return 1
 	fi
 
-	(cd $testroot/wt && got unstage > $testroot/stdout)
+	(cd $testroot/wt && got unstage -R > $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		echo "got unstage command failed unexpectedly" >&2
@@ -1198,7 +1236,7 @@ test_unstage_patch_symlink() {
 	(cd $testroot/wt && ln -sf beta zeta3.link)
 	(cd $testroot/wt && got add zeta3.link > /dev/null)
 
-	(cd $testroot/wt && got stage -S > /dev/null)
+	(cd $testroot/wt && got stage -RS > /dev/null)
 
 	(cd $testroot/wt && got status > $testroot/stdout)
 	cat > $testroot/stdout.expected <<EOF
@@ -1222,7 +1260,7 @@ EOF
 	fi
 
 	printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
-	(cd $testroot/wt && got unstage -F $testroot/patchscript -p \
+	(cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
 		> $testroot/stdout)
 	ret=$?
 	if [ $ret -ne 0 ]; then
@@ -1440,6 +1478,7 @@ EOF
 
 test_parseargs "$@"
 run_test test_unstage_basic
+run_test test_unstage_directory
 run_test test_unstage_unversioned
 run_test test_unstage_nonexistent
 run_test test_unstage_patch