From 3a6fad65df3cd4a63a8022743ed250da7ed117e0 Mon Sep 17 00:00:00 2001 From: Andrew Sichevoi Date: Thu, 4 Oct 2018 14:03:35 +0300 Subject: [PATCH] fix: cd/pushd to worktree using 'git_wtree' shortcut function --- git-wtree.sh | 11 ++++++++++- test-git-wtree.sh | 23 ++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/git-wtree.sh b/git-wtree.sh index fe04aea..8c52a9f 100755 --- a/git-wtree.sh +++ b/git-wtree.sh @@ -236,7 +236,16 @@ git_wtree_cmd_tool_pushd() { git_wtree() { [ 0 -eq $# ] && _git_wtree_set_last_error "Command expected: new, drop, locate" && _git_wtree_show_last_error && return - cmd=git_wtree_cmd_$1 + case "$1" in + cd|pushd) + cmd=tool_$1 + ;; + *) + cmd=$1 + ;; + esac + + cmd=git_wtree_cmd_$cmd shift ${cmd} $* diff --git a/test-git-wtree.sh b/test-git-wtree.sh index 996f456..880378e 100755 --- a/test-git-wtree.sh +++ b/test-git-wtree.sh @@ -1,5 +1,9 @@ #!/bin/sh +### +### Naive smoke tests +### + . $(dirname $0)/git-wtree.sh #set -e @@ -8,7 +12,7 @@ SELF_PID=$$ SELF_ROOT=$(readlink -e $(dirname $0)) FIXED_FAKE_ROOT=/tmp/git-wtree-test.root FAKE_ROOT=$([ -z "${GIT_WTREE_TEST_FIXED_ROOT}" ] && mktemp -d || (mkdir ${FIXED_FAKE_ROOT} && ${FIXED_FAKE_ROOT})) -trap cleanup KILL QUIT EXIT +trap cleanup KILL QUIT EXIT fail() { echo -n "*** FAILED: " @@ -72,10 +76,19 @@ worktrees=$(git_wtree_cmd_ls | grep -E '^master|^test-branch-name' | wc -l) echo "= TEST(cd)" echo "== PWD is changed to worktree" -pwd | grep -qi ${FAKE_ROOT}/main.git -[ 0 -eq $? ] || fail "initial directory is main fake root" -git_wtree_cmd_tool_cd test-branch-name 2>&1 -[ x"${FAKE_ROOT}/test-branch.d" = x"$(pwd)" ] || fail "current directory is test-branche's one" +original_pwd=${PWD} +worktree_dir=NONE +for tested_cmd in git_wtree_cmd_tool_cd "git_wtree cd"; do + pwd | grep -qi ${FAKE_ROOT}/main.git + [ 0 -eq $? ] || fail "initial directory is main fake root" + + ${tested_cmd} test-branch-name 2>&1 + [ x"${FAKE_ROOT}/test-branch.d" = x"$(pwd)" ] || fail "current directory is test-branche's one" + worktree_dir="$(pwd)" + cd ${original_pwd} +done +### Next test depends on starting from worktree dir +cd ${worktree_dir} echo "== PWD is changed to master" pwd | grep -qi ${FAKE_ROOT}/test-branch.d -- 2.20.1