Source code for libka.pkgedit.ka_git_repo
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# pylint: disable=line-too-long
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4
# pylint: enable=line-too-long
############################################################################
# Copyright © 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. #
############################################################################
"""This module just provides the KAGitRepo class"""
import git
[docs]
class KAGitRepo(git.Repo):
"""This class is meant to represent a git repository, it's just a subclass
of git.Repo with some extra methods"""
[docs]
def get_max_version_tag(self, prefix='debian/'):
"""Get the maximum version tag so far with the given prefix"""
#TODO
pass
[docs]
def branch_out_of_sync(self):
"""
Returns `True` if the current branch doesn't point to the same commit
than the branch it is suposed to track.
If we are in 'detached mode' this function returns `True`.
If the current branch isn't tracking any remote branch, this function
returns `True`.
"""
try:
tracking_branch_commit = self.active_branch.tracking_branch().commit
active_branch_commit = self.active_branch.commit
except AttributeError:
#This happens when we are in detached mode or the current branch
#doesn't have an upstream branch
return True
return tracking_branch_commit != active_branch_commit
[docs]
def check_valid_kubuntu_branch(self):
"""Returns True if the current branch is a valid kubuntu branch"""
#TODO
pass
[docs]
def commit_all_debian_changes(self, noci, message):
"""Commits all the files under the debian/ directory, including untracked
files"""
#TODO
pass
[docs]
def revert_first_matching_commit(self, commit_message_regexp, starting_commit=None):
"""
Reverts the first commit found whose message matches `commit_message_regexp`.
If `starting_commit` is `None` it will pick the latest from the current branch.
Returns `True` if the commit was found and reverted, otherwise returns `False`.
"""
#Pick the latest commit from current branch if needed
if starting_commit is None:
starting_commit = self.active_branch.commit
#Find out the matching commit
matching_commits = starting_commit.iter_items(self,
starting_commit,
grep=commit_message_regexp,
max_count=1)
try:
matching_commit = next(matching_commits)
except StopIteration:
matching_commit = None
#Revert the matching commit if appropiate
if matching_commit is not None:
print("Reverting commit %s" % matching_commit)
git_cmd = git.cmd.Git('.')
try:
git_cmd.revert("--no-edit", matching_commit)
result = True
except git.exc.GitCommandError as exception: #pylint: disable=no-member
print(str(exception))
result = False
else:
print("No matching commits found")
result = False
return result