diff options
| -rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 2ee030546a..a0b656b610 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
| @@ -1908,3 +1908,83 @@ class GitShallowTest(FetcherTest): | |||
| 1908 | 1908 | ||
| 1909 | dir = os.listdir(self.unpackdir + "/git/") | 1909 | dir = os.listdir(self.unpackdir + "/git/") |
| 1910 | self.assertIn("fstests.doap", dir) | 1910 | self.assertIn("fstests.doap", dir) |
| 1911 | |||
| 1912 | class GitLfsTest(FetcherTest): | ||
| 1913 | def setUp(self): | ||
| 1914 | FetcherTest.setUp(self) | ||
| 1915 | |||
| 1916 | self.gitdir = os.path.join(self.tempdir, 'git') | ||
| 1917 | self.srcdir = os.path.join(self.tempdir, 'gitsource') | ||
| 1918 | |||
| 1919 | self.d.setVar('WORKDIR', self.tempdir) | ||
| 1920 | self.d.setVar('S', self.gitdir) | ||
| 1921 | self.d.delVar('PREMIRRORS') | ||
| 1922 | self.d.delVar('MIRRORS') | ||
| 1923 | |||
| 1924 | self.d.setVar('SRCREV', '${AUTOREV}') | ||
| 1925 | self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}') | ||
| 1926 | |||
| 1927 | bb.utils.mkdirhier(self.srcdir) | ||
| 1928 | self.git('init', cwd=self.srcdir) | ||
| 1929 | with open(os.path.join(self.srcdir, '.gitattributes'), 'wt') as attrs: | ||
| 1930 | attrs.write('*.mp3 filter=lfs -text') | ||
| 1931 | self.git(['add', '.gitattributes'], cwd=self.srcdir) | ||
| 1932 | self.git(['commit', '-m', "attributes", '.gitattributes'], cwd=self.srcdir) | ||
| 1933 | |||
| 1934 | def git(self, cmd, cwd=None): | ||
| 1935 | if isinstance(cmd, str): | ||
| 1936 | cmd = 'git ' + cmd | ||
| 1937 | else: | ||
| 1938 | cmd = ['git'] + cmd | ||
| 1939 | if cwd is None: | ||
| 1940 | cwd = self.gitdir | ||
| 1941 | return bb.process.run(cmd, cwd=cwd)[0] | ||
| 1942 | |||
| 1943 | def fetch(self, uri=None): | ||
| 1944 | uris = self.d.getVar('SRC_URI').split() | ||
| 1945 | uri = uris[0] | ||
| 1946 | d = self.d | ||
| 1947 | |||
| 1948 | fetcher = bb.fetch2.Fetch(uris, d) | ||
| 1949 | fetcher.download() | ||
| 1950 | ud = fetcher.ud[uri] | ||
| 1951 | return fetcher, ud | ||
| 1952 | |||
| 1953 | def test_lfs_enabled(self): | ||
| 1954 | import shutil | ||
| 1955 | |||
| 1956 | uri = 'git://%s;protocol=file;subdir=${S};lfs=1' % self.srcdir | ||
| 1957 | self.d.setVar('SRC_URI', uri) | ||
| 1958 | |||
| 1959 | fetcher, ud = self.fetch() | ||
| 1960 | self.assertIsNotNone(ud.method._find_git_lfs) | ||
| 1961 | |||
| 1962 | # If git-lfs can be found, the unpack should be successful | ||
| 1963 | ud.method._find_git_lfs = lambda d: True | ||
| 1964 | shutil.rmtree(self.gitdir, ignore_errors=True) | ||
| 1965 | fetcher.unpack(self.d.getVar('WORKDIR')) | ||
| 1966 | |||
| 1967 | # If git-lfs cannot be found, the unpack should throw an error | ||
| 1968 | with self.assertRaises(bb.fetch2.FetchError): | ||
| 1969 | ud.method._find_git_lfs = lambda d: False | ||
| 1970 | shutil.rmtree(self.gitdir, ignore_errors=True) | ||
| 1971 | fetcher.unpack(self.d.getVar('WORKDIR')) | ||
| 1972 | |||
| 1973 | def test_lfs_disabled(self): | ||
| 1974 | import shutil | ||
| 1975 | |||
| 1976 | uri = 'git://%s;protocol=file;subdir=${S};lfs=0' % self.srcdir | ||
| 1977 | self.d.setVar('SRC_URI', uri) | ||
| 1978 | |||
| 1979 | fetcher, ud = self.fetch() | ||
| 1980 | self.assertIsNotNone(ud.method._find_git_lfs) | ||
| 1981 | |||
| 1982 | # If git-lfs can be found, the unpack should be successful | ||
| 1983 | ud.method._find_git_lfs = lambda d: True | ||
| 1984 | shutil.rmtree(self.gitdir, ignore_errors=True) | ||
| 1985 | fetcher.unpack(self.d.getVar('WORKDIR')) | ||
| 1986 | |||
| 1987 | # If git-lfs cannot be found, the unpack should be successful | ||
| 1988 | ud.method._find_git_lfs = lambda d: False | ||
| 1989 | shutil.rmtree(self.gitdir, ignore_errors=True) | ||
| 1990 | fetcher.unpack(self.d.getVar('WORKDIR')) | ||
