Browse Source

Add --no-verify to bypass pre-ftp-push hook

And if the pre-ftp-push hook fails, we now exit with status 9.

We also don't test the hook's executable bit since that test fails in
msysgit.
support-git-dir
Maikel Linke 9 years ago
parent
commit
ebd262012f
  1. 13
      git-ftp
  2. 32
      man/git-ftp.1.md
  3. 13
      tests/git-ftp-test.sh

13
git-ftp

@ -73,6 +73,7 @@ declare -i FORCE=0
declare -i ENABLE_REMOTE_LCK=0
declare -i ACTIVE_MODE=0
declare -i USE_KEYCHAIN=0
declare -i EXECUTE_HOOKS=1
declare -a GIT_SUBMODULES
# ------------------------------------------------------------
@ -85,6 +86,7 @@ readonly ERROR_DOWNLOAD=5
readonly ERROR_UNKNOWN_PROTOCOL=6
readonly ERROR_REMOTE_LOCKED=7
readonly ERROR_GIT=8
readonly ERROR_HOOK=9
# ------------------------------------------------------------
# Functions
@ -175,6 +177,7 @@ OPTIONS
--insecure Don't verify server's certificate.
--cacert Specify a <file> as CA certificate store. Useful when a server has got a self-signed certificate.
--no-commit Perform the merge at the and of pull but do not autocommit, to have the chance to inspect and further tweak the merge result before committing.
--no-verify Bypass the pre-ftp-push hook.
--disable-epsv Tell curl to disable the use of the EPSV command when doing passive FTP transfers. Curl will normally always first attempt to use EPSV before PASV, but with this option, it will not try using EPSV.
--version Prints version.
@ -468,16 +471,16 @@ upload_local_sha1() {
pre_push_hook() {
hook='.git/hooks/pre-ftp-push'
if [ -x "$hook" ]; then
if [ "$EXECUTE_HOOKS" -eq 1 -a -e "$hook" ]; then
scope="${SCOPE:-$REMOTE_HOST}"
write_log "Trigger pre-ftp-push hook with: $scope, $REMOTE_URL, $LOCAL_SHA1, $DEPLOYED_SHA1"
print_status | $hook "$scope" "$REMOTE_URL" "$LOCAL_SHA1" "$DEPLOYED_SHA1"
print_status | $hook "$scope" "$REMOTE_URL" "$LOCAL_SHA1" "$DEPLOYED_SHA1" || exit "$ERROR_HOOK"
fi
}
post_push_hook() {
hook='.git/hooks/post-ftp-push'
if [ -x "$hook" ]; then
if [ -e "$hook" ]; then
scope="${SCOPE:-$REMOTE_HOST}"
write_log "Trigger post-ftp-push hook with: $scope, $REMOTE_URL, $LOCAL_SHA1, $DEPLOYED_SHA1"
$hook "$scope" "$REMOTE_URL" "$LOCAL_SHA1" "$DEPLOYED_SHA1"
@ -1530,6 +1533,10 @@ do
REMOTE_ROOT="$2"
shift
;;
--no-verify)
EXECUTE_HOOKS=0
shift
;;
*)
# Pass thru anything that may be meant for fetch.
[ -n "$1" ] && URL=$1

32
man/git-ftp.1.md

@ -142,6 +142,9 @@ different and handles only those files. That saves time and bandwidth.
`--no-commit`
: Stop while merging downloaded changes during the pull action.
`--no-verify`
: Bypass the pre-ftp-push hook. See **HOOKS** section.
`--version`
: Prints version.
@ -355,10 +358,26 @@ The commit id will be printed so that you can tag it or create a new branch.
Git-ftp supports client-side hook scripts during the init and the push action.
`pre-ftp-push` is called just before the upload to the server starts, but after
the changeset of files was generated. It is fed with all filenames to sync
through standard input. This list is different to git diff, because
the changeset of files was generated. It can be bypassed with the --no-verify
option.
The hook is called with four parameters.
The first is the used scope or the host name if no scope is used.
The second parameter is the destination URL.
The third is the local commit id which is going to be uploaded and
the fourth is the remote commit id on the server which is going to be updated.
The standard input is a list of all filenames to sync. Each file is preceeded
by A or D followed by a space. A means that this file is scheduled for upload,
D means it's scheduled for deletion. All entries are separated by the NUL byte.
This list is different to git diff, because
it has been changed by the rules of the `.git-ftp-include` file and the
`.git-ftp-ignore` file. An example is:
`.git-ftp-ignore` file.
Exiting with non-zero status from this script causes
Git-ftp to abort and exit with status 9.
An example script is:
```bash
#!/bin/bash
@ -407,7 +426,9 @@ exit 0
`post-ftp-push` is called after the transfer has been finished. The standard
input is empty, but the parameters are the same as given to the `pre-ftp-push`
hook.
hook. This hook is **not** bypassed by the --no-verify option.
It is meant primarily for notification and its exit status does not have any
effect.
# NETRC
@ -450,6 +471,9 @@ At the time of this writing, the exit codes are:
`8`
: Not a Git project
`9`
: The `pre-ftp-push` hook failed
# KNOWN ISSUES & BUGS
The upstream BTS can be found at <https://github.com/git-ftp/git-ftp/issues>.

13
tests/git-ftp-test.sh

@ -930,6 +930,19 @@ test_pre_push() {
lastline="$(echo "$out" | tail -n 1)"
assertEquals "A - test 1.txt" "$firstline"
assertEquals "D - test 2.txt" "$lastline"
# push fail
echo 'new content' >> 'test 1.txt'
git commit -a -m 'new content' -q
echo 'exit 1' > "$hook"
out="$($GIT_FTP push -n)"
assertEquals 9 "$?"
assertEquals "" "$out"
# ignore hook
out="$($GIT_FTP push -n --no-verify)"
assertEquals 0 "$?"
assertEquals "" "$out"
}
test_post_push() {

Loading…
Cancel
Save