Commit 8049444d authored by Filippos Giannakos's avatar Filippos Giannakos
Browse files

Merge branch 'feature-changelog' into develop

parents 482c5dd3 30d42d95
......@@ -8,7 +8,8 @@ os.environ["GIT_PYTHON_TRACE"] = "full"
from devflow import utils, versioning
from devflow.version import __version__
from devflow.autopkg import call
from functools import wraps
from devflow.ui import query_action
from functools import wraps, partial
from contextlib import contextmanager
from git.exc import GitCommandError
......@@ -55,6 +56,16 @@ class GitManager(object):
self.new_tags = []
self.repo.git.pull("origin")
def get_branch(self, mode, version):
if mode not in ["release", "hotfix"]:
raise ValueError("Unknown mode: %s" % mode)
return "%s-%s" % (mode, version)
def get_debian_branch(self, mode, version):
if mode not in ["release", "hotfix"]:
raise ValueError("Unknown mode: %s" % mode)
return "debian-%s-%s" % (mode, version)
@cleanup
def start_release(self, version):
self.start_common("release", version)
......@@ -65,11 +76,51 @@ class GitManager(object):
@cleanup
def end_release(self, version):
self.end_common("release", version)
repo = self.repo
master = "master"
debian_master = "debian"
upstream = "develop"
debian = "debian-develop"
upstream_branch = self.get_branch("release", version)
debian_branch = self.get_debian_branch("release", version)
repo.git.checkout(upstream)
with conflicts():
repo.git.merge("--no-ff", upstream_branch)
repo.git.checkout(debian)
with conflicts():
repo.git.merge("--no-ff", debian_branch)
repo.git.checkout(master)
with conflicts():
repo.git.merge("--no-ff", upstream_branch)
repo.git.checkout(debian_master)
with conflicts():
repo.git.merge("--no-ff", debian_branch)
repo.git.checkout(upstream)
print "To remove obsolete branches run:"
print "git branch -d %s" % upstream_branch
print "git branch -d %s" % debian_branch
@cleanup
def end_hotfix(self, version):
self.end_common("hotfix", version)
repo = self.repo
upstream = "master"
debian = "debian"
upstream_branch = self.get_branch("hotfix", version)
debian_branch = self.get_debian_branch("hotfix", version)
repo.git.checkout(upstream)
with conflicts():
repo.git.merge("--no-ff", upstream_branch)
repo.git.checkout(debian)
with conflicts():
repo.git.merge("--no-ff", debian_branch)
repo.git.checkout(upstream)
print "To remove obsolete branches run:"
print "git branch -d %s" % upstream_branch
print "git branch -d %s" % debian_branch
def start_common(self, mode, version):
if mode not in ["release", "hotfix"]:
......@@ -108,6 +159,9 @@ class GitManager(object):
if not feature_upstream in repo.branches:
raise ValueError("Branch %s does not exist." % feature_upstream)
feature_debian = "debian-%s" % feature_upstream
action = partial(self.edit_changelog, feature_upstream, "develop")
query_action("Edit changelog", action = action)
# self.edit_changelog(feature_upstream)
repo.git.checkout("develop")
with conflicts():
repo.git.merge(feature_upstream)
......@@ -121,28 +175,44 @@ class GitManager(object):
if feature_debian in repo.branches:
print "git branch -D %s" % feature_debian
def end_common(self, mode, version):
if mode not in ["release", "hotfix"]:
raise ValueError("Unknown mode: %s" % mode)
def edit_changelog(self, branch, base_branch=None):
repo = self.repo
master = "master"
upstream = "develop" if mode == "release" else "master"
debian = "debian-develop" if mode == "release" else "debian"
upstream_branch = "%s-%s" % (mode, version)
debian_branch = "debian-%s-%s" % (mode, version)
repo.git.checkout(upstream)
with conflicts():
repo.git.merge("--no-ff", upstream_branch)
repo.git.checkout(master)
with conflicts():
repo.git.merge("--no-ff", upstream_branch)
repo.git.checkout(debian)
with conflicts():
repo.git.merge("--no-ff", debian_branch)
repo.git.checkout(upstream)
print "To remove obsolete branches run:"
print "git branch -d %s" % upstream_branch
print "git branch -d %s" % debian_branch
if not branch in repo.branches:
raise ValueError("Branch %s does not exist." % branch)
if base_branch and not base_branch in repo.branches:
raise ValueError("Branch %s does not exist." % base_branch)
repo.git.checkout(branch)
topdir = repo.working_dir
changelog = os.path.join(topdir, "Changelog")
lines = []
lines.append("#Changelog for %s\n" % branch)
if base_branch:
commits = repo.git.rev_list("%s..%s" % (base_branch, branch)).split("\n")
for c in commits:
commit = repo.commit(c)
lines.append(commit.message)
lines.append("\n")
f = open(changelog, 'rw+')
lines.extend(f.readlines())
f.seek(0)
f.truncate(0)
f.writelines(lines)
f.close()
editor = os.getenv('EDITOR')
if not editor:
editor = 'vim'
call("%s %s" % (editor, changelog))
repo.git.add(changelog)
repo.git.commit(m="Update changelog")
print "Updated changelog on branch %s" % branch
def end_common(self, mode, version):
pass
def refhead(repo):
......
#!/usr/bin/env python
import sys
#http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
def query_yes_no(question, default="yes"):
"""Ask a yes/no question via raw_input() and return their answer.
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits <Enter>.
It must be "yes" (the default), "no" or None (meaning
an answer is required of the user).
The "answer" return value is one of "yes" or "no".
"""
valid = {"yes":True, "y":True, "ye":True,
"no":False, "n":False}
if default == None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
sys.stdout.write(question + prompt)
choice = raw_input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' "\
"(or 'y' or 'n').\n")
def query_action(question, default="yes", action=None):
answer = query_yes_no(question, default)
if answer and action is not None:
action()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment