diff --git a/setup_main_tex_file.py b/setup_main_tex_file.py index 30dbb17..4d9b5d2 100755 --- a/setup_main_tex_file.py +++ b/setup_main_tex_file.py @@ -81,43 +81,53 @@ def git_integration(func): author = repo.default_signature committer = author - repo.checkout('refs/heads/master') - 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) + if func.__name__ == 'init': + comment = 'Initialisation de la formation' + elif func.__name__ == 'update': + comment = 'Construction de la formation' + elif func.__name__ == 'outline': + comment = 'Mise à jour du programme' + else: + comment = 'Travail sur la formation' - repo.checkout(f'refs/heads/{branch_name}') - 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) + if master_add_paths: + repo.checkout('refs/heads/master') + 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] + master_head = repo.create_commit('refs/heads/master', + author, + committer, + comment, + tree, + parents) + else: + master_head = repo.revparse_single('refs/heads/master') - basket = repo.branches.get(branch_name) - cherry = repo.lookup_branch('refs/heads/master').target - base = repo.merge_base(cherry, basket.target) - base_tree = cherry.parents[0].tree + if branch_add_paths: + repo.checkout(f'refs/heads/{branch_name}') + index = repo.index + 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) + if master_head not in repo.walk(branch_ref.target): + repo.merge(master_head) + tree = repo.index.write_tree() + merge_commit = repo.create_commit('HEAD', author, committer, 'Merge master into xelatex/*', tree, [repo.head.target, master_head]) - index = repo.merge_trees(base_tree, basket, cherry) - tree_id = index.write_tree(repo) - repo.create_commit(basket.name, author, committer, 'bof', tree_id, [basket.target]) return inner