commit - 1e1446d382398be679918a75e69163fb600fbab3
commit + 9acbc4faa04684945483940044d1b32175a9471e
blob - f37c253a3149dc63c7b93bf00c1c3f5906eddc30
blob + 5e0b55d524c46b55400a3caf23b78c5612cc2649
--- include/got_error.h
+++ include/got_error.h
#define GOT_ERR_HISTEDIT_PATH 98
#define GOT_ERR_NO_MERGED_PATHS 99
#define GOT_ERR_COMMIT_BRANCH 100
+#define GOT_ERR_FILE_STAGED 101
static const struct got_error {
int code;
{ GOT_ERR_NO_MERGED_PATHS, "empty list of merged paths" },
{ GOT_ERR_COMMIT_BRANCH, "will not commit to a branch outside the "
"\"refs/heads/\" reference namespace" },
+ { GOT_ERR_FILE_STAGED, "file has staged changes" },
};
/*
blob - d40289335e722c9620094d0cfbfebe7527a68ab1
blob + 9b859b25a5334be8bbf678d47c83f6913903b322
--- lib/worktree.c
+++ lib/worktree.c
{
const struct got_error *err = NULL;
struct got_fileindex_entry *ie = NULL;
- unsigned char status;
+ unsigned char status, staged_status;
struct stat sb;
ie = got_fileindex_entry_get(fileindex, relpath, strlen(relpath));
if (ie == NULL)
return got_error(GOT_ERR_BAD_PATH);
+ staged_status = get_staged_status(ie);
+ if (staged_status != GOT_STATUS_NO_CHANGE) {
+ if (staged_status == GOT_STATUS_DELETE)
+ return NULL;
+ return got_error_path(relpath, GOT_ERR_FILE_STAGED);
+ }
+
err = get_file_status(&status, &sb, ie, ondisk_path, repo);
if (err)
return err;
blob - f23f8a050f7c15ae2e735c6ceabf32ace25b9d0c
blob + 0631a5ba992111c432b78a52d9dc265b000e7628
--- regress/cmdline/stage.sh
+++ regress/cmdline/stage.sh
test_done "$testroot" "$ret"
}
+function test_stage_rm_already_staged_file {
+ local testroot=`test_init stage_rm_already_staged_file`
+
+ 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 rm beta > /dev/null)
+ echo "new file" > $testroot/wt/foo
+ (cd $testroot/wt && got add foo > /dev/null)
+
+ (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
+
+ (cd $testroot/wt && got rm beta \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got rm command succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+ echo "got: realpath: beta: No such file or directory" \
+ > $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
+
+ for f in alpha foo; do
+ echo "got: $f: file has staged changes" \
+ > $testroot/stderr.expected
+ (cd $testroot/wt && got rm $f \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "got rm command succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+ 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
+ done
+
+ echo ' M alpha' > $testroot/stdout.expected
+ echo ' D beta' >> $testroot/stdout.expected
+ echo ' A foo' >> $testroot/stdout.expected
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+ 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_status
run_test test_stage_add_already_staged_file
+run_test test_stage_rm_already_staged_file