File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -187,22 +187,29 @@ dir="$2"
187187# Try using "humanish" part of source repo if user didn't specify one
188188[ -z " $dir " ] && dir=$( echo " $repo " | sed -e ' s|/$||' -e ' s|:*/*\.git$||' -e ' s|.*[/:]||g' )
189189[ -e " $dir " ] && die " destination directory '$dir ' already exists."
190+ [ yes = " $bare " ] && unset GIT_WORK_TREE
191+ [ -n " $GIT_WORK_TREE " ] && [ -e " $GIT_WORK_TREE " ] &&
192+ die " working tree '$GIT_WORK_TREE ' already exists."
190193D=
194+ W=
191195cleanup () {
192196 err=$?
193197 test -z " $D " && rm -rf " $dir "
198+ test -z " $W " && test -n " $GIT_WORK_TREE " && rm -rf " $GIT_WORK_TREE "
194199 cd ..
195200 test -n " $D " && rm -rf " $D "
201+ test -n " $W " && rm -rf " $W "
196202 exit $err
197203}
198204trap cleanup 0
199205mkdir -p " $dir " && D=$( cd " $dir " && pwd) || usage
200- case " $bare " in
201- yes)
202- GIT_DIR=" $D " ;;
203- * )
204- GIT_DIR=" $D /.git" ;;
205- esac &&
206+ test -n " $GIT_WORK_TREE " && mkdir -p " $GIT_WORK_TREE " &&
207+ W=$( cd " $GIT_WORK_TREE " && pwd) && export GIT_WORK_TREE=" $W "
208+ if test yes = " $bare " || test -n " $GIT_WORK_TREE " ; then
209+ GIT_DIR=" $D "
210+ else
211+ GIT_DIR=" $D /.git"
212+ fi &&
206213export GIT_DIR &&
207214git-init $quiet ${template+" $template " } || usage
208215
@@ -358,7 +365,11 @@ then
358365 done < " $GIT_DIR /CLONE_HEAD"
359366fi
360367
361- cd " $D " || exit
368+ if test -n " $W " ; then
369+ cd " $W " || exit
370+ else
371+ cd " $D " || exit
372+ fi
362373
363374if test -z " $bare " && test -f " $GIT_DIR /REMOTE_HEAD"
364375then
You can’t perform that action at this time.
0 commit comments