git integration

This commit is contained in:
Benjamin Bohard 2020-09-07 18:18:00 +02:00
parent 3563d18c0c
commit 72d42ec54c
1 changed files with 39 additions and 10 deletions

View File

@ -68,16 +68,45 @@ def git_integration(func):
master_ref = repo.references['refs/heads/master'] master_ref = repo.references['refs/heads/master']
commit = master_ref.peel() commit = master_ref.peel()
repo.branches.local.create(branch_name, commit) repo.branches.local.create(branch_name, commit)
# état du dépôt, si il nest pas propre, sortir
# checkout sur la branche master
# création dune branche spécifique pour le document à partir de la branche master
# création des fichiers
func(args) func(args)
if repo: # à transformer en decorateur éventuellement if repo:
print('add et commit') repo_status = repo.status()
# ajout tout le contenu hors presentations dans la branche master to_add_status = [pygit2.GIT_STATUS_WT_NEW,
# ajout de tout le contenu de presentations dans la branche spécifique pygit2.GIT_STATUS_WT_MODIFIED]
branch_add_paths = [fp for fp in repo_status
if fp.startswith(f'presentations/') and repo_status[fp] in to_add_status]
master_add_paths = [fp for fp in repo_status
if (fp.startswith('content/') or fp.startswith('slides/')) and repo_status[fp] in to_add_status]
author = pygit2.Signature(repo.config['user.name'], repo.config['user.email'])
committer = author
index = repo.index
for fp in master_add_paths:
index.add(fp)
index.write()
tree = index.write_tree()
master_ref = repo.references['refs/heads/master']
parents = [master_ref.peel().hex]
repo.create_commit('refs/heads/master',
author,
committer,
'comment',
tree,
parents)
for fp in branch_add_paths:
index.add(fp)
index.write()
tree = index.write_tree()
branch_ref = repo.references[f'refs/heads/{branch_name}']
parents = [branch_ref.peel().hex]
repo.create_commit(f'refs/heads/{branch_name}',
author,
committer,
'comment',
tree,
parents)
return inner return inner
def main(): def main():
@ -105,7 +134,7 @@ def main():
if args.directory: if args.directory:
root = root + re.sub(r'[\w-]+/?', '../', args.directory) root = root + re.sub(r'[\w-]+/?', '../', args.directory)
name = 'master.tex' name = 'diaporama.tex'
title = args.title title = args.title
if not title: if not title: