summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib')
-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)