commit - 52c8d4acdcfac29443b47a3625f2b38b11cce604
commit + f032f1f7ee503b7aa2577cf836c485f96620e772
blob - cbf9d0673835a5bbdf1e42566551338b16037fde
blob + bd4cd933c9ccebfb9a50286f6bde4d29779e8e59
--- include/got_error.h
+++ include/got_error.h
#define GOT_ERR_STAGE_CONFLICT 103
#define GOT_ERR_STAGE_OUT_OF_DATE 104
#define GOT_ERR_FILE_NOT_STAGED 105
+#define GOT_ERR_STAGED_PATHS 106
static const struct got_error {
int code;
{ GOT_ERR_STAGE_OUT_OF_DATE, "work tree must be updated before "
"changes can be staged" },
{ GOT_ERR_FILE_NOT_STAGED, "file is not staged" },
+ { GOT_ERR_STAGED_PATHS, "work tree contains files with staged "
+ "changes; these changes must be committed or unstaged first" },
};
/*
blob - b1367b449134be08b066f2617522e11293a0a05d
blob + 86889ab60a4f04afc08edff1551b7ab9c3f46e57
--- lib/worktree.c
+++ lib/worktree.c
char *tmp_branch_name = NULL, *branch_ref_name = NULL;
struct got_reference *commit_ref = NULL, *branch_ref = NULL;
char *fileindex_path = NULL;
+ int have_staged_files = 0;
*commit_id = NULL;
*new_base_branch = NULL;
err = open_fileindex(fileindex, &fileindex_path, worktree);
if (err)
+ goto done;
+
+ err = got_fileindex_for_each_entry_safe(*fileindex, check_staged_file,
+ &have_staged_files);
+ if (err && err->code != GOT_ERR_CANCELLED)
+ goto done;
+ if (have_staged_files) {
+ err = got_error(GOT_ERR_STAGED_PATHS);
goto done;
+ }
err = get_rebase_tmp_ref_name(&tmp_branch_name, worktree);
if (err)
- return err;
+ goto done;
err = get_rebase_branch_symref_name(&branch_ref_name, worktree);
if (err)
struct got_reference *commit_ref = NULL;
struct got_reference *base_commit_ref = NULL;
char *fileindex_path = NULL;
+ int have_staged_files = 0;
*commit_id = NULL;
*tmp_branch = NULL;
err = open_fileindex(fileindex, &fileindex_path, worktree);
if (err)
+ goto done;
+
+ err = got_fileindex_for_each_entry_safe(*fileindex, check_staged_file,
+ &have_staged_files);
+ if (err && err->code != GOT_ERR_CANCELLED)
+ goto done;
+ if (have_staged_files) {
+ err = got_error(GOT_ERR_STAGED_PATHS);
goto done;
+ }
err = get_histedit_tmp_ref_name(&tmp_branch_name, worktree);
if (err)
- return err;
+ goto done;
err = get_histedit_branch_symref_name(&branch_ref_name, worktree);
if (err)
blob - a859ac4534eef54f7e371c66660a85d84e6dca9c
blob + 5aa888aaf5941ced7ac6eb946be7800afa259b49
--- regress/cmdline/histedit.sh
+++ regress/cmdline/histedit.sh
echo "edited modified alpha on master" > $testroot/wt/alpha
+ # test interaction of 'got stage' and histedit -c
+ (cd $testroot/wt && got stage alpha > /dev/null)
+ (cd $testroot/wt && got histedit -c > $testroot/stdout \
+ 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "histedit succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+ echo -n "got: work tree contains files with staged changes; " \
+ > $testroot/stderr.expected
+ echo "these changes must be committed or unstaged first" \
+ >> $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got unstage alpha > /dev/null)
(cd $testroot/wt && got histedit -c > $testroot/stdout)
local new_commit1=`git_show_parent_commit $testroot/repo`
blob - 3ffba83356a76ba9d0770740495992ede2469262
blob + fb98c2fdf7c7eac7d921af01e7972e5612504657
--- regress/cmdline/rebase.sh
+++ regress/cmdline/rebase.sh
# resolve the conflict
echo "modified alpha on branch and master" > $testroot/wt/alpha
+ # test interaction of 'got stage' and rebase -c
+ (cd $testroot/wt && got stage alpha > /dev/null)
+ (cd $testroot/wt && got rebase -c > $testroot/stdout \
+ 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "rebase succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+ echo -n "got: work tree contains files with staged changes; " \
+ > $testroot/stderr.expected
+ echo "these changes must be committed or unstaged first" \
+ >> $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got unstage alpha > /dev/null)
(cd $testroot/wt && got rebase -c > $testroot/stdout)
(cd $testroot/repo && git checkout -q newbranch)