summaryrefslogtreecommitdiffstats
path: root/commit.sh
diff options
context:
space:
mode:
Diffstat (limited to 'commit.sh')
-rw-r--r--commit.sh102
1 files changed, 46 insertions, 56 deletions
diff --git a/commit.sh b/commit.sh
index 096631a..ff346ff 100644
--- a/commit.sh
+++ b/commit.sh
@@ -1,13 +1,37 @@
##
-# creat_commit_dir_local
+# systr_record_commit_mesg <commit> [<mesg>]
#
-# Create new commit directory, and assign its commit ID. Commit ID is
-# printed to stdout.
+# 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 creat_commit_dir_local
+function systr_record_commit_mesg
{
- cd "$path"
- mktemp -d XXXXXXXX
+ 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
}
##
@@ -23,67 +47,33 @@ function creat_commit_dir_local
##
function systr_commit
{
- read remote <.systr/remote
- read path <.systr/path
- read BASE <.systr/BASE
- read TRAC <.systr/TRAC
-
- if [ $# -gt 1 ]; then
- branch=$2
+ if [ $# -ne 0 ]; then
+ branch=$1
else
branch="$TRAC"
fi
- branchcommit=$(get_commit "$branch") || branchcommit="$BASE"
+ branchcommit=$(systr_repo_resolve_reference "$branch") || branchcommit="$BASE"
if [[ "$BASE" != "$branchcommit" ]]; then
echo "Worktree is out-of-date, won't commit"
- exit
+ exit 1
fi
- # local repository #
- if [[ "$remote" == "" ]]; then
- newcommit=$(creat_commit_dir_local)
- mesgfile=$(mktemp -t systr-edit-mesg.XXXXXX)
- echo "" >$mesgfile
- echo "# --" >>$mesgfile
- systrunk status | sed 's/^/# /' >>$mesgfile
- vi $mesgfile
-
- echo "Sending files..."
-
- rsync -az --info=progress2 --info=stats2 \
- --delete --exclude='*.systr' \
- --link-dest="$path/$branchcommit/" \
- . "$path/$newcommit/"
-
- sed '/^#/ d' <$mesgfile >"$path/$newcommit/.mesg.systr"
- echo "$branchcommit" >"$path/$newcommit/.commit.systr"
+ commit=$(systr_repo_create_commit)
+ systr_record_commit_mesg "$commit"
+ echo "Sending files..."
+ systr_rsync_normal . "$path/revs/$commit" "../$branchcommit"
+ systr_repo_finish_commit "$commit" "$branchcommit"
+ echo "$commit" >.systr/BASE
- if [ -f ".systr/author" ]; then
- cat .systr/author >"$path/$newcommit/.author.systr"
- else
- echo "Anonymous" >"$path/$newcommit/.author.systr"
- fi
-
- if [ -f ".systr/email" ]; then
- cat .systr/email >"$path/$newcommit/.email.systr"
- else
- echo "<anon>" >"$path/$newcommit/.email.systr"
- fi
-
- echo "$newcommit" >"$path/$branch"
- echo "$newcommit" >.systr/BASE
-
- if [[ "$TRAC" == "$BASE" ]]; then
- echo "$newcommit" >.systr/TRAC
- else
- echo "$branch" >.systr/TRAC
- fi
+ if [[ "$branch" != "$branchcommit" ]]; then
+ systr_repo_set_reference "$branch" "$commit"
+ fi
- # remote repository #
+ if [[ "$TRAC" == "$BASE" ]]; then
+ echo "$commit" >.systr/TRAC
else
- exit
-
+ echo "$branch" >.systr/TRAC
fi
}