ensure that 'got update' refuses to update staged files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/lib/worktree.c b/lib/worktree.c
index c62f844..0115f06 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -1185,6 +1185,10 @@ update_blob(struct got_worktree *worktree,
return got_error_from_errno("asprintf");
if (ie) {
+ if (get_staged_status(ie) != GOT_STATUS_NO_CHANGE) {
+ err = got_error_path(ie->path, GOT_ERR_FILE_STAGED);
+ goto done;
+ }
err = get_file_status(&status, &sb, ie, ondisk_path, repo);
if (err)
goto done;
@@ -1308,6 +1312,9 @@ delete_blob(struct got_worktree *worktree, struct got_fileindex *fileindex,
struct stat sb;
char *ondisk_path;
+ if (get_staged_status(ie) != GOT_STATUS_NO_CHANGE)
+ return got_error_path(ie->path, GOT_ERR_FILE_STAGED);
+
if (asprintf(&ondisk_path, "%s/%s", worktree->root_path, ie->path)
== -1)
return got_error_from_errno("asprintf");
diff --git a/regress/cmdline/stage.sh b/regress/cmdline/stage.sh
index 87156b3..4d057d7 100755
--- a/regress/cmdline/stage.sh
+++ b/regress/cmdline/stage.sh
@@ -852,6 +852,48 @@ function test_stage_rebase {
test_done "$testroot" "$ret"
}
+function test_stage_update {
+ local testroot=`test_init stage_update`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified file" > $testroot/wt/alpha
+ (cd $testroot/wt && got stage alpha > /dev/null)
+
+ echo "modified alpha" > $testroot/repo/alpha
+ git_commit $testroot/repo -m "modified alpha"
+
+ (cd $testroot/wt && got update > $testroot/stdout \
+ 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got update command succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo -n > $testroot/stdout.expected
+ echo "got: alpha: file is staged" > $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
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
run_test test_stage_basic
run_test test_stage_conflict
@@ -864,3 +906,4 @@ run_test test_stage_revert
run_test test_stage_diff
run_test test_stage_histedit
run_test test_stage_rebase
+run_test test_stage_update