summaryrefslogtreecommitdiff
path: root/t/t2028-worktree-move.sh
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-02-12 09:49:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-02-12 21:13:35 (GMT)
commitcc73385cf6c5c229458775bc92e7dbbe24d11611 (patch)
tree4b4c59f18ee8dfad93084ca4c0b75f6a10eb1444 /t/t2028-worktree-move.sh
parent78d986b252359351a579dc2629c8384d5c8eb8ff (diff)
downloadgit-cc73385cf6c5c229458775bc92e7dbbe24d11611.zip
git-cc73385cf6c5c229458775bc92e7dbbe24d11611.tar.gz
git-cc73385cf6c5c229458775bc92e7dbbe24d11611.tar.bz2
worktree remove: new command
This command allows to delete a worktree. Like 'move' you cannot remove the main worktree, or one with submodules inside [1]. For deleting $GIT_WORK_TREE, Untracked files or any staged entries are considered precious and therefore prevent removal by default. Ignored files are not precious. When it comes to deleting $GIT_DIR, there's no "clean" check because there should not be any valuable data in there, except: - HEAD reflog. There is nothing we can do about this until somebody steps up and implements the ref graveyard. - Detached HEAD. Technically it can still be recovered. Although it may be nice to warn about orphan commits like 'git checkout' does. [1] We do 'git status' with --ignore-submodules=all for safety anyway. But this needs a closer look by submodule people before we can allow deletion. For example, if a submodule is totally clean, but its repo not absorbed to the main .git dir, then deleting worktree also deletes the valuable .submodule repo too. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2028-worktree-move.sh')
-rwxr-xr-xt/t2028-worktree-move.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/t/t2028-worktree-move.sh b/t/t2028-worktree-move.sh
index deb486c..4718c45 100755
--- a/t/t2028-worktree-move.sh
+++ b/t/t2028-worktree-move.sh
@@ -96,4 +96,34 @@ test_expect_success 'move worktree to another dir' '
test_cmp expected2 actual2
'
+test_expect_success 'remove main worktree' '
+ test_must_fail git worktree remove .
+'
+
+test_expect_success 'move some-dir/destination back' '
+ git worktree move some-dir/destination destination
+'
+
+test_expect_success 'remove locked worktree' '
+ git worktree lock destination &&
+ test_when_finished "git worktree unlock destination" &&
+ test_must_fail git worktree remove destination
+'
+
+test_expect_success 'remove worktree with dirty tracked file' '
+ echo dirty >>destination/init.t &&
+ test_when_finished "git -C destination checkout init.t" &&
+ test_must_fail git worktree remove destination
+'
+
+test_expect_success 'remove worktree with untracked file' '
+ : >destination/untracked &&
+ test_must_fail git worktree remove destination
+'
+
+test_expect_success 'force remove worktree with untracked file' '
+ git worktree remove --force destination &&
+ test_path_is_missing destination
+'
+
test_done