From 38f60a3be294d1bfe79c91bd4fe9c74b51a20bd5 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 30 Apr 2017 22:23:16 -0400 Subject: Add functions systr_init_wktree() and systr_check_repo() --- checkout.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/checkout.sh b/checkout.sh index 01a9bf0..ab9d4bd 100644 --- a/checkout.sh +++ b/checkout.sh @@ -1,3 +1,65 @@ +## +# systr_check_repo +# +# 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 [] +# +# Assert that the repository at : 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 [[] ] # -- cgit v1.2.3