summaryrefslogtreecommitdiffstats
path: root/checkout.sh
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-04-30 22:23:16 -0400
committerMalf Furious <m@lfurio.us>2017-04-30 22:23:16 -0400
commit38f60a3be294d1bfe79c91bd4fe9c74b51a20bd5 (patch)
tree79aa000832dffce7a35e351f2204278c1fb9455c /checkout.sh
parent151f754b5e87920c3fec9927f978549b2343a99b (diff)
downloadsystrunk-38f60a3be294d1bfe79c91bd4fe9c74b51a20bd5.tar.gz
systrunk-38f60a3be294d1bfe79c91bd4fe9c74b51a20bd5.zip
Add functions systr_init_wktree() and systr_check_repo()
Diffstat (limited to 'checkout.sh')
-rw-r--r--checkout.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/checkout.sh b/checkout.sh
index 01a9bf0..ab9d4bd 100644
--- a/checkout.sh
+++ b/checkout.sh
@@ -1,4 +1,66 @@
##
+# systr_check_repo <path>
+#
+# Assert that the local repository path exists and is valid.
+##
+function systr_check_repo
+{
+ if [ $# -lt 1 ]; then
+ echo "Fatal: too few arguments to systr_check_repo"
+ exit 1
+ fi
+
+ path="$1"
+
+ (
+ cd "$path"
+
+ if [ ! -f "refs/HEAD" ]; then
+ echo "Fatal: $path is not a repository"
+ exit 1
+ fi
+ )
+}
+
+##
+# systr_init_wktree [<remote>] <path>
+#
+# Assert that the repository at <remote>:<path> exists, then setup
+# the .systr directory at the CWD.
+##
+function systr_init_wktree
+{
+ if [ $# -lt 1 ]; then
+ echo "Fatal: too few arguments to systr_init_wktree"
+ exit 1
+ fi
+
+ if [ $# -gt 1 ]; then
+ remote="$1"
+ shift
+ else
+ remote=""
+ fi
+
+ path="$1"
+
+ if [[ "$remote" == "" ]]; then
+ systr_check_repo "$path"
+ else
+ ssh "$remote" "systrunk check-repo \"$path\""
+ fi
+
+ mkdir -p .systr/
+
+ echo "$remote" >.systr/remote
+ echo "$path" >.systr/path
+ echo "NULL" >.systr/BASE
+ echo "NULL" >.systr/TRAC
+
+ echo "Setup worktree at $(pwd)"
+}
+
+##
# systrunk checkout <version> [[<remote>] <path>]
#
# Reset a worktree to the state at <version>. If <path> is given,