0f8abc0854a2f6b4cbfcc7a4f50f403b52167ccb
   1#!/bin/sh
   2
   3test_description='test git worktree move, remove, lock and unlock'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        test_commit init &&
   9        git worktree add source &&
  10        git worktree list --porcelain | grep "^worktree" >actual &&
  11        cat <<-EOF >expected &&
  12        worktree $(pwd)
  13        worktree $(pwd)/source
  14        EOF
  15        test_cmp expected actual
  16'
  17
  18test_expect_success 'lock main worktree' '
  19        test_must_fail git worktree lock .
  20'
  21
  22test_expect_success 'lock linked worktree' '
  23        git worktree lock --reason hahaha source &&
  24        echo hahaha >expected &&
  25        test_cmp expected .git/worktrees/source/locked
  26'
  27
  28test_expect_success 'lock linked worktree from another worktree' '
  29        rm .git/worktrees/source/locked &&
  30        git worktree add elsewhere &&
  31        git -C elsewhere worktree lock --reason hahaha ../source &&
  32        echo hahaha >expected &&
  33        test_cmp expected .git/worktrees/source/locked
  34'
  35
  36test_expect_success 'lock worktree twice' '
  37        test_must_fail git worktree lock source &&
  38        echo hahaha >expected &&
  39        test_cmp expected .git/worktrees/source/locked
  40'
  41
  42test_expect_success 'lock worktree twice (from the locked worktree)' '
  43        test_must_fail git -C source worktree lock . &&
  44        echo hahaha >expected &&
  45        test_cmp expected .git/worktrees/source/locked
  46'
  47
  48test_expect_success 'unlock main worktree' '
  49        test_must_fail git worktree unlock .
  50'
  51
  52test_expect_success 'unlock linked worktree' '
  53        git worktree unlock source &&
  54        test_path_is_missing .git/worktrees/source/locked
  55'
  56
  57test_expect_success 'unlock worktree twice' '
  58        test_must_fail git worktree unlock source &&
  59        test_path_is_missing .git/worktrees/source/locked
  60'
  61
  62test_expect_success 'move non-worktree' '
  63        mkdir abc &&
  64        test_must_fail git worktree move abc def
  65'
  66
  67test_expect_success 'move locked worktree' '
  68        git worktree lock source &&
  69        test_when_finished "git worktree unlock source" &&
  70        test_must_fail git worktree move source destination
  71'
  72
  73test_expect_success 'move worktree' '
  74        toplevel="$(pwd)" &&
  75        git worktree move source destination &&
  76        test_path_is_missing source &&
  77        git worktree list --porcelain | grep "^worktree.*/destination" &&
  78        ! git worktree list --porcelain | grep "^worktree.*/source" >empty &&
  79        git -C destination log --format=%s >actual2 &&
  80        echo init >expected2 &&
  81        test_cmp expected2 actual2
  82'
  83
  84test_expect_success 'move main worktree' '
  85        test_must_fail git worktree move . def
  86'
  87
  88test_done