blob: 80a808d88f03dd0374246e5f11d4db3dcb124429 [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011import bb
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012from bb.fetch2.git import Git
13from bb.fetch2 import runfetchcmd
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
15class GitANNEX(Git):
16 def supports(self, ud, d):
17 """
18 Check to see if a given url can be fetched with git.
19 """
20 return ud.type in ['gitannex']
21
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022 def urldata_init(self, ud, d):
23 super(GitANNEX, self).urldata_init(ud, d)
24 if ud.shallow:
25 ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*']
26
Patrick Williamsc0f7c042017-02-23 20:41:17 -060027 def uses_annex(self, ud, d, wd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 for name in ud.names:
29 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060030 runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 return True
32 except bb.fetch.FetchError:
33 pass
34
35 return False
36
Patrick Williamsc0f7c042017-02-23 20:41:17 -060037 def update_annex(self, ud, d, wd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060039 runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 except bb.fetch.FetchError:
41 return False
Patrick Williamsc0f7c042017-02-23 20:41:17 -060042 runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
44 return True
45
46 def download(self, ud, d):
47 Git.download(self, ud, d)
48
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049 if not ud.shallow or ud.localpath != ud.fullshallow:
50 if self.uses_annex(ud, d, ud.clonedir):
51 self.update_annex(ud, d, ud.clonedir)
52
53 def clone_shallow_local(self, ud, dest, d):
54 super(GitANNEX, self).clone_shallow_local(ud, dest, d)
55
56 try:
57 runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest)
58 except bb.fetch.FetchError:
59 pass
60
61 if self.uses_annex(ud, d, dest):
62 runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest)
63 runfetchcmd("chmod u+w -R %s/.git/annex" % (dest), d, quiet=True, workdir=dest)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064
65 def unpack(self, ud, destdir, d):
66 Git.unpack(self, ud, destdir, d)
67
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060069 runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070 except bb.fetch.FetchError:
71 pass
72
Patrick Williamsc0f7c042017-02-23 20:41:17 -060073 annex = self.uses_annex(ud, d, ud.destdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074 if annex:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060075 runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir)
76 runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir)
77