From b4acf0ac3704124bbb76528beea5656c0239d1cb Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 13 Sep 2017 02:05:25 -0400 Subject: Add reset op --- commit.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.sh | 2 ++ 2 files changed, 66 insertions(+) diff --git a/commit.sh b/commit.sh index f2cf7f3..ade63f1 100644 --- a/commit.sh +++ b/commit.sh @@ -115,3 +115,67 @@ function systr_commit echo "$branch" >.systr/TRAC fi } + +## +# systrunk reset +# +# Similar to systrunk commit, but doesn't require the worktree to +# be up-to-date with . This command can be used to rollback +# a branch to a previous state by running systrunk checkout followed +# by this command. If does not exist, this command will +# fail. If is a commit ID instead of a symbolic reference, +# no action is taken. +## +function systr_reset +{ + if [ $# -lt 1 ]; then + echo "Fatal: too few args to reset" >&2 + exit 1 + fi + + branch="$1" + + if [[ "$branch" == "BASE" ]]; then + echo "Fatal: bad branch name BASE" >&2 + exit 1 + elif [[ "$branch" == "TRAC" ]]; then + echo "Fatal: bad branch name TRAC" >&2 + exit 1 + elif [[ "$branch" == "NULL" ]]; then + echo "Fatal: bad branch name NULL" >&2 + exit 1 + elif [[ "$branch" == "MERG" ]]; then + echo "Fatal: bad branch name MERG" >&2 + exit 1 + fi + + if [[ "$MERG" != "NULL" ]]; then + echo "Fatal: merge in progress, won't reset" >&2 + exit 1 + fi + + branchcommit=$(systr_repo_resolve_reference "$branch") + + if [[ "$branchcommit" == "$branch" ]]; then + echo "Fatal: $branch is a commit ID, not a symbolic reference" >&2 + exit 1 + fi + + commit=$(systr_repo_create_commit) + systr_record_commit_mesg "$commit" "$branch" "Reset $branch to state at $BASE" + echo "Performing RESET" + echo "Sending files..." + + if [[ "$BASE" != "NULL" ]]; then + systr_rsync_normal . "$path/revs/$commit/" "../$BASE/" + else + systr_rsync_normal . "$path/revs/$commit/" + fi + + systr_repo_finish_commit "$commit" "$branchcommit" + echo "$commit" >.systr/BASE + echo "NULL" >.systr/MERG + date >.systr/updated + systr_repo_set_reference "$branch" "$commit" + echo "$branch" >.systr/TRAC +} diff --git a/main.sh b/main.sh index 9bf4df1..5593dd8 100644 --- a/main.sh +++ b/main.sh @@ -43,6 +43,8 @@ function main systr_checkout "$@" elif [[ "$cmd" == "commit" ]]; then systr_commit "$@" + elif [[ "$cmd" == "reset" ]]; then + systr_reset "$@" elif [[ "$cmd" == "tag" ]]; then systr_repo_tag "$@" elif [[ "$cmd" == "shortlog" ]]; then -- cgit v1.2.3