blob: 1d497dcb0f6cd4f594c22f9908bf78b6128c0272 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001"""
2BitBake 'Fetch' git annex implementation
3"""
4
5# Copyright (C) 2014 Otavio Salvador
6# Copyright (C) 2014 O.S. Systems Software LTDA.
7#
Brad Bishopc342db32019-05-15 21:57:59 -04008# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009#
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010
11import os
12import bb
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013from bb.fetch2.git import Git
14from bb.fetch2 import runfetchcmd
15from bb.fetch2 import logger
16
17class GitANNEX(Git):
18 def supports(self, ud, d):
19 """
20 Check to see if a given url can be fetched with git.
21 """
22 return ud.type in ['gitannex']
23
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 def urldata_init(self, ud, d):
25 super(GitANNEX, self).urldata_init(ud, d)
26 if ud.shallow:
27 ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*']
28
Patrick Williamsc0f7c042017-02-23 20:41:17 -060029 def uses_annex(self, ud, d, wd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030 for name in ud.names:
31 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032 runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 return True
34 except bb.fetch.FetchError:
35 pass
36
37 return False
38
Patrick Williamsc0f7c042017-02-23 20:41:17 -060039 def update_annex(self, ud, d, wd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041 runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 except bb.fetch.FetchError:
43 return False
Patrick Williamsc0f7c042017-02-23 20:41:17 -060044 runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045
46 return True
47
48 def download(self, ud, d):
49 Git.download(self, ud, d)
50
Brad Bishopd7bf8c12018-02-25 22:55:05 -050051 if not ud.shallow or ud.localpath != ud.fullshallow:
52 if self.uses_annex(ud, d, ud.clonedir):
53 self.update_annex(ud, d, ud.clonedir)
54
55 def clone_shallow_local(self, ud, dest, d):
56 super(GitANNEX, self).clone_shallow_local(ud, dest, d)
57
58 try:
59 runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest)
60 except bb.fetch.FetchError:
61 pass
62
63 if self.uses_annex(ud, d, dest):
64 runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest)
65 runfetchcmd("chmod u+w -R %s/.git/annex" % (dest), d, quiet=True, workdir=dest)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
67 def unpack(self, ud, destdir, d):
68 Git.unpack(self, ud, destdir, d)
69
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060071 runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072 except bb.fetch.FetchError:
73 pass
74
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075 annex = self.uses_annex(ud, d, ud.destdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076 if annex:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077 runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir)
78 runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir)
79