forked from adamm/git-importer
Compare commits
9 Commits
use_git_fo
...
fix_magic_
Author | SHA1 | Date | |
---|---|---|---|
eba3fece91 | |||
b74f36c81e | |||
7b9b033adc | |||
c44cb17e5d | |||
3384a6f2b1 | |||
1ec72ac80c | |||
033b8f8cee | |||
17062df04e | |||
aa73d97b35 |
14
lib/git.py
14
lib/git.py
@ -85,7 +85,7 @@ class Git:
|
||||
"""Checkout into the branch HEAD"""
|
||||
new_branch = False
|
||||
if branch not in self.branches():
|
||||
self.git_run(["branch", "-q", branch, "HEAD"])
|
||||
self.git_run(["switch", "-q", "--orphan", branch])
|
||||
new_branch = True
|
||||
else:
|
||||
ref = f"refs/heads/{branch}"
|
||||
@ -180,7 +180,13 @@ class Git:
|
||||
# logging.warning(f"Error removing file {path}: {e}")
|
||||
|
||||
def add(self, filename):
|
||||
self.git_run(["add", filename])
|
||||
self.git_run(["add", ":(literal)" + filename])
|
||||
|
||||
def add_default_gitignore(self):
|
||||
if not (self.path / ".gitignore").exists():
|
||||
with (self.path / ".gitignore").open("w") as f:
|
||||
f.write(".osc\n")
|
||||
self.add(".gitignore")
|
||||
|
||||
def add_default_lfs_gitattributes(self, force=False):
|
||||
if not (self.path / ".gitattributes").exists() or force:
|
||||
@ -235,7 +241,7 @@ class Git:
|
||||
|
||||
def remove(self, file: pathlib.Path):
|
||||
self.git_run(
|
||||
["rm", "-q", "-f", "--ignore-unmatch", file.name],
|
||||
["rm", "-q", "-f", "--ignore-unmatch", ":(literal)" + file.name],
|
||||
)
|
||||
patterns = self.get_specific_lfs_gitattributes()
|
||||
if file.name in patterns:
|
||||
@ -271,7 +277,7 @@ class Git:
|
||||
["remote"],
|
||||
stdout=subprocess.PIPE,
|
||||
).stdout.decode("utf-8"):
|
||||
logger.warning("Not pushing to remote because no 'origin' configured")
|
||||
logging.warning("Not pushing to remote because no 'origin' configured")
|
||||
return
|
||||
|
||||
cmd = ["push"]
|
||||
|
@ -2,8 +2,6 @@ import logging
|
||||
import os
|
||||
|
||||
import yaml
|
||||
from hashlib import md5
|
||||
from pathlib import Path
|
||||
|
||||
from lib.binary import is_binary_or_large
|
||||
from lib.db import DB
|
||||
@ -88,6 +86,11 @@ class GitExporter:
|
||||
logging.debug(f"Committing {flat}")
|
||||
self.commit_flat(flat, branch_state)
|
||||
|
||||
# make sure that we create devel branch
|
||||
if not branch_state["devel"]:
|
||||
logging.debug("force creating devel")
|
||||
self.git.set_branch_head("devel", self.git.branch_head("factory"))
|
||||
|
||||
self.git.push(force=True)
|
||||
|
||||
def run_gc(self):
|
||||
@ -135,12 +138,6 @@ class GitExporter:
|
||||
return True
|
||||
return flat.parent1 == branch_state[flat.branch]
|
||||
|
||||
def file_md5(self, file):
|
||||
m = md5()
|
||||
with open(file, 'rb') as f:
|
||||
m.update(f.read())
|
||||
return m.hexdigest()
|
||||
|
||||
def commit_flat(self, flat, branch_state):
|
||||
parents = []
|
||||
self.git.checkout(flat.branch)
|
||||
@ -158,41 +155,13 @@ class GitExporter:
|
||||
|
||||
# create file if not existant
|
||||
self.git.add_default_lfs_gitattributes(force=False)
|
||||
self.git.add_default_gitignore()
|
||||
|
||||
new_files = flat.commit.files_list()
|
||||
cur_files = os.listdir(self.git.path)
|
||||
for cf in cur_files:
|
||||
if cf[0] == '.':
|
||||
continue
|
||||
found = False
|
||||
for nf in new_files:
|
||||
if nf['name'] == cf:
|
||||
found = True
|
||||
break
|
||||
|
||||
if found:
|
||||
# check if file is modified
|
||||
file_path = self.git.path.joinpath(cf)
|
||||
stat = file_path.stat()
|
||||
if stat.st_size != nf['size'] or self.file_md5(file_path) != nf['md5']:
|
||||
logging.debug(f"updating {file_path.name}")
|
||||
self.commit_file(flat, Path(cf), nf['size'], nf['md5'])
|
||||
else:
|
||||
logging.debug(f"leaving {file_path.name}")
|
||||
else:
|
||||
# file not exist in new commit
|
||||
self.git.remove(Path(cf))
|
||||
|
||||
|
||||
# new files?
|
||||
for file in new_files:
|
||||
found = False
|
||||
for cf in cur_files:
|
||||
if file['name'] == cf:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
self.commit_file(flat, Path(file['name']), file['size'], file['md5'])
|
||||
to_download, to_delete = flat.commit.calc_delta(branch_state[flat.branch])
|
||||
for file in to_delete:
|
||||
self.git.remove(file)
|
||||
for file, size, md5 in to_download:
|
||||
self.commit_file(flat, file, size, md5)
|
||||
|
||||
commit = self.git.commit(
|
||||
flat.user.realname,
|
||||
|
Reference in New Issue
Block a user