blob: a9b69caab4d56ca2f08411080d97b8da64a04aca [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3"""
4BitBake 'Fetch' git annex implementation
5"""
6
7# Copyright (C) 2014 Otavio Salvador
8# Copyright (C) 2014 O.S. Systems Software LTDA.
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License version 2 as
12# published by the Free Software Foundation.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along
20# with this program; if not, write to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23import os
24import bb
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025from bb.fetch2.git import Git
26from bb.fetch2 import runfetchcmd
27from bb.fetch2 import logger
28
29class GitANNEX(Git):
30 def supports(self, ud, d):
31 """
32 Check to see if a given url can be fetched with git.
33 """
34 return ud.type in ['gitannex']
35
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036 def urldata_init(self, ud, d):
37 super(GitANNEX, self).urldata_init(ud, d)
38 if ud.shallow:
39 ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*']
40
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041 def uses_annex(self, ud, d, wd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042 for name in ud.names:
43 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060044 runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 return True
46 except bb.fetch.FetchError:
47 pass
48
49 return False
50
Patrick Williamsc0f7c042017-02-23 20:41:17 -060051 def update_annex(self, ud, d, wd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060053 runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 except bb.fetch.FetchError:
55 return False
Patrick Williamsc0f7c042017-02-23 20:41:17 -060056 runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True, workdir=wd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057
58 return True
59
60 def download(self, ud, d):
61 Git.download(self, ud, d)
62
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063 if not ud.shallow or ud.localpath != ud.fullshallow:
64 if self.uses_annex(ud, d, ud.clonedir):
65 self.update_annex(ud, d, ud.clonedir)
66
67 def clone_shallow_local(self, ud, dest, d):
68 super(GitANNEX, self).clone_shallow_local(ud, dest, d)
69
70 try:
71 runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest)
72 except bb.fetch.FetchError:
73 pass
74
75 if self.uses_annex(ud, d, dest):
76 runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest)
77 runfetchcmd("chmod u+w -R %s/.git/annex" % (dest), d, quiet=True, workdir=dest)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078
79 def unpack(self, ud, destdir, d):
80 Git.unpack(self, ud, destdir, d)
81
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060083 runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 except bb.fetch.FetchError:
85 pass
86
Patrick Williamsc0f7c042017-02-23 20:41:17 -060087 annex = self.uses_annex(ud, d, ud.destdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088 if annex:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060089 runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir)
90 runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir)
91