summaryrefslogtreecommitdiff
path: root/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-29 11:07:11 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-29 18:47:16 +0100
commit4018afbdb583517277a0f1f7d990fa4c2a04923a (patch)
tree625e63034b107c07a205d7077e0e0faec807d8b7 /tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script
parentb78ac0f72aa2fc4815131bb2bbd883a373c62e48 (diff)
downloadmorph-4018afbdb583517277a0f1f7d990fa4c2a04923a.tar.gz
Make "morph show-system-branch" anywhere in a workspace, if possible
There are mainly three situations to deal with: 1. We are outside a workspace and cannot deduce the system branch. 2. We are inside a workspace and inside a branch. We can detect this by walking up from the working directory towards the workspace. If we find a .morph-system-branch in one of the parent directories, we know the branch name. If we don't find one, something is wrong. 3. We are inside a workspace but outside a branch (or partially into a branch, e.g. in foo/ where the branch is foo/bar). We can deduce the branch if we recurse into subdirectories to find a .morph-system-branch directory. Care needs to be taken to not recurse infinitely. We may also not recurse if there are multiple subdirectories as these could belong to two different branches. This commit makes "morph show-system-branch" work in all of the above scenarios. It also adds tests for all of them.
Diffstat (limited to 'tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script')
-rwxr-xr-xtests.branching/show-system-branch-works-in-different-directories-in-a-branch.script57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script b/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script
new file mode 100755
index 00000000..1391f0ec
--- /dev/null
+++ b/tests.branching/show-system-branch-works-in-different-directories-in-a-branch.script
@@ -0,0 +1,57 @@
+#!/bin/sh
+# Copyright (C) 2012 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+# Check that 'morph show-system-branch' shows the name of the
+# current system branch correctly from various working directories.
+
+
+set -eu
+
+# Create a workspace and two system branches.
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" branch first/branch
+"$SRCDIR/scripts/test-morph" branch second/branch
+
+# Create a few subdirectories in the first branch.
+mkdir -p "$DATADIR/workspace/first/branch/foo"
+mkdir -p "$DATADIR/workspace/first/branch/bar"
+mkdir -p "$DATADIR/workspace/first/branch/foo/bar/baz"
+
+# Show the first branch when partially inside the branch.
+cd "$DATADIR/workspace/first"
+"$SRCDIR/scripts/test-morph" show-system-branch
+
+# Show the first branch when inside the main branch directory.
+cd "$DATADIR/workspace/first/branch"
+"$SRCDIR/scripts/test-morph" show-system-branch
+
+# Show the first branch when somewhere inside the branch.
+cd "$DATADIR/workspace/first/branch/foo"
+"$SRCDIR/scripts/test-morph" show-system-branch
+
+# Show the first branch when somewhere else inside the branch.
+cd "$DATADIR/workspace/first/branch/foo/bar/baz"
+"$SRCDIR/scripts/test-morph" show-system-branch
+
+# Show the second branch when partially inside the branch.
+cd "$DATADIR/workspace/second"
+"$SRCDIR/scripts/test-morph" show-system-branch
+
+# Show the second branch when inside the main branch directory.
+cd "$DATADIR/workspace/second/branch"
+"$SRCDIR/scripts/test-morph" show-system-branch