#!/bin/sh global test_description := ''test git worktree move, remove, lock and unlock'' source ./test-lib.sh test_expect_success 'setup' ' test_commit init && git worktree add source && git worktree list --porcelain | grep "^worktree" >actual && cat <<-EOF >expected && worktree $(pwd) worktree $(pwd)/source EOF test_cmp expected actual ' test_expect_success 'lock main worktree' ' test_must_fail git worktree lock . ' test_expect_success 'lock linked worktree' ' git worktree lock --reason hahaha source && echo hahaha >expected && test_cmp expected .git/worktrees/source/locked ' test_expect_success 'lock linked worktree from another worktree' ' rm .git/worktrees/source/locked && git worktree add elsewhere && git -C elsewhere worktree lock --reason hahaha ../source && echo hahaha >expected && test_cmp expected .git/worktrees/source/locked ' test_expect_success 'lock worktree twice' ' test_must_fail git worktree lock source && echo hahaha >expected && test_cmp expected .git/worktrees/source/locked ' test_expect_success 'lock worktree twice (from the locked worktree)' ' test_must_fail git -C source worktree lock . && echo hahaha >expected && test_cmp expected .git/worktrees/source/locked ' test_expect_success 'unlock main worktree' ' test_must_fail git worktree unlock . ' test_expect_success 'unlock linked worktree' ' git worktree unlock source && test_path_is_missing .git/worktrees/source/locked ' test_expect_success 'unlock worktree twice' ' test_must_fail git worktree unlock source && test_path_is_missing .git/worktrees/source/locked ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test git worktree move, remove, lock and unlock">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\ttest_commit init &&\n"> <"\tgit worktree add source &&\n"> <"\tgit worktree list --porcelain | grep \"^worktree\" >actual &&\n"> <"\tcat <<-EOF >expected &&\n"> <"\tworktree $(pwd)\n"> <"\tworktree $(pwd)/source\n"> <"\tEOF\n"> <"\ttest_cmp expected actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"lock main worktree">)} {(SQ <"\n"> <"\ttest_must_fail git worktree lock .\n">)} ) (C {(test_expect_success)} {(SQ <"lock linked worktree">)} { (SQ <"\n"> <"\tgit worktree lock --reason hahaha source &&\n"> <"\techo hahaha >expected &&\n"> <"\ttest_cmp expected .git/worktrees/source/locked\n"> ) } ) (C {(test_expect_success)} {(SQ <"lock linked worktree from another worktree">)} { (SQ <"\n"> <"\trm .git/worktrees/source/locked &&\n"> <"\tgit worktree add elsewhere &&\n"> <"\tgit -C elsewhere worktree lock --reason hahaha ../source &&\n"> <"\techo hahaha >expected &&\n"> <"\ttest_cmp expected .git/worktrees/source/locked\n"> ) } ) (C {(test_expect_success)} {(SQ <"lock worktree twice">)} { (SQ <"\n"> <"\ttest_must_fail git worktree lock source &&\n"> <"\techo hahaha >expected &&\n"> <"\ttest_cmp expected .git/worktrees/source/locked\n"> ) } ) (C {(test_expect_success)} {(SQ <"lock worktree twice (from the locked worktree)">)} { (SQ <"\n"> <"\ttest_must_fail git -C source worktree lock . &&\n"> <"\techo hahaha >expected &&\n"> <"\ttest_cmp expected .git/worktrees/source/locked\n"> ) } ) (C {(test_expect_success)} {(SQ <"unlock main worktree">)} {(SQ <"\n"> <"\ttest_must_fail git worktree unlock .\n">)} ) (C {(test_expect_success)} {(SQ <"unlock linked worktree">)} { (SQ <"\n"> <"\tgit worktree unlock source &&\n"> <"\ttest_path_is_missing .git/worktrees/source/locked\n"> ) } ) (C {(test_expect_success)} {(SQ <"unlock worktree twice">)} { (SQ <"\n"> <"\ttest_must_fail git worktree unlock source &&\n"> <"\ttest_path_is_missing .git/worktrees/source/locked\n"> ) } ) (C {(test_done)}) ] )