diff --git a/gitFunctions.py b/gitFunctions.py index 61b0e41..209f6d8 100644 --- a/gitFunctions.py +++ b/gitFunctions.py @@ -115,6 +115,14 @@ def replaceauthor(author, email): shell.execute("git config --replace-all user.name " + shell.quote(author)) shell.execute("git config --replace-all user.email " + email) + @staticmethod + def checkbranchname(branchname): + exitcode = shell.execute("git check-ref-format --normalize refs/heads/" + branchname) + if exitcode is 0: + return True + else: + return False + @staticmethod def branch(branchname): branchexist = shell.execute("git show-ref --verify --quiet refs/heads/" + branchname) diff --git a/migration.py b/migration.py index 94cd1a2..942ebe5 100644 --- a/migration.py +++ b/migration.py @@ -116,6 +116,23 @@ def parsecommandline(): configuration.setconfigfile(arguments.configfile) +def validate(): + config = configuration.get() + streamname = config.streamname + branchname = streamname + "_branchpoint" + previousstreamname = config.previousstreamname + offendingbranchname = None + if not Commiter.checkbranchname(streamname): + offendingbranchname = streamname + elif not Commiter.checkbranchname(branchname): + offendingbranchname = branchname + elif not Commiter.checkbranchname(previousstreamname): + offendingbranchname = previousstreamname + if offendingbranchname: + sys.exit(offendingbranchname + " is not a valid git branch name - consider renaming the stream") + + if __name__ == "__main__": parsecommandline() + validate() migrate() diff --git a/tests/test_gitFunctions.py b/tests/test_gitFunctions.py index 2fcc314..aa79a6e 100644 --- a/tests/test_gitFunctions.py +++ b/tests/test_gitFunctions.py @@ -174,6 +174,18 @@ def test_filterignore(self): self.assertEqual(jar, lines[0].strip()) self.assertEqual(zip, lines[1].strip()) + def test_checkbranchname_expect_valid(self): + with testhelper.createrepo(folderprefix="gitfunctionstestcase_"): + self.assertEqual(True, Commiter.checkbranchname("master"), "master should be a valid branch name") + + def test_checkbranchname_quoted_expect_invalid(self): + with testhelper.createrepo(folderprefix="gitfunctionstestcase_"): + self.assertEqual(False, Commiter.checkbranchname("'master pflaster'"), "'master pflaster' should not be a valid branch name") + + def test_checkbranchname_unquoted_expect_invalid(self): + with testhelper.createrepo(folderprefix="gitfunctionstestcase_"): + self.assertEqual(False, Commiter.checkbranchname("master pflaster"), "master pflaster should not be a valid branch name") + def simulateCreationAndRenameInGitRepo(self, originalfilename, newfilename): open(originalfilename, 'a').close() # create file Initializer.initialcommit()