commit - 06dc3607479d190ff1dacaad2823903c41ff024f
commit + a6dfa7b2fc6f025f11ff57a315c99d96014550d8
blob - 4b47dee9aa9889b4af2b5f244668c1b65df4e331
blob + 59890cb8a1a778ec76fcdca844df0b233f20c342
--- got/got.1
+++ got/got.1
.Tg sg
.It Xo
.Cm stage
-.Op Fl lpS
+.Op Fl lpRS
.Op Fl F Ar response-script
.Op Ar path ...
.Xc
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.
.Tg ug
.It Xo
.Cm unstage
-.Op Fl p
+.Op Fl pR
.Op Fl F Ar response-script
.Op Ar path ...
.Xc
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 - 92a8f05c92c261ded6044f2c5d6917dfdfe2a38e
blob + 31c07cd69ecc36c386c0a308d3eb11e9739a64b5
--- got/got.c
+++ got/got.c
}
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;
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);
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;
}
}
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);
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;
}
}
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;
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;
}
}
__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);
}
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;
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;
case 'p':
pflag = 1;
break;
+ case 'R':
+ can_recurse = 1;
+ break;
case 'S':
allow_bad_symlinks = 1;
break;
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,
__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);
}
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;
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;
error = get_worktree_paths_from_argv(&paths, argc, argv, worktree);
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";
blob - 3c2cfbb76859df180a86e0ad56d976c5f0327eb8
blob + 3574d07a0fe6f57793fe8dbfe5997c032aa0b710
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
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=$?
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`
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
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
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
# 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=$?
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
# 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
# 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
(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
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
(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
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
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`
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
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
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)
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)
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
# 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
# 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
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
# 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
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
# 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
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
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
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
(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
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
(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
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
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