@@ -209,14 +209,15 @@ setup() {
209209 local ref=` config_get ref`
210210 local fetch=` config_get fetch`
211211 local branch=${ref#*/ }
212+
212213 hook_pre_setup || abort pre-setup hook failed
213214 run " mkdir -p $path /{shared/{logs,pids},source}"
214215 test $? -eq 0 || abort setup paths failed
215216 log running setup
216217 log cloning $repo
217- if test fetch ! = " fast" ; then
218+ if test " $ fetch" ! = " fast" ; then
218219 log " full fetch"
219- run " git clone $repo $path /source"
220+ run " git clone --branch $branch $repo $path /source"
220221 else
221222 log " fast fetch"
222223 run " git clone --depth=5 --branch $branch $repo $path /source"
@@ -234,6 +235,10 @@ setup() {
234235
235236deploy () {
236237 local ref=$1
238+ local branch=$2
239+ if test -z " $branch " ; then
240+ branch=${ref#*/ }
241+ fi
237242 local path=` config_get path`
238243 local fetch=` config_get fetch`
239244
@@ -246,33 +251,29 @@ deploy() {
246251
247252 hook pre-deploy || abort pre-deploy hook failed
248253
249- # fetch source
250- log fetching updates
251-
252- if test fetch ! = " fast" ; then
253- log " full fetch"
254- run " cd $path /source && git fetch --all --tags"
254+ if run " cd $path /source && git rev-parse --quiet --verify $branch " > /dev/null; then
255+ log fast forward $branch
256+ run " cd $path /source && git checkout $branch && git pull origin $branch "
257+ test $? -eq 0 || abort git pull failed
255258 else
256- log " fast fetch"
257- run " cd $path /source && git fetch --depth=5 --all --tags"
258- fi
259+ # fetch source
260+ log fetching updates
259261
260- test $? -eq 0 || abort fetch failed
262+ if test " $fetch " ! = " fast" ; then
263+ log " full fetch"
264+ run " cd $path /source && git fetch --all --tags"
265+ else
266+ log " fast fetch"
267+ run " cd $path /source && git fetch --depth=5 --all --tags"
268+ fi
261269
262- # latest tag
263- if test -z " $ref " ; then
264- log fetching latest tag
265- ref=` run " cd $path /source && git for-each-ref refs/tags \
266- --sort=-*authordate \
267- --format='%(refname)' \
268- --count=1 | cut -d '/' -f 3" `
269- test $? -eq 0 || abort failed to determine latest tag
270- fi
270+ test $? -eq 0 || abort fetch failed
271271
272- # reset HEAD
273- log resetting HEAD to $ref
274- run " cd $path /source && git reset --hard $ref "
275- test $? -eq 0 || abort git reset failed
272+ # checkout ref to branch
273+ log checkout $ref to $branch
274+ run " cd $path /source && git checkout $ref -b $branch "
275+ test $? -eq 0 || abort git checkout failed
276+ fi
276277
277278 # link current
278279 run " ln -sfn $path /source $path /current"
@@ -384,11 +385,11 @@ while test $# -ne 0; do
384385 setup) setup $@ ; exit ;;
385386 list) list_deploys; exit ;;
386387 config) config $@ ; exit ;;
387- ref) REF=$1 ;;
388+ ref) REF=$1 ; BRANCH= $2 ;;
388389 esac
389390done
390391
391392check_for_local_changes
392393
393394# deploy
394- deploy " ${REF:- `config_get ref`} "
395+ deploy " ${REF:- `config_get ref`} " " ${BRANCH} "
0 commit comments