commit f032f1f7ee503b7aa2577cf836c485f96620e772 from: Stefan Sperling date: Sun Aug 04 12:10:07 2019 UTC fix and test interaction of rebase/histedit -c and 'got stage' commit - 52c8d4acdcfac29443b47a3625f2b38b11cce604 commit + f032f1f7ee503b7aa2577cf836c485f96620e772 blob - cbf9d0673835a5bbdf1e42566551338b16037fde blob + bd4cd933c9ccebfb9a50286f6bde4d29779e8e59 --- include/got_error.h +++ include/got_error.h @@ -119,6 +119,7 @@ #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; @@ -241,6 +242,8 @@ static const struct got_error { { 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 @@ -3945,6 +3945,7 @@ got_worktree_rebase_continue(struct got_object_id **co 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; @@ -3958,11 +3959,20 @@ got_worktree_rebase_continue(struct got_object_id **co 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) @@ -4793,6 +4803,7 @@ got_worktree_histedit_continue(struct got_object_id ** 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; @@ -4805,11 +4816,20 @@ got_worktree_histedit_continue(struct got_object_id ** 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 @@ -525,6 +525,29 @@ function test_histedit_edit { 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 @@ -244,6 +244,29 @@ function test_rebase_continue { # 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)