summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-05-25 13:37:33 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-05-25 13:37:33 +0100
commitb6d915a56ceefc952b81c5bafa2bdf2223f31f20 (patch)
treebfa3e7f304c4c061965b609169ca08a8a453590a
parentd1ceb7623b3d382187269e8c3a7d22a5ef0ca7e3 (diff)
downloadgit-pull-request-b6d915a56ceefc952b81c5bafa2bdf2223f31f20.tar.bz2
extracting attachments
-rwxr-xr-xgit-pull-request.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/git-pull-request.sh b/git-pull-request.sh
index 989213a..0720571 100755
--- a/git-pull-request.sh
+++ b/git-pull-request.sh
@@ -20,6 +20,7 @@ File attachment sub-commands are:
attach Attach a file to a pull request
ls List files attached to a pull request
+extract Extract an attached file from a pull request
--
General Options
@@ -514,6 +515,55 @@ cmd_ls () {
rm -f "${PR_INDEX_FILE}"
}
+cmd_extract () {
+ local PR ATT AS
+ PR="$1"
+ ATT="$2"
+ AS="$3"
+
+ if test "x$PR" = "x"; then
+ echo >&2 "Please specify a pull-request name to list attachments of."
+ 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}"
+
+ if ! meta_file_exists "attached/$ATT"; then
+ echo >&2 "Unable to find attachment '${ATT}'"
+ exit 1
+ fi
+
+ if test "x${AS}" = "x"; then
+ AS=$(basename "${ATT}")
+ fi
+
+ if test "x${AS}" = "x-"; then
+ git cat-file -p "${METADATA[META_SHA]}:attached/${ATT}"
+ else
+ if test -d "${AS}"; then
+ AS="${AS}/"$(basename "${ATT}")
+ fi
+
+ if test -e "${AS}"; then
+ if test "x$OVERWRITE_ATTACH" = "x"; then
+ echo >&2 "Unable to extract '${ATT}', '${AS}' already exists"
+ fi
+ fi
+ say "Extracting '${ATT}' as '${AS}'"
+ git cat-file -p "${METADATA[META_SHA]}:attached/${ATT}" > "${AS}"
+ fi
+}
+
#############################################################################
## Command invocation #####################################################
#############################################################################