diff options
author | Malf Furious <m@lfurio.us> | 2017-04-27 23:40:11 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-04-27 23:40:11 -0400 |
commit | c61c94fb66deaad15087dc21c1f71ccb7bb16f96 (patch) | |
tree | 5265e007c2e35602b3112c3947e86112b3b19cda /checkout.sh | |
parent | 1e0b46f7068fee1470e8b785fc29e1b9ff4da2fd (diff) | |
download | systrunk-c61c94fb66deaad15087dc21c1f71ccb7bb16f96.tar.gz systrunk-c61c94fb66deaad15087dc21c1f71ccb7bb16f96.zip |
Add checkout module
Diffstat (limited to 'checkout.sh')
-rw-r--r-- | checkout.sh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/checkout.sh b/checkout.sh new file mode 100644 index 0000000..5ea4b70 --- /dev/null +++ b/checkout.sh @@ -0,0 +1,61 @@ +## +# systrunk checkout [[<remote>] <path>] <version> +# +# Reset a worktree to the state at <version>. If <path> is given, +# checkout also initializes a new worktree at the CWD. If <remote> +# is given, the path is assumed to be located on a remote machine +# and is contacted over SSH. While resetting to the state at +# <version>, all local uncommitted changes are lost. +# +# After checkout, BASE and TRAC will be set to <version>. +## +function systr_checkout +{ + # check arguments # + if [ $# -lt 2 ]; then + echo "Missing required parameters" + exit + fi + + # init worktree # + if [ $# -gt 2 ]; then + init_wktree $@ + fi + + # perform checkout # + read remote <.systr/remote + read path <.systr/path + version=$2 + + if [[ "$version" == "NULL" ]]; then + echo "Checking out NULL :: Checkout not performed" + exit + fi + + commit=$(get_commit "$version") + symref=$(get_symref "$version") + + echo "$commit" >.systr/BASE + echo "$symref" >.systr/TRAC + + if [[ "$commit" == "NULL" ]]; then + echo "Nothing to checkout" + exit + fi + + echo "Checking out files..." + + # local repository # + if [[ "$remote" == "" ]]; then + rsync -az --info=progress2 --info=stats2 \ + --delete --exclude='*.systr' \ + "$path/$commit/" . + + # remote repository # + else + rsync -az -e ssh --info=progress2 --info=stats2 \ + --delete --exclude='*.systr' \ + "$remote:$path/$commit/" . + + fi +} |