summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-05-25 14:24:21 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-05-25 14:24:21 +0100
commit9ab6fc84d1bf0f90a8cbd3d0d8accb93a171b23b (patch)
tree6c0ddff5529c59d418e356e052b21592e9671a70
parentb6d915a56ceefc952b81c5bafa2bdf2223f31f20 (diff)
downloadgit-pull-request-9ab6fc84d1bf0f90a8cbd3d0d8accb93a171b23b.tar.bz2
Lots of marking functions
-rwxr-xr-xgit-pull-request.sh173
1 files changed, 171 insertions, 2 deletions
diff --git a/git-pull-request.sh b/git-pull-request.sh
index 0720571..f394230 100755
--- a/git-pull-request.sh
+++ b/git-pull-request.sh
@@ -12,8 +12,10 @@ list List pull requests along with their status
precis Show the precis from a given pull-request's creation
create Create a new pull request
merge Merge a given pull request into your current branch
-needs-work Indicate a pull request needs additional work before merging
-reject Reject a pull request
+needs-work Mark a pull request as needing additional work before merging
+merged Mark a pull request as merged
+reject Mark a pull request as rejected
+update Mark a pull request as updated, updating the anchors etc also.
archive Archive a pull request
File attachment sub-commands are:
@@ -67,6 +69,8 @@ if test "x$SUBCMD" = "x"; then
SUBCMD="list"
fi
+SUBCMD=$(echo "${SUBCMD}" | tr 'A-Z' 'a-z' | sed -e's/[^a-z]/_/g')
+
#############################################################################
## Utility functions ######################################################
#############################################################################
@@ -564,6 +568,171 @@ cmd_extract () {
fi
}
+_cmd_mark () {
+ local PR MARKAS
+ PR="$1"
+ MARKAS="$2"
+ if test "x$PR" = "x"; then
+ echo >&2 "Please specify a pull-request name to mark as '${MARKAS}'."
+ exit 1
+ fi
+ local COMMIT BRANCH
+ while read _COMMIT _BRANCH; do
+ COMMIT="${_COMMIT}"
+ BRANCH="${_BRANCH}"
+ done <<<$(rgit show-ref "$PR"__meta)
+ if test "x$COMMIT" = "x"; then
+ echo >&2 "Pull request '${PR}' not found."
+ exit 1
+ fi
+
+ load_meta_from "${COMMIT}"
+ load_index_from "${COMMIT}"
+
+ # Concoct a commit message
+ cat > "${PR_EDIT_MSG}" <<EOF
+
+# This message will become the reasoning for marking this pull-request as
+# ${MARKAS}. If you do not want to attach the file to the pull request, you
+# should quit the editor without saving the file.
+#
+# Any line starting with a hash mark will be removed before the attachment
+# is committed to the repository.
+#
+# The first line of your message will be used as the title and the remainder
+# will be the body of the reasoning. The entire message will be used as the
+# commit message on the pull request.
+#
+# This pull request is called: ${PR}
+#
+EOF
+ local PRESUM POSTSUM
+ PRESUM=$(rgit hash-object -t blob "${PR_EDIT_MSG}")
+ git_editor "${PR_EDIT_MSG}"
+ POSTSUM=$(rgit hash-object -t blob "${PR_EDIT_MSG}")
+ # (if unchanged, clean up and quit)
+ if test "x$PRESUM" = "x$POSTSUM"; then
+ echo >&2 "Message unchanged, aborting marking pull request '${MARKAS}'"
+ rm -f "${PR_EDIT_MSG}"
+ exit 1
+ fi
+ local MSHA
+ METADATA[STATE]="${MARKAS}"
+ MSHA=$(inject_metadata_file)
+
+ GIT_INDEX_FILE="${PR_INDEX_FILE}" rgit update-index \
+ --cacheinfo "100644" "${MSHA}" "pull-request.meta"
+ local TSHA
+ TSHA=$(GIT_INDEX_FILE="${PR_INDEX_FILE}" rgit write-tree)
+ local CSHA
+ CSHA=$(sed -e'/^#/d' < "${PR_EDIT_MSG}" | \
+ rgit commit-tree "${TSHA}" -p "${METADATA[META_SHA]}")
+ rgit update-ref -m "Updated state of '${PR}' to '${MARKAS}'" \
+ "${BRANCH}" "${CSHA}" "${METADATA[META_SHA]}"
+ say "'${PR}' marked '${MARKAS}'"
+ rm -f "${PR_EDIT_MSG}"
+ rm -f "${PR_INDEX_FILE}"
+}
+
+cmd_needs_work () {
+ _cmd_mark "$1" "needs-work"
+}
+
+cmd_reject () {
+ _cmd_mark "$1" "rejected"
+}
+
+cmd_merged () {
+ _cmd_mark "$1" "merged"
+}
+
+cmd_update () {
+ local PR
+ PR="$1"
+ if test "x$PR" = "x"; then
+ echo >&2 "Please specify a pull-request name to update."
+ exit 1
+ fi
+ local COMMIT BRANCH
+ while read _COMMIT _BRANCH; do
+ COMMIT="${_COMMIT}"
+ BRANCH="${_BRANCH}"
+ done <<<$(rgit show-ref "$PR"__meta)
+ if test "x$COMMIT" = "x"; then
+ echo >&2 "Pull request '${PR}' not found."
+ exit 1
+ fi
+
+ load_meta_from "${COMMIT}"
+ load_index_from "${COMMIT}"
+
+ require_clean_work_tree
+
+ # Determine new SHA
+ local NEWCOMMIT
+ NEWCOMMIT=$(rgit for-each-ref --format="%(objectname)" \
+ $(rgit symbolic-ref HEAD))
+
+ if test "x${METADATA[COMMIT]}" = "x${NEWCOMMIT}"; then
+ echo >&2 "You haven't changed anything, cannot update pull request"
+ exit 1
+ fi
+
+ # Concoct a commit message
+ cat > "${PR_EDIT_MSG}" <<EOF
+
+# This message will become the reasoning for marking this pull-request as
+# updated. If you do not want to attach the file to the pull request, you
+# should quit the editor without saving the file.
+#
+# Any line starting with a hash mark will be removed before the attachment
+# is committed to the repository.
+#
+# The first line of your message will be used as the title and the remainder
+# will be the body of the reasoning. The entire message will be used as the
+# commit message on the pull request.
+#
+# This pull request is called: ${PR}
+# It was for ${METADATA[COMMIT]}
+# It will now be for ${NEWCOMMIT}
+#
+# The following is the diffstat between the two:
+EOF
+ local OLDCOMMIT
+ OLDCOMMIT="${METADATA[COMMIT]}"
+ METADATA[COMMIT]="${NEWCOMMIT}"
+ METADATA[STATE]="updated"
+ rgit diff --stat "${OLDCOMMIT}" "${NEWCOMMIT}" | \
+ sed -e's/^/# /' >> "${PR_EDIT_MSG}"
+ local PRESUM POSTSUM
+ PRESUM=$(rgit hash-object -t blob "${PR_EDIT_MSG}")
+ git_editor "${PR_EDIT_MSG}"
+ POSTSUM=$(rgit hash-object -t blob "${PR_EDIT_MSG}")
+ # (if unchanged, clean up and quit)
+ if test "x$PRESUM" = "x$POSTSUM"; then
+ echo >&2 "Message unchanged, aborting marking pull request '${MARKAS}'"
+ rm -f "${PR_EDIT_MSG}"
+ exit 1
+ fi
+ local MSHA
+ MSHA=$(inject_metadata_file)
+
+ GIT_INDEX_FILE="${PR_INDEX_FILE}" rgit update-index \
+ --cacheinfo "100644" "${MSHA}" "pull-request.meta"
+ local TSHA
+ TSHA=$(GIT_INDEX_FILE="${PR_INDEX_FILE}" rgit write-tree)
+ local CSHA
+ CSHA=$(sed -e'/^#/d' < "${PR_EDIT_MSG}" | \
+ rgit commit-tree "${TSHA}" -p "${METADATA[META_SHA]}")
+ rgit update-ref -m "Updated '${PR}' to '${NEWCOMMIT}'" \
+ "${BRANCH}" "${CSHA}" "${METADATA[META_SHA]}"
+ rgit update-ref -m "Copying anchor for pull-request ${PR}" \
+ "refs/pull-requests/heads/${PR}__anchor" "${NEWCOMMIT}" "${OLDCOMMIT}"
+ say "'${PR}' updated"
+ rm -f "${PR_EDIT_MSG}"
+ rm -f "${PR_INDEX_FILE}"
+}
+
#############################################################################
## Command invocation #####################################################
#############################################################################