commit - 93b39c2f4a792f8a83e7621425edbd48f0c16854
commit + ebd4d9a0266bb7a7145bcd6138bf64a5b0c1d004
blob - a36755abe9a86dda460f66de1cb5275ad1ac57b9
blob + adc1a793e253541b83360e9a96a100b0dfcebe65
--- got/got.1
+++ got/got.1
.Tg sg
.It Xo
.Cm stage
-.Op Fl lpRS
+.Op Fl lpS
.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 pR
+.Op Fl p
.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 - 9b22bd01524107cae5a5dc3a2b85913cadb5bd7b
blob + 855d9d97039be14a03f12d2f1a5712cfa8d7574b
--- got/got.c
+++ got/got.c
while (path[0] == '/')
path++;
printf("%c %s\n", status, path);
- return NULL;
-}
-
-static const struct got_error *
-pathlist_contains_directory(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;
}
struct got_worktree *worktree = NULL;
char *cwd = NULL;
struct got_pathlist_head paths;
- int ch, contains_dir, can_recurse = 0, no_ignores = 0;
+ struct got_pathlist_entry *pe;
+ int ch, can_recurse = 0, no_ignores = 0;
int *pack_fds = NULL;
TAILQ_INIT(&paths);
goto done;
if (!can_recurse) {
- error = pathlist_contains_directory(&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;
+ 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;
+ }
}
}
const char *status_codes = NULL;
char *cwd = NULL;
struct got_pathlist_head paths;
- int contains_dir, ch, i, delete_local_mods = 0, can_recurse = 0;
- int ignore_missing_paths = 0, keep_on_disk = 0;
+ 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 *pack_fds = NULL;
TAILQ_INIT(&paths);
goto done;
if (!can_recurse) {
- error = pathlist_contains_directory(&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;
+ 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;
+ }
}
}
struct got_repository *repo = NULL;
char *cwd = NULL, *path = NULL;
struct got_pathlist_head paths;
- int ch, contains_dir, can_recurse = 0, pflag = 0;
+ struct got_pathlist_entry *pe;
+ int ch, 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) {
- error = pathlist_contains_directory(&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;
+ 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;
+ }
}
}
__dead static void
usage_stage(void)
{
- fprintf(stderr, "usage: %s stage [-lpRS] [-F response-script] "
+ fprintf(stderr, "usage: %s stage [-lpS] [-F response-script] "
"[path ...]\n", getprogname());
exit(1);
}
struct got_worktree *worktree = NULL;
char *cwd = NULL;
struct got_pathlist_head paths;
- int ch, contains_dir;
- int can_recurse = 0, list_stage = 0, pflag = 0, allow_bad_symlinks = 0;
+ int ch, 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:lpRS")) != -1) {
+ while ((ch = getopt(argc, argv, "F:lpS")) != -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 = pathlist_contains_directory(&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 [-pR] [-F response-script] "
+ fprintf(stderr, "usage: %s unstage [-p] [-F response-script] "
"[path ...]\n", getprogname());
exit(1);
}
struct got_worktree *worktree = NULL;
char *cwd = NULL;
struct got_pathlist_head paths;
- int ch, contains_dir, can_recurse = 0, pflag = 0;
+ int ch, 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:Rp")) != -1) {
+ while ((ch = getopt(argc, argv, "F:p")) != -1) {
switch (ch) {
case 'F':
patch_script_path = optarg;
break;
- case 'R':
- can_recurse = 1;
- break;
case 'p':
pflag = 1;
break;
if (error)
goto done;
- if (!can_recurse) {
- error = pathlist_contains_directory(&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 - 56c7c3d94ec8c638360c2980c7e28c7de32199e4
blob + 3c2cfbb76859df180a86e0ad56d976c5f0327eb8
--- 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 -R > $testroot/stdout)
-
- cmp -s $testroot/stdout.expected $testroot/stdout
- ret=$?
- if [ $ret -ne 0 ]; then
- diff -u $testroot/stdout.expected $testroot/stdout
- fi
- 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 > $testroot/stdout)
- (cd $testroot/wt && got stage -R . > $testroot/stdout)
-
- echo ' A test' >> $testroot/stdout.expected
cmp -s $testroot/stdout.expected $testroot/stdout
ret=$?
if [ $ret -ne 0 ]; then
return 1
fi
- (cd $testroot/wt && got stage -R > $testroot/stdout)
+ (cd $testroot/wt && got stage > $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 -Rl > $testroot/stdout)
+ (cd $testroot/wt && got stage -l > $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 -R > /dev/null)
+ (cd $testroot/wt && got unstage > /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 -R > /dev/null)
+ (cd $testroot/wt && got stage > /dev/null)
(cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
ret=$?
return 1
fi
- (cd $testroot/wt && got unstage -R >/dev/null)
+ (cd $testroot/wt && got unstage >/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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got stage -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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got stage -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 -R > $testroot/stdout 2> $testroot/stderr)
+ (cd $testroot/wt && got stage > $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 -RS > $testroot/stdout)
+ (cd $testroot/wt && got stage -S > $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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got stage -F $testroot/patchscript -p \
> $testroot/stdout)
cat > $testroot/stdout.expected <<EOF
test_parseargs "$@"
run_test test_stage_basic
-run_test test_stage_directory
run_test test_stage_no_changes
run_test test_stage_unversioned
run_test test_stage_nonexistent
blob - 2fca3b7bc8c926ed84027fe7ac16c1c8bc9f1e45
blob + 5f9b7bb3b3a19f838ac5afc1984ab0cc09919ed9
--- 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 -R > $testroot/stdout)
+ (cd $testroot/wt && got unstage > $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
- fi
- test_done "$testroot" "$ret"
-}
-
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 -R > /dev/null)
+ (cd $testroot/wt && got stage > /dev/null)
touch $testroot/wt/unversioned-file
return 1
fi
- (cd $testroot/wt && got unstage -R > $testroot/stdout)
+ (cd $testroot/wt && got unstage > $testroot/stdout)
ret=$?
if [ $ret -ne 0 ]; then
echo "got unstage command failed unexpectedly" >&2
return 1
fi
- (cd $testroot/wt && got stage -R > /dev/null)
+ (cd $testroot/wt && got stage > /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 -R > /dev/null)
+ (cd $testroot/wt && got stage > /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 -R > /dev/null)
+ (cd $testroot/wt && got stage > /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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
numbers > $testroot/stdout)
cat > $testroot/stdout.expected <<EOF
return 1
fi
- (cd $testroot/wt && got stage -R >/dev/null)
+ (cd $testroot/wt && got stage >/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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
numbers > $testroot/stdout)
cat > $testroot/stdout.expected <<EOF
return 1
fi
- (cd $testroot/wt && got stage -R >/dev/null)
+ (cd $testroot/wt && got stage >/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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -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 -R > /dev/null)
+ (cd $testroot/wt && got stage > /dev/null)
printf "y\n" > $testroot/patchscript
- (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -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 -R > /dev/null)
+ (cd $testroot/wt && got stage > /dev/null)
printf "y\n" > $testroot/patchscript
- (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -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 -R > /dev/null)
+ (cd $testroot/wt && got stage > /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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -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 -RS > /dev/null)
+ (cd $testroot/wt && got stage -S > /dev/null)
(cd $testroot/wt && got status > $testroot/stdout)
cat > $testroot/stdout.expected <<EOF
return 1
fi
- (cd $testroot/wt && got unstage -R > $testroot/stdout)
+ (cd $testroot/wt && got unstage > $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 -RS > /dev/null)
+ (cd $testroot/wt && got stage -S > /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 -R -F $testroot/patchscript -p \
+ (cd $testroot/wt && got unstage -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