blob: 1190715f1d7b8ce0613ef9a21a089a80bc6847bc (
plain) (
tree)
|
|
##
# systr_record_commit_mesg <commit> [<mesg>]
#
# Setup and present user with an editor to enter a commit message for
# the given commit ID. If <mesg> is given, that content will be the
# default in the opened text file. Once user is finished, the file is
# moved into the repository root, awaiting a call to systr_repo_finish_commit.
##
function systr_record_commit_mesg
{
if [ $# -eq 0 ]; then
echo "Fatal: too few arguments to systr_record_commit_mesg"
exit 1
fi
commit="$1"
if [ $# -gt 1 ]; then
mesg="$2"
else
mesg=""
fi
echo "$mesg" >.systr/commit-edit-mesg.txt
echo "# --" >>.systr/commit-edit-mesg.txt
systrunk status | sed 's/^/# /' >>.systr/commit-edit-mesg.txt
vi .systr/commit-edit-mesg.txt
sed '/^#/ d' <.systr/commit-edit-mesg.txt >.systr/commit.mesg
if [[ "$remote" == "" ]]; then
mv .systr/commit.mesg "$path/revs/$commit.mesg"
else
ssh "$remote" "systrunk message-commit \"$commit\"" <.systr/commit.mesg
fi
}
##
# systrunk commit [<branch>=TRAC]
#
# Create a snapshot of the current state of the worktree and record
# it in the repository. Your worktree must be up-to-date with <branch>
# before you can commit. The branch committed to is updated to
# reference the new commit. If <branch> does not exist in the
# repository, it is created. If <branch> is a commit ID instead of
# a symbolic reference, the new commit will not exist on any branch,
# but an anonymous one referenced by TRAC.
##
function systr_commit
{
if [ $# -ne 0 ]; then
branch="$1"
else
branch="$TRAC"
fi
if [[ "$branch" == "BASE" ]]; then
echo "Fatal: bad branch name"
exit 1
elif [[ "$branch" == "TRAC" ]]; then
echo "Fatal: bad branch name"
exit 1
elif [[ "$branch" == "NULL" ]]; then
echo "Fatal: bad branch name"
exit 1
elif [[ "$branch" == "MERG" ]]; then
echo "Fatal: bad branch name"
exit 1
fi
branchcommit=$(systr_repo_resolve_reference "$branch" 2>/dev/null) || branchcommit="$BASE"
systr_repo_resolve_reference "$branch" >/dev/null 2>&1 || echo "Creating new branch $branch"
if [[ "$BASE" != "$branchcommit" ]]; then
echo "Worktree is out-of-date, won't commit"
exit 1
fi
commit=$(systr_repo_create_commit)
systr_record_commit_mesg "$commit"
echo "Sending files..."
if [[ "$branchcommit" != "NULL" ]]; then
systr_rsync_normal . "$path/revs/$commit" "../$branchcommit"
else
systr_rsync_normal . "$path/revs/$commit"
fi
systr_repo_finish_commit "$commit" "$branchcommit"
echo "$commit" >.systr/BASE
if [[ "$branch" != "$branchcommit" ]]; then
systr_repo_set_reference "$branch" "$commit"
fi
if [[ "$TRAC" == "$BASE" ]]; then
echo "$commit" >.systr/TRAC
else
echo "$branch" >.systr/TRAC
fi
}
|