{"thread":{"id":"950","subject":"[PATCH 2/3] Reorganization of git-commit-script [rev 4]","startedAt":"2005-06-15T14:38:11Z","lastAt":"2005-06-15T14:38:11Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"4974","messageId":"20050615143811.27248.qmail@blackcubes.dyndns.org","threadId":"950","inReplyTo":null,"subject":"[PATCH 2/3] Reorganization of git-commit-script [rev 4]","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-06-15T14:38:11Z","receivedAt":"2005-06-15T14:38:11Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nThis change re-organizes git-commit-script to break out\nthe different phases of execution into separate bash\nfunctions.\n\nThe main body is now:\n\nif ! print_status > .editmsg; then\n\t# error handling\nfi\n\nif edit_message .editmsg .cmitmsg; then\n\texec_commit .cmitmsg\n\t# cleanup\nfi\n\nThe subsequent patch in this series adds support for\nan optional .nextmsg file to enable the pre-population\nof commit message text by external tools.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n\n git-commit-script |  110 ++++++++++++++++++++++++++++++++++++-----------------\n 1 files changed, 75 insertions(+), 35 deletions(-)\n\ndiff --git a/git-commit-script b/git-commit-script\n--- a/git-commit-script\n+++ b/git-commit-script\n@@ -1,44 +1,84 @@\n #!/bin/sh\n+\n+initial_commit() {\n+cat <<EOF\n+#\n+# Initial commit:\n+# \n+$(git-ls-files | sed \"s/^/# New file: /\")\n+#\n+EOF\n+}\n+\n+merge_commit() {\n+cat <<EOF\n+#\n+# It looks like your may be committing a MERGE.\n+# If this is not correct, please remove the file\n+# $GIT_DIR/MERGE_HEAD\n+# and try again\n+#\n+EOF\n+}\n+\n+print_status() {\n+\tif [ ! -r $GIT_DIR/HEAD ]; then\n+\t\tif [ -z \"$(git-ls-files)\" ]; then\n+\t\t\techo Nothing to commit 1>&2\n+\t\t\treturn 1\n+\t\tfi\n+\t\tinitial_commit \n+\telse\n+\t\tif [ -f $GIT_DIR/MERGE_HEAD ]; then\n+\t\t\tmerge_commit\n+\t\tfi\n+\t\tgit-status-script\n+\tfi\n+}\n+\n+edit_message() {\n+\tstatus=$1\n+\tmsg=$2\n+\n+\t:> $msg\n+\t${VISUAL:-${EDITOR:-vi}} \"$status\"\n+\tgrep -v '^#' < $status | git-stripspace >$msg\n+\t[ -s $msg ] || exit 1\n+}\n+\n+commit_parents() {\n+\t[ -f $GIT_DIR/HEAD ] &&\n+\techo -n \"-p HEAD\" &&\n+\t[ -f $GIT_DIR/MERGE_HEAD ] &&\n+\techo -n \" -p MERGE_HEAD\"\n+\techo \"\"\n+}\n+\n+exec_commit() {\n+\tmsg=$1\n+\ttree=$(git-write-tree) || exit 1\n+\tparents=$(commit_parents) || exit 1\n+\tcommit=$(cat $msg | git-commit-tree $tree $parents) || exit 1\n+\techo $commit > $GIT_DIR/HEAD\n+\trm -f -- $GIT_DIR/MERGE_HEAD\n+}\n+\n+SENTINEL=\"#SENTINEL - delete this line to confirm the commit\"\n : ${GIT_DIR=.git}\n if [ ! -d $GIT_DIR ]; then\n \techo Not a git directory 1>&2\n \texit 1\n fi\n-PARENTS=\"-p HEAD\"\n-if [ ! -r $GIT_DIR/HEAD ]; then\n-\tif [ -z \"$(git-ls-files)\" ]; then\n-\t\techo Nothing to commit 1>&2\n-\t\texit 1\n-\tfi\n-\t(\n-\t\techo \"#\"\n-\t\techo \"# Initial commit\"\n-\t\techo \"#\"\n-\t\tgit-ls-files | sed 's/^/# New file: /'\n-\t\techo \"#\"\n-\t) > .editmsg\n-\tPARENTS=\"\"\n-else\n-\tif [ -f $GIT_DIR/MERGE_HEAD ]; then\n-\t\techo \"#\"\n-\t\techo \"# It looks like your may be committing a MERGE.\"\n-\t\techo \"# If this is not correct, please remove the file\"\n-\t\techo \"#\t$GIT_DIR/MERGE_HEAD\"\n-\t\techo \"# and try again\"\n-\t\techo \"#\"\n-\t\tPARENTS=\"-p HEAD -p MERGE_HEAD\"\n-\tfi > .editmsg\n-\tgit-status-script >> .editmsg\n-fi\n-if [ \"$?\" != \"0\" ]\n-then\n+\n+if ! print_status > .editmsg; then\n \tcat .editmsg\n+\trm .editmsg\n \texit 1\n fi\n-${VISUAL:-${EDITOR:-vi}} .editmsg\n-grep -v '^#' < .editmsg | git-stripspace > .cmitmsg\n-[ -s .cmitmsg ] || exit 1\n-tree=$(git-write-tree) || exit 1\n-commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) || exit 1\n-echo $commit > $GIT_DIR/HEAD\n-rm -f -- $GIT_DIR/MERGE_HEAD\n+\n+if edit_message .editmsg .cmitmsg; then\n+\texec_commit .cmitmsg\n+\t[ -f .editmsg ] && rm .editmsg\n+\t[ -f .cmitmsg ] && rm .cmitmsg\n+\texit 0\n+fi\n------------\n"}]}