fix: cd/pushd to worktree using 'git_wtree' shortcut function fix/cd-over-shortcut-function
authorAndrew Sichevoi <kondor@thekondor.net>
Thu, 4 Oct 2018 11:03:35 +0000 (14:03 +0300)
committerAndrew Sichevoi <kondor@thekondor.net>
Thu, 4 Oct 2018 11:03:35 +0000 (14:03 +0300)
git-wtree.sh
test-git-wtree.sh

index fe04aea..8c52a9f 100755 (executable)
@@ -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} $*
index 996f456..880378e 100755 (executable)
@@ -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