t / t2027-worktree-list.shon commit revision: new rev^-n shorthand for rev^n..rev (8779351)
   1#!/bin/sh
   2
   3test_description='test git worktree list'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        test_commit init
   9'
  10
  11test_expect_success 'rev-parse --git-common-dir on main worktree' '
  12        git rev-parse --git-common-dir >actual &&
  13        echo .git >expected &&
  14        test_cmp expected actual &&
  15        mkdir sub &&
  16        git -C sub rev-parse --git-common-dir >actual2 &&
  17        echo sub/.git >expected2 &&
  18        test_cmp expected2 actual2
  19'
  20
  21test_expect_success '"list" all worktrees from main' '
  22        echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
  23        test_when_finished "rm -rf here && git worktree prune" &&
  24        git worktree add --detach here master &&
  25        echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
  26        git worktree list | sed "s/  */ /g" >actual &&
  27        test_cmp expect actual
  28'
  29
  30test_expect_success '"list" all worktrees from linked' '
  31        echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
  32        test_when_finished "rm -rf here && git worktree prune" &&
  33        git worktree add --detach here master &&
  34        echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
  35        git -C here worktree list | sed "s/  */ /g" >actual &&
  36        test_cmp expect actual
  37'
  38
  39test_expect_success '"list" all worktrees --porcelain' '
  40        echo "worktree $(git rev-parse --show-toplevel)" >expect &&
  41        echo "HEAD $(git rev-parse HEAD)" >>expect &&
  42        echo "branch $(git symbolic-ref HEAD)" >>expect &&
  43        echo >>expect &&
  44        test_when_finished "rm -rf here && git worktree prune" &&
  45        git worktree add --detach here master &&
  46        echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect &&
  47        echo "HEAD $(git rev-parse HEAD)" >>expect &&
  48        echo "detached" >>expect &&
  49        echo >>expect &&
  50        git worktree list --porcelain >actual &&
  51        test_cmp expect actual
  52'
  53
  54test_expect_success 'bare repo setup' '
  55        git init --bare bare1 &&
  56        echo "data" >file1 &&
  57        git add file1 &&
  58        git commit -m"File1: add data" &&
  59        git push bare1 master &&
  60        git reset --hard HEAD^
  61'
  62
  63test_expect_success '"list" all worktrees from bare main' '
  64        test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
  65        git -C bare1 worktree add --detach ../there master &&
  66        echo "$(pwd)/bare1 (bare)" >expect &&
  67        echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
  68        git -C bare1 worktree list | sed "s/  */ /g" >actual &&
  69        test_cmp expect actual
  70'
  71
  72test_expect_success '"list" all worktrees --porcelain from bare main' '
  73        test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
  74        git -C bare1 worktree add --detach ../there master &&
  75        echo "worktree $(pwd)/bare1" >expect &&
  76        echo "bare" >>expect &&
  77        echo >>expect &&
  78        echo "worktree $(git -C there rev-parse --show-toplevel)" >>expect &&
  79        echo "HEAD $(git -C there rev-parse HEAD)" >>expect &&
  80        echo "detached" >>expect &&
  81        echo >>expect &&
  82        git -C bare1 worktree list --porcelain >actual &&
  83        test_cmp expect actual
  84'
  85
  86test_expect_success '"list" all worktrees from linked with a bare main' '
  87        test_when_finished "rm -rf there && git -C bare1 worktree prune" &&
  88        git -C bare1 worktree add --detach ../there master &&
  89        echo "$(pwd)/bare1 (bare)" >expect &&
  90        echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
  91        git -C there worktree list | sed "s/  */ /g" >actual &&
  92        test_cmp expect actual
  93'
  94
  95test_expect_success 'bare repo cleanup' '
  96        rm -rf bare1
  97'
  98
  99test_done