Diff
Modified: trunk/Tools/ChangeLog (291803 => 291804)
--- trunk/Tools/ChangeLog 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/ChangeLog 2022-03-24 17:57:50 UTC (rev 291804)
@@ -1,3 +1,40 @@
+2022-03-24 Jonathan Bedard <[email protected]>
+
+ [git-webkit] Install git-lfs
+ https://bugs.webkit.org/show_bug.cgi?id=238270
+ <rdar://problem/90708032>
+
+ Reviewed by Aakash Jain and Wenson Hsieh.
+
+ * Scripts/libraries/webkitcorepy/setup.py: Bump version.
+ * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
+ * Scripts/libraries/webkitcorepy/webkitcorepy/mocks/requests_.py:
+ (Response.__init__): Accept binary content or text.
+ (Response.text): Decode binary content.
+ * Scripts/libraries/webkitscmpy/setup.py: Bump version.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
+ (Git): Add git lfs mocks.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/git_hub.py:
+ (GitHub.__init__): Mock project release binaries.
+ (GitHub.request): Ditto.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py: Add InstallGitLFS.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/program/install_git_lfs.py: Added.
+ (InstallGitLFS):
+ (InstallGitLFS.url): Return URL specific to the current platform.
+ (InstallGitLFS.install): Install `git lfs` globally on this machine.
+ (InstallGitLFS.parser): Install `git lfs` even if it is already installed.
+ (InstallGitLFS.main): Check `git lfs` version, install it if needed, and then run `git lfs install`.
+ * Scripts/libraries/webkitscmpy/webkitscmpy/test/install_git_lfs_unittest.py: Added.
+ (TestInstallGitLFS):
+ (TestInstallGitLFS.setUp):
+ (TestInstallGitLFS.test_svn):
+ (TestInstallGitLFS.test_remote_git):
+ (TestInstallGitLFS.test_url):
+ (TestInstallGitLFS.test_install):
+ (TestInstallGitLFS.test_configure):
+ (TestInstallGitLFS.test_no_op):
+
2022-03-24 Ben Nham <[email protected]>
PushAPI.firePushEventWithNoPagesTimeout fails in debug builds
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/setup.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitcorepy/setup.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/setup.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -30,7 +30,7 @@
setup(
name='webkitcorepy',
- version='0.13.4',
+ version='0.13.5',
description='Library containing various Python support classes and functions.',
long_description=readme(),
classifiers=[
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -44,7 +44,7 @@
from webkitcorepy.editor import Editor
from webkitcorepy.file_lock import FileLock
-version = Version(0, 13, 4)
+version = Version(0, 13, 5)
from webkitcorepy.autoinstall import Package, AutoInstall
if sys.version_info > (3, 0):
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/requests_.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/requests_.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/requests_.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -46,7 +46,7 @@
def create404(url="" headers=None):
return Response(status_code=404, url="" headers=headers)
- def __init__(self, status_code=None, text=None, url="" headers=None):
+ def __init__(self, status_code=None, text=None, content=None, url="" headers=None):
if status_code is not None:
self.status_code = status_code
elif text is not None:
@@ -53,7 +53,14 @@
self.status_code = 200
else:
self.status_code = 204 # No content
- self.text = text
+
+ if text and content:
+ raise ValueError("Cannot define both 'text' and 'content'")
+ elif text:
+ self.content = string_utils.encode(text)
+ else:
+ self.content = content or b''
+
self.url = ""
self.headers = headers or {}
@@ -60,8 +67,12 @@
if 'Content-Type' not in self.headers:
self.headers['Content-Type'] = 'text'
if 'Content-Length' not in self.headers:
- self.headers['Content-Length'] = len(self.text) if self.text else 0
+ self.headers['Content-Length'] = len(self.content) if self.content else 0
+ @property
+ def text(self):
+ return string_utils.decode(self.content)
+
def json(self):
return json.loads(self.text)
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/setup.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitscmpy/setup.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/setup.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -29,7 +29,7 @@
setup(
name='webkitscmpy',
- version='4.4.3',
+ version='4.5.0',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -46,7 +46,7 @@
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)
-version = Version(4, 4, 3)
+version = Version(4, 5, 0)
AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('jinja2', Version(2, 11, 3)))
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -79,6 +79,8 @@
self.staged = {}
self.modified = {}
+ self.has_git_lfs = False
+
# If the directory provided actually exists, populate it
if self.path != '/' and os.path.isdir(self.path):
if not os.path.isdir(os.path.join(self.path, '.git')):
@@ -536,6 +538,22 @@
returncode=128,
stderr='fatal: not a git repository (or any parent up to mount point)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).\n',
),
+ ), mocks.Subprocess.Route(
+ 'sudo', 'sh', re.compile(r'.+/install.sh'),
+ generator=lambda *args, **kwargs: self._install_git_lfs(),
+ ), mocks.Subprocess.Route(
+ self.executable, 'lfs', '--version',
+ generator=lambda *args, **kwargs:
+ mocks.ProcessCompletion(
+ returncode=0,
+ stdout='git-lfs/3.1.2 (???)\n',
+ ) if self.has_git_lfs else mocks.ProcessCompletion(
+ returncode=1,
+ stderr='usage: git [--version] [--help]...\n',
+ ),
+ ), mocks.Subprocess.Route(
+ self.executable, 'lfs', 'install',
+ generator=lambda *args, **kwargs: self._configure_git_lfs(),
), *git_svn_routes
)
@@ -924,7 +942,25 @@
stdout='Committed r{}\n\tM\tFiles/Changed.txt\n'.format(self.commits[branch][-1].revision),
)
-
def reset(self, index):
self.head = self.commits[self.head.branch][-(index + 1)]
return mocks.ProcessCompletion(returncode=0)
+
+ def _install_git_lfs(self):
+ self.has_git_lfs = True
+ return mocks.ProcessCompletion(
+ returncode=0,
+ stdout='Git LFS initialized.\n',
+ )
+
+ def _configure_git_lfs(self):
+ if not self.has_git_lfs:
+ return mocks.ProcessCompletion(
+ returncode=1,
+ stderr='usage: git [--version] [--help]...\n',
+ )
+ self.edit_config('lfs.repositoryformatversion', '0')
+ return mocks.ProcessCompletion(
+ returncode=0,
+ stdout='Updated Git hooks.\nGit LFS initialized.\n',
+ )
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/git_hub.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/git_hub.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/remote/git_hub.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -35,6 +35,7 @@
def __init__(
self, remote='github.example.com/WebKit/WebKit', datafile=None,
default_branch='main', git_svn=False, environment=None,
+ releases=None,
):
if not scmremote.GitHub.is_webserver('https://{}'.format(remote)):
raise ValueError('"{}" is not a valid GitHub remote'.format(remote))
@@ -56,6 +57,7 @@
self.head = self.commits[self.default_branch][-1]
self.tags = {}
self.pull_requests = []
+ self.releases = releases or dict()
def commit(self, ref):
if ref in self.commits:
@@ -412,4 +414,9 @@
))
return mocks.Response.fromJson(self.pull_requests[existing], url=""
+ # Releases
+ download_base = '{}/releases/download/'.format(self.remote)
+ if method == 'GET' and stripped_url.startswith(download_base):
+ return self.releases.get(stripped_url[len(download_base):], mocks.Response.create404(url))
+
return super(GitHub, self).request(method, url, data="" params=params, auth=auth, json=json, **kwargs)
Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py (291803 => 291804)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py 2022-03-24 17:30:59 UTC (rev 291803)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/__init__.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -32,6 +32,7 @@
from .command import Command
from .checkout import Checkout
from .find import Find, Info
+from .install_git_lfs import InstallGitLFS
from .land import Land
from .log import Log
from .pull import Pull
@@ -71,7 +72,7 @@
)
subparsers = parser.add_subparsers(help='sub-command help')
- programs = [Blame, Branch, Canonicalize, Checkout, Clean, Find, Info, Land, Log, Pull, PullRequest, Setup]
+ programs = [Blame, Branch, Canonicalize, Checkout, Clean, Find, Info, Land, Log, Pull, PullRequest, Setup, InstallGitLFS]
if subversion:
programs.append(SetupGitSvn)
Added: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/install_git_lfs.py (0 => 291804)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/install_git_lfs.py (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program/install_git_lfs.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -0,0 +1,163 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2022 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import logging
+import os
+import platform
+import re
+import requests
+import shutil
+import subprocess
+import sys
+import tempfile
+import zipfile
+
+from webkitcorepy import Version, arguments, run
+from webkitscmpy import local, log
+from .command import Command
+
+
+class InstallGitLFS(Command):
+ name = 'install-git-lfs'
+ help = "Install 'git lfs' on this machine"
+
+ BASE_URL = 'https://github.com/git-lfs/git-lfs/releases/download'
+ VERSION = Version(3, 1, 2)
+ FILE = 'git-lfs-v{}.zip'.format(VERSION)
+
+ VERSION_RE = re.compile(r'^git-lfs/(?P<version>\d+\.\d+\.\d+) \(.*\)')
+
+ @classmethod
+ def url(cls):
+ from whichcraft import which
+ if platform.system() == 'Darwin':
+ # x86_64 compiled version works better with VPN, if Rosetta is installed, prefer it even on Apple Silicon
+ if platform.machine() == 'arm64' and not which('rosetta'):
+ return '{url}/v{version}/git-lfs-darwin-arm64-v{version}.zip'.format(url="" version=cls.VERSION)
+ return '{url}/v{version}/git-lfs-darwin-amd64-v{version}.zip'.format(url="" version=cls.VERSION)
+
+ # FIXME: Determine URLs for non-Darwin installs
+ return None
+
+ @classmethod
+ def install(cls):
+ if not cls.url():
+ sys.stderr.write('No `git lfs` install implemented for the current platform\n')
+ return False
+
+ log.info("Downloading `git lfs` from '{}'...".format(cls.url()))
+ response = requests.get(cls.url(), allow_redirects=True)
+ log.info("Downloading finished, status code '{}'".format(response.status_code))
+
+ if response.status_code != 200:
+ sys.stderr.write("Failed to download `git lfs` from '{}'\n".format(cls.url()))
+ sys.stderr.write("Response code '{}'\n".format(response.status_code))
+ return False
+
+ tmpdir = tempfile.mkdtemp()
+ try:
+ dest = '{}/{}'.format(tmpdir, cls.FILE)
+ log.info("Saving `git lfs` to '{}'".format(dest))
+ with open(dest, 'wb') as file:
+ file.write(response.content)
+
+ target = os.path.splitext(dest)[0]
+ log.info("Unpacking '{}'...".format(dest))
+ with zipfile.ZipFile(dest, 'r') as file:
+ file.extractall(target)
+ log.info("Unpacked '{}' to '{}'...".format(dest, target))
+
+ log.info("Installing `git lfs` from '{}'...".format(target))
+ install_script = os.path.join(target, 'install.sh')
+ if not os.path.isfile(install_script):
+ sys.stderr.write("Could not find install script at '{}'\n".format(install_script))
+ return False
+ result = run(
+ ['sudo', 'sh', install_script],
+ cwd=os.path.dirname(install_script),
+ stdout=None if log.getEffectiveLevel() > logging.DEBUG else subprocess.PIPE,
+ )
+ log.info("`git lfs` install finished with exit code '{}'".format(result.returncode))
+ if result.returncode:
+ sys.stderr.write("Failed `git lfs` install with exit code '{}'\n".format(result.returncode))
+ return False
+ return True
+
+ finally:
+ shutil.rmtree(tmpdir, ignore_errors=True)
+
+ @classmethod
+ def parser(cls, parser, loggers=None):
+ parser.add_argument(
+ '--overwrite', '-o', '--force', '-f',
+ help='Overwrite existing `git lfs` install, regardless of version',
+ action='',
+ dest='overwrite',
+ default=False,
+ )
+ parser.add_argument(
+ '--no-configure', '--configure',
+ help='Explicitly opt out of configuring this checkout for `git lfs`',
+ action=""
+ dest='configure',
+ default=True,
+ )
+
+ @classmethod
+ def main(cls, args, repository, **kwargs):
+ if not repository.path:
+ sys.stderr.write("Cannot install `git lfs` from a remote repository\n")
+ return 1
+
+ if not isinstance(repository, local.Git):
+ sys.stderr.write("`git lfs` only supported from git repositories\n")
+ return 1
+
+ log.info('Checking `git lfs` version')
+ ran = run([repository.executable(), 'lfs', '--version'], capture_output=True, encoding='utf-8')
+ match = cls.VERSION_RE.match(ran.stdout)
+ version = Version.from_string(match.group('version')) if match else None
+
+ if args.overwrite or ran.returncode or version != cls.VERSION:
+ print('Installing `git lfs` version {}'.format(cls.VERSION))
+ if not cls.install():
+ sys.stderr.write("Failed to install `git lfs` on this machine\n")
+ return 1
+ else:
+ print("`git lfs` version {} is already installed".format(version))
+
+ if not args.configure:
+ print("Skipping configuring `git lfs` for '{}', as requested".format(repository.path))
+ return 0
+
+ lfs_repo_status = repository.config(location='repository').get('lfs.repositoryformatversion')
+ if not args.overwrite and lfs_repo_status == '0':
+ print("`git lfs` is already configured for '{}'".format(repository.path))
+ return 0
+ log.info("Configuring `git lfs` for '{}'".format(repository.path))
+ if run([repository.executable(), 'lfs', 'install'], capture_output=log.getEffectiveLevel() > logging.INFO).returncode:
+ sys.stderr.write("Failed to configure `git lfs` for '{}'\n".format(repository.path))
+ return 1
+ print("Configured `git lfs` for '{}'".format(repository.path))
+ return 0
Added: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/install_git_lfs_unittest.py (0 => 291804)
--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/install_git_lfs_unittest.py (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/test/install_git_lfs_unittest.py 2022-03-24 17:57:50 UTC (rev 291804)
@@ -0,0 +1,134 @@
+# Copyright (C) 2022 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+
+from mock import patch
+from webkitcorepy import OutputCapture, testing, mocks as wkmocks
+from webkitscmpy import local, program, mocks
+
+
+class TestInstallGitLFS(testing.PathTestCase):
+ basepath = 'mock/repository'
+ ZIP_CONTENTS = b'PK\x03\x04\x14\x00\x08\x00\x08\x00QIxT\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00\n\x00 \x00install.shUT\r\x00\x07\xfb\x97<b\xfd\x97<b\xfb\x97<bux\x0b\x00\x01\x04\xf5\x01\x00\x00\x04\x14\x00\x00\x00SV\xd4/-.\xd2O\xca\xcc\xd3O\xcd+S(\xce\xe0\xe2J\xad\xc8,Q0\xe0\xe2\x02\x00PK\x07\x08\xc2\x15&\xc4\x1d\x00\x00\x00\x1b\x00\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00QIxT\xc2\x15&\xc4\x1d\x00\x00\x00\x1b\x00\x00\x00\n\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00install.shUT\r\x00\x07\xfb\x97<b\xfd\x97<b\xfb\x97<bux\x0b\x00\x01\x04\xf5\x01\x00\x00\x04\x14\x00\x00\x00PK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00X\x00\x00\x00u\x00\x00\x00\x00\x00'
+
+ def setUp(self):
+ super(TestInstallGitLFS, self).setUp()
+ os.mkdir(os.path.join(self.path, '.git'))
+ os.mkdir(os.path.join(self.path, '.svn'))
+
+ def test_svn(self):
+ with OutputCapture() as captured, mocks.local.Git(), mocks.local.Svn(self.path):
+ self.assertEqual(1, program.main(
+ args=('install-git-lfs',),
+ path=self.path,
+ ))
+ self.assertEqual(captured.stderr.getvalue(), "`git lfs` only supported from git repositories\n")
+
+ def test_remote_git(self):
+ with OutputCapture() as captured, mocks.remote.GitHub():
+ self.assertEqual(1, program.main(
+ args=('-C', 'https://github.example.com/WebKit/WebKit', 'install-git-lfs'),
+ path=self.path,
+ ))
+ self.assertEqual(captured.stderr.getvalue(), 'Cannot install `git lfs` from a remote repository\n')
+
+ def test_url(self):
+ with patch('platform.system', lambda: 'Windows'):
+ self.assertIsNone(program.InstallGitLFS.url())
+
+ with patch('platform.system', lambda: 'Darwin'), patch('platform.machine', lambda: 'x86_64'):
+ self.assertEqual(
+ program.InstallGitLFS.url(),
+ 'https://github.com/git-lfs/git-lfs/releases/download/v3.1.2/git-lfs-darwin-amd64-v3.1.2.zip',
+ )
+
+ with patch('platform.system', lambda: 'Darwin'), patch('platform.machine', lambda: 'arm64'), patch('whichcraft.which', lambda name: '/bin/{}'.format(name)):
+ self.assertEqual(
+ program.InstallGitLFS.url(),
+ 'https://github.com/git-lfs/git-lfs/releases/download/v3.1.2/git-lfs-darwin-amd64-v3.1.2.zip',
+ )
+
+ with patch('platform.system', lambda: 'Darwin'), patch('platform.machine', lambda: 'arm64'), patch('whichcraft.which', lambda name: None):
+ self.assertEqual(
+ program.InstallGitLFS.url(),
+ 'https://github.com/git-lfs/git-lfs/releases/download/v3.1.2/git-lfs-darwin-arm64-v3.1.2.zip',
+ )
+
+ def test_install(self):
+ with OutputCapture() as captured, mocks.remote.GitHub('github.com/git-lfs/git-lfs', releases={
+ 'v3.1.2/git-lfs-darwin-arm64-v3.1.2.zip': wkmocks.Response(status_code=200, content=self.ZIP_CONTENTS),
+ 'v3.1.2/git-lfs-darwin-amd64-v3.1.2.zip': wkmocks.Response(status_code=200, content=self.ZIP_CONTENTS),
+ }), mocks.local.Git(self.path), mocks.local.Svn():
+ self.assertIsNone(local.Git(self.path).config().get('lfs.repositoryformatversion'))
+ self.assertEqual(0, program.main(
+ args=('install-git-lfs',),
+ path=self.path,
+ ))
+ self.assertEqual(local.Git(self.path).config()['lfs.repositoryformatversion'], '0')
+
+ self.assertEqual(
+ captured.stdout.getvalue(),
+ 'Installing `git lfs` version 3.1.2\n'
+ 'Git LFS initialized.\n'
+ "Configured `git lfs` for '{}'\n".format(self.path),
+ )
+
+ def test_configure(self):
+ with OutputCapture() as captured, mocks.remote.GitHub('github.com/git-lfs/git-lfs', releases={
+ 'v3.1.2/git-lfs-darwin-arm64-v3.1.2.zip': wkmocks.Response(status_code=200, content=self.ZIP_CONTENTS),
+ 'v3.1.2/git-lfs-darwin-amd64-v3.1.2.zip': wkmocks.Response(status_code=200, content=self.ZIP_CONTENTS),
+ }), mocks.local.Git(self.path) as mocked, mocks.local.Svn():
+ mocked.has_git_lfs = True
+
+ self.assertIsNone(local.Git(self.path).config().get('lfs.repositoryformatversion'))
+ self.assertEqual(0, program.main(
+ args=('install-git-lfs',),
+ path=self.path,
+ ))
+ self.assertEqual(local.Git(self.path).config()['lfs.repositoryformatversion'], '0')
+
+ self.assertEqual(
+ captured.stdout.getvalue(),
+ '`git lfs` version 3.1.2 is already installed\n'
+ "Configured `git lfs` for '{}'\n".format(self.path),
+ )
+
+ def test_no_op(self):
+ with OutputCapture() as captured, mocks.remote.GitHub('github.com/git-lfs/git-lfs', releases={
+ 'v3.1.2/git-lfs-darwin-arm64-v3.1.2.zip': wkmocks.Response(status_code=200, content=self.ZIP_CONTENTS),
+ 'v3.1.2/git-lfs-darwin-amd64-v3.1.2.zip': wkmocks.Response(status_code=200, content=self.ZIP_CONTENTS),
+ }), mocks.local.Git(self.path) as mocked, mocks.local.Svn():
+ mocked.has_git_lfs = True
+ mocked.edit_config('lfs.repositoryformatversion', '0')
+
+ self.assertEqual(0, program.main(
+ args=('install-git-lfs',),
+ path=self.path,
+ ))
+ self.assertEqual(local.Git(self.path).config()['lfs.repositoryformatversion'], '0')
+
+ self.assertEqual(
+ captured.stdout.getvalue(),
+ '`git lfs` version 3.1.2 is already installed\n'
+ "`git lfs` is already configured for '{}'\n".format(self.path),
+ )