def simulateCreationAndRenameInGitRepo(self, originalfilename, newfilename): open(originalfilename, 'a').close() # create file Initializer.initialcommit() Commiter.pushmaster() os.rename(originalfilename, newfilename) # change capitalization shell.execute("git add -A") Commiter.handle_captitalization_filename_changes()
def test_CreationOfGitIgnore_DoesntExist_ShouldGetCreated(self): with testhelper.mkchdir("aFolder") as folder: configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").build() ignore = '.gitignore' Initializer().createrepo() Initializer.createignore() gitignorepath = os.path.join(os.getcwd(), ignore) self.assertTrue(os.path.exists(gitignorepath))
def initialize(config): directory = config.workDirectory if os.path.exists(directory): sys.exit("Configured directory already exists, please make sure to use a non-existing directory") os.mkdir(directory) os.chdir(directory) git = Initializer(config) git.initalize() RTCInitializer.initialize(config) git.initialcommitandpush()
def test_CreationOfGitIgnore_ExistAlready_ShouldntGetCreated(self): with testhelper.mkchdir("aFolder") as folder: configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").build() ignore = '.gitignore' existing_git_ignore_entry = "test" Initializer().createrepo() with open(ignore, 'w') as gitIgnore: gitIgnore.write(existing_git_ignore_entry) Initializer.createignore() with open(ignore, 'r') as gitIgnore: for line in gitIgnore.readlines(): self.assertEqual(existing_git_ignore_entry, line)
def test_CreationOfGitattributes_ExistAlready_ShouldntGetCreated(self): with testhelper.mkchdir("aFolder") as folder: configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").setgitattributes(["# comment", "*.sql text"]).build() attributes = '.gitattributes' existing_git_attribute_entry = "* text=auto" Initializer().createrepo() with open(attributes, 'w') as gitattributes: gitattributes.write(existing_git_attribute_entry) Initializer.createattributes() with open(attributes, 'r') as gitattributes: for line in gitattributes.readlines(): self.assertEqual(existing_git_attribute_entry, line)
def createrepo(reponame="test.git", folderprefix="rtc2test_case"): repodir = tempfile.mkdtemp(prefix=folderprefix) configuration.config = Builder().setworkdirectory(repodir).setgitreponame(reponame).build() initializer = Initializer() previousdir = os.getcwd() os.chdir(repodir) initializer.initalize() try: yield finally: os.chdir(previousdir) shutil.rmtree(repodir, ignore_errors=True) # on windows folder remains in temp, git process locks it
def test_CreationOfGitattributes_DoesntExist_ShouldGetCreated(self): with testhelper.mkchdir("aFolder") as folder: configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").setgitattributes(["# comment", "* text=auto"]).build() attributes = '.gitattributes' Initializer().createrepo() Initializer.createattributes() gitattributespath = os.path.join(os.getcwd(), attributes) self.assertTrue(os.path.exists(gitattributespath)) with open(gitattributespath, 'r') as gitattributes: lines = gitattributes.readlines() self.assertEqual(2, len(lines)) self.assertEquals('# comment\n', lines[0]) self.assertEquals('* text=auto\n', lines[1])
def resume(): shouter.shout("Found existing git repo in work directory, resuming migration...") config = configuration.get() os.chdir(config.workDirectory) os.chdir(config.clonedGitRepoName) if Differ.has_diff(): sys.exit("Your git repo has some uncommited changes, please add/remove them manually") RTCLogin.loginandcollectstreamuuid() Initializer.preparerepo() if config.previousstreamname: prepare() else: WorkspaceHandler().load()
def createrepo(reponame="test.git", folderprefix="rtc2test_case"): repodir = tempfile.mkdtemp(prefix=folderprefix) configuration.config = Builder().setworkdirectory(repodir).setgitreponame( reponame).build() initializer = Initializer() previousdir = os.getcwd() os.chdir(repodir) initializer.initalize() try: yield finally: os.chdir(previousdir) shutil.rmtree( repodir, ignore_errors=True ) # on windows folder remains in temp, git process locks it
def test_handleignore_global_extensions(self): with testhelper.mkchdir("aFolder") as folder: # create test repo configuration.config = Builder().setworkdirectory( folder).setgitreponame("test.git").setignorefileextensions( ".zip; .jar").build() ignore = ".gitignore" Initializer().createrepo() # simulate addition of .zip and .jar files zip = "test.zip" with open(zip, 'w') as testzip: testzip.write("test zip content") jar = "test.jar" with open(jar, 'w') as testjar: testjar.write("test jar content") # do the filtering Commiter.handleignore() # check output of .gitignore with open(ignore, 'r') as gitIgnore: lines = gitIgnore.readlines() self.assertEqual(2, len(lines)) lines.sort() # the ignore should not be recursive: self.assertEqual('/' + jar, lines[0].strip()) self.assertEqual('/' + zip, lines[1].strip())
def test_CreationOfGitIgnore_DoesntExist_ShouldGetCreated_WithDirectories(self): with testhelper.mkchdir("aFolder") as folder: configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").setignoredirectories(["projectX/dist", "projectZ/out"]).build() ignore = '.gitignore' Initializer().createrepo() Initializer.createignore() gitignorepath = os.path.join(os.getcwd(), ignore) self.assertTrue(os.path.exists(gitignorepath)) expectedlines = [] expectedlines.append(".jazz5\n") expectedlines.append(".metadata\n") expectedlines.append(".jazzShed\n") expectedlines.append("\n") expectedlines.append("# directories\n") expectedlines.append("/projectX/dist\n") expectedlines.append("/projectZ/out\n") expectedlines.append("\n") with open(gitignorepath, 'r') as gitignore: lines = gitignore.readlines() self.assertEqual(expectedlines, lines)
def initialize(config): directory = config.workDirectory if os.path.exists(directory): sys.exit( "Configured directory already exists, please make sure to use a non-existing directory" ) os.mkdir(directory) os.chdir(directory) git = Initializer(config) git.initalize() RTCInitializer.initialize(config) git.initialcommitandpush()
def test_handleignore_local_jazzignore_expect_delete_gitignore(self): with testhelper.mkchdir("aFolder") as folder: # create a repository with a .jazzignore and .gitignore file configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").build() Initializer().createrepo() subfolder = "aSubFolder" os.mkdir(subfolder) jazzignore = subfolder + os.sep + ".jazzignore" with open(jazzignore, 'w') as testjazzignore: testjazzignore.write("# my ignores\n") testjazzignore.write("core.ignore = {*.pyc}") Commiter.addandcommit(testhelper.createchangeentry(comment="Initial .jazzignore")) gitignore = subfolder + os.sep + ".gitignore" self.assertTrue(os.path.exists(gitignore)) # now remove .jazzignore os.remove(jazzignore) Commiter.handleignore() self.assertFalse(os.path.exists(gitignore))
def test_handleignore_local_jazzignore_expect_empty_gitignore(self): with testhelper.mkchdir("aFolder") as folder: configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").build() Initializer().createrepo() subfolder = "aSubFolder" os.mkdir(subfolder) gitignore = subfolder + os.sep + ".gitignore" with open(gitignore, 'w') as localgitignore: localgitignore.write('\n') localgitignore.write("/*.pyc") jazzignore = subfolder + os.sep + ".jazzignore" with open(jazzignore, 'w') as testjazzignore: testjazzignore.write("# my ignores are empty\n") Commiter.handleignore() self.assertTrue(os.path.exists(gitignore)) gitignorelines = [] with open(gitignore, 'r') as localgitignore: gitignorelines = localgitignore.readlines() self.assertEqual(0, len(gitignorelines))
def test_handleignore_local_jazzignore_expect_new_gitignore(self): with testhelper.mkchdir("aFolder") as folder: configuration.config = Builder().setworkdirectory(folder).setgitreponame("test.git").build() Initializer().createrepo() subfolder = "aSubFolder" os.mkdir(subfolder) jazzignore = subfolder + os.sep + ".jazzignore" with open(jazzignore, 'w') as testjazzignore: testjazzignore.write("# my ignores\n") testjazzignore.write("core.ignore = {*.pyc}") expectedlines = ["\n","/*.pyc\n"] gitignore = subfolder + os.sep + ".gitignore" self.assertFalse(os.path.exists(gitignore)) Commiter.handleignore() self.assertTrue(os.path.exists(gitignore)) gitignorelines = [] with open(gitignore, 'r') as localgitignore: gitignorelines = localgitignore.readlines() self.assertEqual(expectedlines, gitignorelines)
def initialize(): config = configuration.get() directory = config.workDirectory if os.path.exists(directory): sys.exit("Configured directory already exists, please make sure to use a non-existing directory") shouter.shout("Migration will take place in " + directory) os.makedirs(directory) os.chdir(directory) config.deletelogfolder() git = Initializer() git.initalize() RTCInitializer.initialize() if Differ.has_diff(): git.initialcommit() Commiter.pushmaster()