/var/lib/sorcery/modules/dl_handlers/dl_git
1 #!/bin/bash
2 #---------------------------------------------------------------------
3 ##
4 ##=head1 COPYRIGHT
5 ##
6 ## Copyright 2004 by the Source Mage Team
7 ##
8 ##=head1 FUNCTIONS
9 ##
10 ##=over 4
11 ##
12 #---------------------------------------------------------------------
13
14
15 #---------------------------------------------------------------------
16 ##=item dl_get_git <url>
17 ##
18 ## Fetch the specified git url.
19 ##
20 ## This handler only supports tree downloads.
21 ##
22 #---------------------------------------------------------------------
23 function dl_git_get() {
24 dl_command_check git || return 254
25
26 local target=$1
27 local url_list=$2
28 local hints=$3
29 local dl_target=$4
30 local dl_type=$5
31 local url rc=0
32
33 [[ $target ]] &&
34 dl_connect || return 255
35
36 for url in $url_list; do
37 local URL GIT_ROOT GIT_DIRECTORY GIT_TAG
38 url_crack "$url" "$hints"
39 if [[ -z $GIT_DIRECTORY ]]
40 then
41 GIT_DIRECTORY=${target/.git/}
42 fi
43 if test -d $GIT_DIRECTORY; then
44 message "${MESSAGE_COLOR}Running git pull...${DEFAULT_COLOR}"
45 ( cd $GIT_DIRECTORY &&
46 match=$(git branch | grep -F " $GIT_TAG"; true) &&
47 if [[ $match ]]; then
48 # no need to checkout a branch if we're already on it
49 if [[ ${match:0:1} != '*' ]]; then
50 echo git checkout $GIT_TAG &&
51 git checkout $GIT_TAG
52 else
53 : # already on the correct branch
54 fi
55 else
56 echo git checkout -b $GIT_TAG origin/$GIT_TAG &&
57 git checkout -b $GIT_TAG origin/$GIT_TAG
58 fi
59 echo git pull &&
60 git pull )
61 rc=$?
62 eval "$dl_target=\"$GIT_DIRECTORY\""
63 else
64 message "${MESSAGE_COLOR}Running git clone...${DEFAULT_COLOR}"
65 echo git clone $GIT_ROOT $GIT_DIRECTORY
66 git clone $GIT_ROOT $GIT_DIRECTORY &&
67 cd $GIT_DIRECTORY &&
68 if ! git branch | grep -qF " $GIT_TAG"; then
69 echo git checkout -b $GIT_TAG origin/$GIT_TAG &&
70 git checkout -b $GIT_TAG origin/$GIT_TAG
71 fi
72 rc=$?
73 cd ../
74 eval "$dl_target=\"$GIT_DIRECTORY\""
75 fi
76 [[ $rc == 0 ]] && break
77 done
78 dl_disconnect
79
80 eval "$dl_type=\"tree\""
81 return $rc
82 }
83
84 #---------------------------------------------------------------------
85 ##=back
86 ##
87 ##=head1 LICENSE
88 ##
89 ## This software is free software; you can redistribute it and/or modify
90 ## it under the terms of the GNU General Public License as published by
91 ## the Free Software Foundation; either version 2 of the License, or
92 ## (at your option) any later version.
93 ##
94 ## This software is distributed in the hope that it will be useful,
95 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
96 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97 ## GNU General Public License for more details.
98 ##
99 ## You should have received a copy of the GNU General Public License
100 ## along with this software; if not, write to the Free Software
101 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
102 ##
103 #---------------------------------------------------------------------