commit - f032f1f7ee503b7aa2577cf836c485f96620e772
commit + f0b0c0cee4bcde602c12bf5a2be6bd107a7ced66
blob - 86889ab60a4f04afc08edff1551b7ab9c3f46e57
blob + d52d55ec691b7403e0f094e701a8449ef30e216a
--- lib/worktree.c
+++ lib/worktree.c
if (status != GOT_STATUS_NO_CHANGE) {
if (status == GOT_STATUS_DELETE)
return NULL;
- if (status != GOT_STATUS_MODIFY)
- return got_error(GOT_ERR_FILE_STATUS);
- if (!delete_local_mods)
- return got_error(GOT_ERR_FILE_MODIFIED);
+ if (status == GOT_STATUS_MODIFY && !delete_local_mods)
+ return got_error_path(relpath, GOT_ERR_FILE_MODIFIED);
+ if (status != GOT_STATUS_MODIFY &&
+ status != GOT_STATUS_MISSING)
+ return got_error_path(relpath, GOT_ERR_FILE_STATUS);
}
- if (unlink(ondisk_path) != 0)
+ if (status != GOT_STATUS_MISSING && unlink(ondisk_path) != 0)
return got_error_from_errno2("unlink", ondisk_path);
got_fileindex_entry_mark_deleted_from_disk(ie);
blob - 8d663c816fcc48fad3790aeacf9f73d6ef7ee8be
blob + 03c8d8fc147c4298c5425973fe32318e931e8992
--- regress/cmdline/rm.sh
+++ regress/cmdline/rm.sh
fi
echo "modified beta" > $testroot/wt/beta
- echo 'got: file contains modifications' > $testroot/stderr.expected
+ echo 'got: beta: file contains modifications' \
+ > $testroot/stderr.expected
(cd $testroot/wt && got rm beta 2>$testroot/stderr)
cmp -s $testroot/stderr.expected $testroot/stderr
test_done "$testroot" "0"
}
+function test_rm_and_add_elsewhere {
+ local testroot=`test_init rm_and_add_elsewhere`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && mv alpha epsilon/)
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+
+ echo '! alpha' > $testroot/stdout.expected
+ echo '? epsilon/alpha' >> $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo 'D alpha' > $testroot/stdout.expected
+ (cd $testroot/wt && got rm alpha > $testroot/stdout)
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo 'A epsilon/alpha' > $testroot/stdout.expected
+ (cd $testroot/wt && got add epsilon/alpha > $testroot/stdout)
+
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got status > $testroot/stdout)
+
+ echo 'D alpha' > $testroot/stdout.expected
+ echo 'A epsilon/alpha' >> $testroot/stdout.expected
+ 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_rm_basic
run_test test_rm_with_local_mods
run_test test_double_rm
+run_test test_rm_and_add_elsewhere