Added support for LFS clones

This commit is contained in:
pieterclaerhout
2017-10-10 19:52:07 +02:00
parent 0b3f120e2b
commit e6b6eb8bef
2 changed files with 24 additions and 7 deletions

View File

@@ -31,7 +31,7 @@ CLI Usage is as follows::
[-o OUTPUT_DIRECTORY] [-i] [--starred] [--watched] [-o OUTPUT_DIRECTORY] [-i] [--starred] [--watched]
[--all] [--issues] [--issue-comments] [--issue-events] [--all] [--issues] [--issue-comments] [--issue-events]
[--pulls] [--pull-comments] [--pull-commits] [--labels] [--pulls] [--pull-comments] [--pull-commits] [--labels]
[--hooks] [--milestones] [--repositories] [--bare] [--hooks] [--milestones] [--repositories] [--bare] [--lfs]
[--wikis] [--skip-existing] [--wikis] [--skip-existing]
[-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX] [-L [LANGUAGES [LANGUAGES ...]]] [-N NAME_REGEX]
[-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F] [-H GITHUB_HOST] [-O] [-R REPOSITORY] [-P] [-F]
@@ -72,6 +72,7 @@ CLI Usage is as follows::
--milestones include milestones in backup --milestones include milestones in backup
--repositories include repository clone in backup --repositories include repository clone in backup
--bare clone bare repositories --bare clone bare repositories
--lfs clone LFS repositories
--wikis include wiki clone in backup --wikis include wiki clone in backup
--skip-existing skip project if a backup directory exists --skip-existing skip project if a backup directory exists
-L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]] -L [LANGUAGES [LANGUAGES ...]], --languages [LANGUAGES [LANGUAGES ...]]

View File

@@ -208,6 +208,10 @@ def parse_args():
action='store_true', action='store_true',
dest='bare_clone', dest='bare_clone',
help='clone bare repositories') help='clone bare repositories')
parser.add_argument('--lfs',
action='store_true',
dest='lfs_clone',
help='clone lfs repositories')
parser.add_argument('--wikis', parser.add_argument('--wikis',
action='store_true', action='store_true',
dest='include_wiki', dest='include_wiki',
@@ -540,7 +544,8 @@ def backup_repositories(args, output_directory, repositories):
repo_url, repo_url,
repo_dir, repo_dir,
skip_existing=args.skip_existing, skip_existing=args.skip_existing,
bare_clone=args.bare_clone) bare_clone=args.bare_clone,
lfs_clone=arg.lfs_clone)
download_wiki = (args.include_wiki or args.include_everything) download_wiki = (args.include_wiki or args.include_everything)
if repository['has_wiki'] and download_wiki: if repository['has_wiki'] and download_wiki:
@@ -548,7 +553,8 @@ def backup_repositories(args, output_directory, repositories):
repo_url.replace('.git', '.wiki.git'), repo_url.replace('.git', '.wiki.git'),
os.path.join(repo_cwd, 'wiki'), os.path.join(repo_cwd, 'wiki'),
skip_existing=args.skip_existing, skip_existing=args.skip_existing,
bare_clone=args.bare_clone) bare_clone=args.bare_clone,
lfs_clone=arg.lfs_clone)
if args.include_issues or args.include_everything: if args.include_issues or args.include_everything:
backup_issues(args, repo_cwd, repository, repos_template) backup_issues(args, repo_cwd, repository, repos_template)
@@ -738,7 +744,8 @@ def fetch_repository(name,
remote_url, remote_url,
local_dir, local_dir,
skip_existing=False, skip_existing=False,
bare_clone=False): bare_clone=False,
lfs_clone=False):
if bare_clone: if bare_clone:
if os.path.exists(local_dir): if os.path.exists(local_dir):
clone_exists = subprocess.check_output(['git', clone_exists = subprocess.check_output(['git',
@@ -780,6 +787,9 @@ def fetch_repository(name,
git_command = ['git', 'remote', 'set-url', 'origin', remote_url] git_command = ['git', 'remote', 'set-url', 'origin', remote_url]
logging_subprocess(git_command, None, cwd=local_dir) logging_subprocess(git_command, None, cwd=local_dir)
if lfs_clone:
git_command = ['git', 'lfs', 'fetch', '--all', '--force', '--tags', '--prune']
else:
git_command = ['git', 'fetch', '--all', '--force', '--tags', '--prune'] git_command = ['git', 'fetch', '--all', '--force', '--tags', '--prune']
logging_subprocess(git_command, None, cwd=local_dir) logging_subprocess(git_command, None, cwd=local_dir)
else: else:
@@ -788,7 +798,13 @@ def fetch_repository(name,
masked_remote_url, masked_remote_url,
local_dir)) local_dir))
if bare_clone: if bare_clone:
if lfs_clone:
git_command = ['git', 'lfs', 'clone', '--mirror', remote_url, local_dir]
else:
git_command = ['git', 'clone', '--mirror', remote_url, local_dir] git_command = ['git', 'clone', '--mirror', remote_url, local_dir]
else:
if lfs_clone:
git_command = ['git', 'lfs', 'clone', remote_url, local_dir]
else: else:
git_command = ['git', 'clone', remote_url, local_dir] git_command = ['git', 'clone', remote_url, local_dir]
logging_subprocess(git_command, None) logging_subprocess(git_command, None)