From 0e60a1538e05d331d2f544ca63c6f7cb318824de Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 25 May 2012 15:26:25 +0100 Subject: archive command --- git-pull-request.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/git-pull-request.sh b/git-pull-request.sh index f394230..6531e11 100755 --- a/git-pull-request.sh +++ b/git-pull-request.sh @@ -733,6 +733,47 @@ EOF rm -f "${PR_INDEX_FILE}" } +cmd_archive () { + local PR + PR="$1" + if test "x$PR" = "x"; then + echo >&2 "Please specify a pull-request name to archive." + 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 + + if sane_grep -q -F /archive/ <<<"${BRANCH}"; then + echo >&2 "Pull request '${PR}' is already archived" + exit 1 + fi + + load_meta_from "${COMMIT}" + case "${METADATA[STATE]}" in + merged|rejected) + ;; + *) + echo >&2 "Pull request '${PR}' is not merged or rejected" + exit 1 + ;; + esac + + rgit update-ref -m "Archive '${PR}'" \ + "refs/pull-requests/archive/${PR}__meta" "${COMMIT}" + rgit update-ref -m "Archive '${PR}'" -d \ + "refs/pull-requests/heads/${PR}__meta" + rgit update-ref -m "Archive '${PR}'" -d \ + "refs/pull-requests/heads/${PR}__anchor" + exit 0 +} + ############################################################################# ## Command invocation ##################################################### ############################################################################# -- cgit v1.2.1