2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 BitBake 'Fetch' git implementation
7 Copyright (C) 2005 Richard Purdie
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place, Suite 330, Boston, MA 02111-1307 USA.
26 from bb.fetch import Fetch
27 from bb.fetch import FetchError
30 # Delete everything reachable from the directory named in 'topdir'.
31 # CAUTION: This is dangerous!
32 for root, dirs, files in os.walk(topdir, topdown=False):
34 os.remove(os.path.join(root, name))
36 os.rmdir(os.path.join(root, name))
40 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % cmd)
42 # Need to export PATH as git is likely to be in metadata paths
43 # rather than host provided
44 pathcmd = 'export PATH=%s; %s' % (data.expand('${PATH}', d), cmd)
46 myret = os.system(pathcmd)
49 raise FetchError("Git: %s failed" % pathcmd)
52 """Class to fetch a module or modules from git repositories"""
53 def supports(self, url, ud, d):
55 Check to see if a given url can be fetched with cvs.
57 return ud.type in ['git']
59 def localpath(self, url, ud, d):
62 if 'protocol' in ud.parm:
63 ud.proto = ud.parm['protocol']
67 ud.tag = ud.parm['tag']
69 ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.tag), d)
71 return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
73 def go(self, loc, ud, d):
76 gitsrcname = '%s%s' % (ud.host, path.replace('/', '.'))
78 repofilename = 'git_%s.tar.gz' % (gitsrcname)
79 repofile = os.path.join(data.getVar("DL_DIR", d, 1), repofilename)
80 repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname)
82 coname = '%s' % (ud.tag)
83 codir = os.path.join(repodir, coname)
87 # tag=="master" must always update
88 if (ud.tag != "master") and Fetch.try_mirror(d, ud.localfile):
89 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % cofile)
92 if not os.path.exists(repodir):
93 if Fetch.try_mirror(d, repofilename):
96 rungitcmd("tar -xzf %s" % (repofile),d)
98 rungitcmd("git clone -n %s://%s%s %s" % (ud.proto, ud.host, ud.path, repodir),d)
101 rungitcmd("git pull %s://%s%s" % (ud.proto, ud.host, ud.path),d)
102 rungitcmd("git pull --tags %s://%s%s" % (ud.proto, ud.host, ud.path),d)
103 rungitcmd("git prune-packed", d)
104 rungitcmd("git pack-redundant --all | xargs -r rm", d)
105 # Remove all but the .git directory
106 rungitcmd("rm * -Rf", d)
107 # old method of downloading tags
108 #rungitcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (ud.host, ud.path, os.path.join(repodir, ".git", "")),d)
111 bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git repository")
112 rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d)
114 if os.path.exists(codir):
119 rungitcmd("git read-tree %s" % (ud.tag),d)
120 rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d)
123 bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout")
124 rungitcmd("tar -czf %s %s" % (cofile, os.path.join(".", "*") ),d)