diff options
author | Malf Furious <m@lfurio.us> | 2017-04-30 01:29:03 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2017-04-30 01:29:03 -0400 |
commit | 9900821d6b8c704bb8f8399d1a343aa5d780abf7 (patch) | |
tree | a824256ea485fc5a29aa094d81e717d120c7ba42 /commit.sh | |
parent | d919e18488c196caf7a8ea7a8db9bd7dc75995d0 (diff) | |
download | systrunk-9900821d6b8c704bb8f8399d1a343aa5d780abf7.tar.gz systrunk-9900821d6b8c704bb8f8399d1a343aa5d780abf7.zip |
Add commit module
Diffstat (limited to 'commit.sh')
-rw-r--r-- | commit.sh | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/commit.sh b/commit.sh new file mode 100644 index 0000000..096631a --- /dev/null +++ b/commit.sh @@ -0,0 +1,89 @@ +## +# creat_commit_dir_local +# +# Create new commit directory, and assign its commit ID. Commit ID is +# printed to stdout. +## +function creat_commit_dir_local +{ + cd "$path" + mktemp -d XXXXXXXX +} + +## +# 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 +{ + read remote <.systr/remote + read path <.systr/path + read BASE <.systr/BASE + read TRAC <.systr/TRAC + + if [ $# -gt 1 ]; then + branch=$2 + else + branch="$TRAC" + fi + + branchcommit=$(get_commit "$branch") || branchcommit="$BASE" + + if [[ "$BASE" != "$branchcommit" ]]; then + echo "Worktree is out-of-date, won't commit" + exit + 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" + + 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 + + # remote repository # + else + exit + + fi +} |