summaryrefslogtreecommitdiffstats
path: root/commit.sh
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-09-13 02:05:25 -0400
committerMalf Furious <m@lfurio.us>2017-09-13 02:05:25 -0400
commitb4acf0ac3704124bbb76528beea5656c0239d1cb (patch)
treed73ef6caafc56828d345c755072da395e77739ab /commit.sh
parentcf67abdf0e7c29c69abdcb8e9c2ba995622eeb28 (diff)
downloadsystrunk-b4acf0ac3704124bbb76528beea5656c0239d1cb.tar.gz
systrunk-b4acf0ac3704124bbb76528beea5656c0239d1cb.zip
Add reset op
Diffstat (limited to 'commit.sh')
-rw-r--r--commit.sh64
1 files changed, 64 insertions, 0 deletions
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 <branch>
+#
+# Similar to systrunk commit, but doesn't require the worktree to
+# be up-to-date with <branch>. This command can be used to rollback
+# a branch to a previous state by running systrunk checkout followed
+# by this command. If <branch> does not exist, this command will
+# fail. If <branch> 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
+}