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

Svn commit on empty repo #132

Open
wants to merge 3 commits into
base: develop
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 config.ini.minimum.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ User=USR
Password=secret
GIT-Reponame = myGitRepo.git
WorkspaceName=ToBeCreatedWorkspaceName
SVNRepoDir = SVNemptyRepoDirectory

[Migration]
# Stream to be migrated, referenced by Name or UUID
Expand Down
2 changes: 2 additions & 0 deletions config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ScmCommand = lscm
# Optional - Set encoding of files (For example encoding = UTF-8)
# See "https://github.com/rtcTo/rtc2git/wiki/Encoding" for further instructions
encoding =
# Optional - Set empty SVN repo directory if you want to commit also on a SVN repo
SVNRepoDir =

[Migration]
# Stream to be migrated, referenced by Name or UUID
Expand Down
13 changes: 11 additions & 2 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def read(configname=None):

workspace = shlex.quote(generalsection['WorkspaceName'])
gitreponame = generalsection['GIT-Reponame']
svnrepodir = shlex.quote(generalsection['SVNRepoDir'])

useexistingworkspace = generalsection.get('useExistingWorkspace', "False")
useprovidedhistory = migrationsection.get('UseProvidedHistory', "False")
Expand Down Expand Up @@ -66,6 +67,7 @@ def read(configname=None):
configbuilder.setignoredirectories(ignoredirectories)
configbuilder.setincludecomponentroots(includecomponentroots).setcommitmessageprefix(commitmessageprefix)
configbuilder.setgitattributes(gitattributes)
configbuilder.setsvnrepodir(svnrepodir)
global config
config = configbuilder.build()
return config
Expand Down Expand Up @@ -141,6 +143,7 @@ def __init__(self):
self.includecomponentroots = ""
self.commitmessageprefix = ""
self.gitattributes = ""
self.svnrepodir = ""

def setuser(self, user):
self.user = user
Expand All @@ -162,6 +165,10 @@ def setworkspace(self, workspace):
self.workspace = workspace
return self

def setsvnrepodir(self, svnrepodir):
self.svnrepodir = svnrepodir
return self

def setworkdirectory(self, workdirectory):
self.workdirectory = workdirectory
return self
Expand Down Expand Up @@ -237,14 +244,15 @@ def build(self):
self.streamname, self.gitreponame, self.useprovidedhistory,
self.useautomaticconflictresolution, self.maxchangesetstoaccepttogether, self.clonedgitreponame, self.rootFolder,
self.previousstreamname, self.ignorefileextensions, self.ignoredirectories, self.includecomponentroots,
self.commitmessageprefix, self.gitattributes)
self.commitmessageprefix, self.gitattributes, self.svnrepodir)


class ConfigObject:
def __init__(self, user, password, repourl, scmcommand, workspace, useexistingworkspace, workdirectory,
initialcomponentbaselines, streamname, gitreponame, useprovidedhistory,
useautomaticconflictresolution, maxchangesetstoaccepttogether, clonedgitreponame, rootfolder, previousstreamname,
ignorefileextensions, ignoredirectories, includecomponentroots, commitmessageprefix, gitattributes):
ignorefileextensions, ignoredirectories, includecomponentroots, commitmessageprefix, gitattributes,
svnrepodir):
self.user = user
self.password = password
self.repo = repourl
Expand All @@ -270,6 +278,7 @@ def __init__(self, user, password, repourl, scmcommand, workspace, useexistingwo
self.includecomponentroots = includecomponentroots
self.commitmessageprefix = commitmessageprefix
self.gitattributes = gitattributes
self.svnrepodir = svnrepodir

def getlogpath(self, filename):
if not self.hasCreatedLogFolder:
Expand Down
5 changes: 4 additions & 1 deletion rtcFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sorter
from configuration import ComponentBaseLineEntry
from gitFunctions import Commiter, Differ

from svnFunctions import svnCommiter

class RTCInitializer:
@staticmethod
Expand Down Expand Up @@ -229,6 +229,9 @@ def acceptchangesintoworkspace(self, changeentries):
self.is_user_aborting(changeentries)
shouter.shout("Accepted change %d/%d into working directory" % (amountofacceptedchanges, amountofchanges))
Commiter.addandcommit(changeEntry)
# SVN support
if self.config.svnrepodir:
svnCommiter.addandcommit(changeEntry)
return amountofacceptedchanges

@staticmethod
Expand Down
38 changes: 38 additions & 0 deletions svnFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
import configuration
import shouter
import shell
from gitFunctions import Commiter

class svnCommiter:

@staticmethod
def getcommitcommand(changeentry, comment):
msg = (comment, "[RTC commit", changeentry.date, "by", changeentry.getgitauthor() + "]")
return "svn commit -m %s" % (shell.quote(" ".join(msg)))

@staticmethod
def addandcommit(changeentry):
config = configuration.get()
if config.svnrepodir:
shouter.shout("[SVN] current dir=%s svndir=%s" % (os.getcwd(), config.svnrepodir))
# 1 - rsync current git dir to svn dir
gitrepodir = os.getcwd()
cmd = "rsync -r %s %s" % (
os.path.join(gitrepodir, config.component2load, "*"),
config.svnrepodir)
shouter.shout("[SVN] %s" % cmd)
shell.execute(cmd)
# 2 - chdir to svnrepo, add and commit
os.chdir(config.svnrepodir)
cmd = "svn add --force * --auto-props --parents --depth infinity -q"
shouter.shout("[SVN] %s" % cmd)
shell.execute(cmd)
comment = Commiter.getcommentwithprefix(changeentry.comment)
cmd = svnCommiter.getcommitcommand(changeentry, comment)
shouter.shout("[SVN] %s" % cmd)
shell.execute(cmd)
shell.execute("svn update")
# 3 - go back to current dir
os.chdir(gitrepodir)

1 change: 1 addition & 0 deletions tests/resources/test_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Directory = /tmp/migration
useExistingWorkspace = True
ScmCommand = scm
encoding = UTF-8
SVNRepoDir =

[Migration]
StreamToMigrate = Superstream
Expand Down
1 change: 1 addition & 0 deletions tests/resources/test_minimum_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ User = miniuser
Password = minisecret
GIT-Reponame = mini.git
WorkspaceName = Miniworkspace
SVNRepoDir =

[Migration]
StreamToMigrate = Ministream