Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subversion support #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ include/
lib/
.Python
bumpversion.egg-info/
*.pyc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm indeed.. It was added by the GitHub windows client... (I'll remove it).

66 changes: 62 additions & 4 deletions bumpversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from datetime import datetime
from difflib import unified_diff
from tempfile import NamedTemporaryFile
from contextlib import contextmanager

import sys
import codecs
Expand All @@ -42,6 +43,18 @@
logger = logging.getLogger("bumpversion.logger")
logger_list = logging.getLogger("bumpversion.list")


@contextmanager
def message_file(message):
try:
f = NamedTemporaryFile('wb', delete=False)
f.write(message.encode('utf-8'))
f.close()
yield f.name
finally:
os.unlink(f.name)


from argparse import _AppendAction
class DiscardDefaultIfSpecifiedAppendAction(_AppendAction):

Expand Down Expand Up @@ -89,6 +102,51 @@ def is_usable(cls):
raise


class Svn(BaseVCS):

_TEST_USABLE_COMMAND = ["svn", "info"]
_COMMIT_COMMAND = ["svn", "commit", "--file"]

@classmethod
def assert_nondirty(cls):
lines = [
line.strip() for line in
subprocess.check_output(
["svn", "status"]).splitlines()
if line.strip()
]

if lines:
raise WorkingDirectoryIsDirtyException(
"Subversion working directory is not clean:\n{}".format(
b"\n".join(lines)))

@classmethod
def latest_tag_info(cls):
return {}

@classmethod
def add_path(cls, path):
pass

@classmethod
def tag(cls, name, message=""):
svn_info = subprocess.check_output(["svn", "info"])
rurl = re.search(r'^relative url: (.*)$', svn_info,
re.M|re.I).groups()[0]
rurl = rurl.split('/trunk')[0]
rurl = rurl.split('/branches')[0]

with message_file(message) as filename:
subprocess.check_output([
"svn",
"copy",
".",
rurl + "/tags/" + name,
"--file=" + filename
])


class Git(BaseVCS):

_TEST_USABLE_COMMAND = ["git", "rev-parse", "--git-dir"]
Expand Down Expand Up @@ -146,7 +204,7 @@ def add_path(cls, path):
subprocess.check_output(["git", "add", "--update", path])

@classmethod
def tag(cls, name):
def tag(cls, name, message=""):
subprocess.check_output(["git", "tag", name])


Expand Down Expand Up @@ -178,10 +236,10 @@ def add_path(cls, path):
pass

@classmethod
def tag(cls, name):
def tag(cls, name, message=""):
subprocess.check_output(["hg", "tag", name])

VCS = [Git, Mercurial]
VCS = [Git, Mercurial, Svn]


def prefixed_environ():
Expand Down Expand Up @@ -985,5 +1043,5 @@ def main(original_args=None):
))

if do_tag:
vcs.tag(tag_name)
vcs.tag(tag_name, message=commit_message)