-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'git worktree list' iterates through the worktree list, and outputs details of the worktree including the path to the worktree, the currently checked out revision and branch, and if the work tree is bare. There is also porcelain format option available. Signed-off-by: Michael Rappazzo <rappazzo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Michael Rappazzo
authored and
Junio C Hamano
committed
Oct 8, 2015
1 parent
92718b7
commit bb9c03b
Showing
3 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/sh | ||
|
||
test_description='test git worktree list' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success 'setup' ' | ||
test_commit init | ||
' | ||
|
||
test_expect_success '"list" all worktrees from main' ' | ||
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && | ||
test_when_finished "rm -rf here && git worktree prune" && | ||
git worktree add --detach here master && | ||
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && | ||
git worktree list | sed "s/ */ /g" >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success '"list" all worktrees from linked' ' | ||
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && | ||
test_when_finished "rm -rf here && git worktree prune" && | ||
git worktree add --detach here master && | ||
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && | ||
git -C here worktree list | sed "s/ */ /g" >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success '"list" all worktrees --porcelain' ' | ||
echo "worktree $(git rev-parse --show-toplevel)" >expect && | ||
echo "HEAD $(git rev-parse HEAD)" >>expect && | ||
echo "branch $(git symbolic-ref HEAD)" >>expect && | ||
echo >>expect && | ||
test_when_finished "rm -rf here && git worktree prune" && | ||
git worktree add --detach here master && | ||
echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect && | ||
echo "HEAD $(git rev-parse HEAD)" >>expect && | ||
echo "detached" >>expect && | ||
echo >>expect && | ||
git worktree list --porcelain >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success 'bare repo setup' ' | ||
git init --bare bare1 && | ||
echo "data" >file1 && | ||
git add file1 && | ||
git commit -m"File1: add data" && | ||
git push bare1 master && | ||
git reset --hard HEAD^ | ||
' | ||
|
||
test_expect_success '"list" all worktrees from bare main' ' | ||
test_when_finished "rm -rf there && git -C bare1 worktree prune" && | ||
git -C bare1 worktree add --detach ../there master && | ||
echo "$(pwd)/bare1 (bare)" >expect && | ||
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && | ||
git -C bare1 worktree list | sed "s/ */ /g" >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success '"list" all worktrees --porcelain from bare main' ' | ||
test_when_finished "rm -rf there && git -C bare1 worktree prune" && | ||
git -C bare1 worktree add --detach ../there master && | ||
echo "worktree $(pwd)/bare1" >expect && | ||
echo "bare" >>expect && | ||
echo >>expect && | ||
echo "worktree $(git -C there rev-parse --show-toplevel)" >>expect && | ||
echo "HEAD $(git -C there rev-parse HEAD)" >>expect && | ||
echo "detached" >>expect && | ||
echo >>expect && | ||
git -C bare1 worktree list --porcelain >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success '"list" all worktrees from linked with a bare main' ' | ||
test_when_finished "rm -rf there && git -C bare1 worktree prune" && | ||
git -C bare1 worktree add --detach ../there master && | ||
echo "$(pwd)/bare1 (bare)" >expect && | ||
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && | ||
git -C there worktree list | sed "s/ */ /g" >actual && | ||
test_cmp expect actual | ||
' | ||
|
||
test_expect_success 'bare repo cleanup' ' | ||
rm -rf bare1 | ||
' | ||
|
||
test_done |