diff options
| -rw-r--r-- | commit.sh | 64 | ||||
| -rw-r--r-- | main.sh | 2 | 
2 files changed, 66 insertions, 0 deletions
| @@ -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 +} @@ -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 | 
