summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/gitsm.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2014-02-24 18:50:02 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-02-28 14:50:43 +0000
commit957c9a80bc698845475591912c8cb6ae42077d19 (patch)
tree67db87e55fa978f39e95b6e2cd949dfb2480c325 /bitbake/lib/bb/fetch2/gitsm.py
parent519f0a58df2aca5264cdc409533d2d4e3ecc154c (diff)
downloadpoky-957c9a80bc698845475591912c8cb6ae42077d19.tar.gz
bitbake: fetch2: fix fetching git submodules with git 1.7.9.x or older
Git versions older than 1.7.10 put absolute paths in configuration files for the submodule repositories, leading to errors when the repository checkout is moved. We move the repository as a matter of course in the gitsm fetcher; the failure occurs in do_unpack). Change the absolute paths to be relative during processing to fix this. (At the time of writing, Ubuntu 12.04.4 LTS ships Git version 1.7.9.5, hence the desire to fix this rather than just mandating a newer Git version.) Fixes [YOCTO #5525]. (Bitbake rev: e700d5a41deed4ee837465af526ed30c8a579933) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/gitsm.py')
-rw-r--r--bitbake/lib/bb/fetch2/gitsm.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py
index 9fdde468cb..1a762153c4 100644
--- a/bitbake/lib/bb/fetch2/gitsm.py
+++ b/bitbake/lib/bb/fetch2/gitsm.py
@@ -42,6 +42,53 @@ class GitSM(Git):
42 pass 42 pass
43 return False 43 return False
44 44
45 def _set_relative_paths(self, repopath):
46 """
47 Fix submodule paths to be relative instead of absolute,
48 so that when we move the repo it doesn't break
49 (In Git 1.7.10+ this is done automatically)
50 """
51 submodules = []
52 with open(os.path.join(repopath, '.gitmodules'), 'r') as f:
53 for line in f.readlines():
54 if line.startswith('[submodule'):
55 submodules.append(line.split('"')[1])
56
57 for module in submodules:
58 repo_conf = os.path.join(repopath, module, '.git')
59 if os.path.exists(repo_conf):
60 with open(repo_conf, 'r') as f:
61 lines = f.readlines()
62 newpath = ''
63 for i, line in enumerate(lines):
64 if line.startswith('gitdir:'):
65 oldpath = line.split(': ')[-1].rstrip()
66 if oldpath.startswith('/'):
67 newpath = '../' * (module.count('/') + 1) + '.git/modules/' + module
68 lines[i] = 'gitdir: %s\n' % newpath
69 break
70 if newpath:
71 with open(repo_conf, 'w') as f:
72 for line in lines:
73 f.write(line)
74
75 repo_conf2 = os.path.join(repopath, '.git', 'modules', module, 'config')
76 if os.path.exists(repo_conf2):
77 with open(repo_conf2, 'r') as f:
78 lines = f.readlines()
79 newpath = ''
80 for i, line in enumerate(lines):
81 if line.lstrip().startswith('worktree = '):
82 oldpath = line.split(' = ')[-1].rstrip()
83 if oldpath.startswith('/'):
84 newpath = '../' * (module.count('/') + 3) + module
85 lines[i] = '\tworktree = %s\n' % newpath
86 break
87 if newpath:
88 with open(repo_conf2, 'w') as f:
89 for line in lines:
90 f.write(line)
91
45 def update_submodules(self, ud, d): 92 def update_submodules(self, ud, d):
46 # We have to convert bare -> full repo, do the submodule bit, then convert back 93 # We have to convert bare -> full repo, do the submodule bit, then convert back
47 tmpclonedir = ud.clonedir + ".tmp" 94 tmpclonedir = ud.clonedir + ".tmp"
@@ -54,6 +101,7 @@ class GitSM(Git):
54 runfetchcmd(ud.basecmd + " reset --hard", d) 101 runfetchcmd(ud.basecmd + " reset --hard", d)
55 runfetchcmd(ud.basecmd + " submodule init", d) 102 runfetchcmd(ud.basecmd + " submodule init", d)
56 runfetchcmd(ud.basecmd + " submodule update", d) 103 runfetchcmd(ud.basecmd + " submodule update", d)
104 self._set_relative_paths(tmpclonedir)
57 runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*false/bare = true/'", d) 105 runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*false/bare = true/'", d)
58 os.rename(gitdir, ud.clonedir,) 106 os.rename(gitdir, ud.clonedir,)
59 bb.utils.remove(tmpclonedir, True) 107 bb.utils.remove(tmpclonedir, True)