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(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 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 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 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 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 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())