Source code for libka.gitattributes
#!/usr/bin/python3
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4
############################################################################
# Copyright © 2016-2018 José Manuel Santamaría Lema <panfaust@gmail.com> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
############################################################################
import os
from git import Repo
# Returns 0 on success, non-zero on error
[docs]
def create_gitattibutes_file(verbose=False):
if not os.path.exists('debian/'):
if verbose:
print("No debian/ directory found.")
return 1
if os.path.exists("debian/.gitattributes"):
if verbose:
print("The file debian/.gitattributes already exists, not touching it.")
return 1
attr_file = open('debian/.gitattributes','w')
print("changelog merge=dpkg-mergechangelogs", file=attr_file)
return 0
# Returns 0 on success, non-zero on error
[docs]
def create_gitattributes_file_and_commit(verbose=False):
#Exit if we couldn't create the file
ret = create_gitattibutes_file(verbose)
if ret != 0:
return ret
#Commit the changes to git
try:
repo = Repo(".")
except:
print("Couldn't open git repository")
return 1
repo.index.add(['debian/.gitattributes'])
repo.index.commit("NOCI\nCreate debian/.gitattributes file with the changelog merge driver.")
return 0