diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/gitsm.py')
| -rw-r--r-- | bitbake/lib/bb/fetch2/gitsm.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py new file mode 100644 index 0000000000..572b637c9a --- /dev/null +++ b/bitbake/lib/bb/fetch2/gitsm.py | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | """ | ||
| 4 | BitBake 'Fetch' git submodules implementation | ||
| 5 | """ | ||
| 6 | |||
| 7 | # Copyright (C) 2013 Richard Purdie | ||
| 8 | # | ||
| 9 | # This program is free software; you can redistribute it and/or modify | ||
| 10 | # it under the terms of the GNU General Public License version 2 as | ||
| 11 | # published by the Free Software Foundation. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License along | ||
| 19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 21 | |||
| 22 | import os | ||
| 23 | import bb | ||
| 24 | from bb import data | ||
| 25 | from bb.fetch2.git import Git | ||
| 26 | from bb.fetch2 import runfetchcmd | ||
| 27 | from bb.fetch2 import logger | ||
| 28 | |||
| 29 | class GitSM(Git): | ||
| 30 | def supports(self, url, ud, d): | ||
| 31 | """ | ||
| 32 | Check to see if a given url can be fetched with git. | ||
| 33 | """ | ||
| 34 | return ud.type in ['gitsm'] | ||
| 35 | |||
| 36 | def uses_submodules(self, ud, d): | ||
| 37 | for name in ud.names: | ||
| 38 | try: | ||
| 39 | runfetchcmd("%s show %s:.gitmodules" % (ud.basecmd, ud.revisions[name]), d, quiet=True) | ||
| 40 | return True | ||
| 41 | except bb.fetch.FetchError: | ||
| 42 | pass | ||
| 43 | return False | ||
| 44 | |||
| 45 | def update_submodules(self, u, ud, d): | ||
| 46 | # We have to convert bare -> full repo, do the submodule bit, then convert back | ||
| 47 | tmpclonedir = ud.clonedir + ".tmp" | ||
| 48 | gitdir = tmpclonedir + os.sep + ".git" | ||
| 49 | bb.utils.remove(tmpclonedir, True) | ||
| 50 | os.mkdir(tmpclonedir) | ||
| 51 | os.rename(ud.clonedir, gitdir) | ||
| 52 | runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*true/bare = false/'", d) | ||
| 53 | os.chdir(tmpclonedir) | ||
| 54 | runfetchcmd("git reset --hard", d) | ||
| 55 | runfetchcmd("git submodule init", d) | ||
| 56 | runfetchcmd("git submodule update", d) | ||
| 57 | runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*false/bare = true/'", d) | ||
| 58 | os.rename(gitdir, ud.clonedir,) | ||
| 59 | bb.utils.remove(tmpclonedir, True) | ||
| 60 | |||
| 61 | def download(self, loc, ud, d): | ||
| 62 | Git.download(self, loc, ud, d) | ||
| 63 | |||
| 64 | os.chdir(ud.clonedir) | ||
| 65 | submodules = self.uses_submodules(ud, d) | ||
| 66 | if submodules: | ||
| 67 | self.update_submodules(loc, ud, d) | ||
| 68 | |||
| 69 | def unpack(self, ud, destdir, d): | ||
| 70 | Git.unpack(self, ud, destdir, d) | ||
| 71 | |||
| 72 | os.chdir(ud.destdir) | ||
| 73 | submodules = self.uses_submodules(ud, d) | ||
| 74 | if submodules: | ||
| 75 | runfetchcmd("cp -r " + ud.clonedir + "/modules " + ud.destdir + "/.git/", d) | ||
| 76 | runfetchcmd("git submodule init", d) | ||
| 77 | runfetchcmd("git submodule update", d) | ||
| 78 | |||
