Commit Diff


commit - 243d7cf151a263df63eb1e203effec4218b78e8a
commit + a76c42e670c040cbc63fae5cedba54de3540ce3c
blob - c62f844a6d658b784464b3887910990df6b30b79
blob + 0115f0622a0a1725349d74ab33e8f9c95ba22184
--- lib/worktree.c
+++ 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_
 	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");
blob - 87156b328de4f944c0e2fb7a849795b86e4ec61c
blob + 4d057d721979e93aa1b31d4d280ee4f9deadbab0
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
@@ -852,7 +852,49 @@ 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
 run_test test_stage_out_of_date
@@ -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