def prep_commit(self, new_rev, subdir=None): """ Caller should ensure correct cwd. Returns list of newly created files. """ if not subdir: subdir = self.subdir self.scmlogs.annotate("cwd is %s" % os.getcwd()) newly_created = [] if not os.path.exists('a'): newly_created.append('a') if not os.path.exists(subdir): os.mkdir(subdir) # This will take care of adding subdir/b too newly_created.append(subdir) for fname in ('a', subdir + '/b'): file_write_legacy(fname, new_rev) self.scmlogs.annotate("Wrote %s to %s" % (new_rev, fname)) # we never commit through symlink 'c' but instead see the updated # revision through the symlink if not os.path.lexists('c'): os.symlink('a', 'c') newly_created.append('c') return newly_created
def create_repo(self): os.makedirs(self.repo_path) os.chdir(self.repo_path) self.safe_run('init') out = "[ui]\nusername = %s\n" % self.name_and_email file_write_legacy('.hg/hgrc', out) self.wdir = self.repo_path print("created repo %s" % self.repo_path)
def create_repo(self): quietrun('svnadmin create ' + self.repo_path) # allow revprop changes to explicitly set svn:date hook = self.repo_path + '/hooks/pre-revprop-change' file_write_legacy(hook, "#!/bin/sh\nexit 0;\n") sta = os.stat(hook) os.chmod(hook, sta.st_mode | stat.S_IEXEC) print("created repo %s" % self.repo_path)
def test_file_conflicts_revision(self): fix = self.fixtures fix.create_commits(2) repo_path = fix.repo_path os.chdir(repo_path) os.mkdir("test") file_write_legacy("test/myfile.txt", "just for testing") fix.safe_run('add test') fix.safe_run('commit -m "added tests"') fix.safe_run('tag test') self.tar_scm_std("--revision", 'test')
def test_tar_scm_finalize(self): wdir = self.pkgdir info = os.path.join(wdir, "test.obsinfo") print("INFOFILE: '%s'" % info) os.chdir(self.pkgdir) out_str = "name: pkgname\n" \ "version: 0.1.1\n" \ "mtime: 1476683264\n" \ "commit: fea6eb5f43841d57424843c591b6c8791367a9e5\n" file_write_legacy(info, out_str) src_dir = os.path.join(wdir, "pkgname") os.mkdir(src_dir) self.tar_scm_std() self.assertTrue(os.path.isdir(src_dir))
def create_commit_unicode(self, wdir=None): self.scmlogs.annotate("Creating commit with unicode commit message") if wdir is None: wdir = self.wdir os.chdir(wdir) new_rev = self.next_commit_rev(wdir) fname = 'd' file_write_legacy(fname, new_rev) self.scmlogs.annotate("Wrote %s to %s" % (new_rev, fname)) self.safe_run('add .') date = self.get_committer_date() self.safe_run('commit -m"füfüfü nününü %d" %s' % (new_rev, date)) self.record_rev(new_rev, wdir) self.scmlogs.annotate("Created 1 commit; now at %s" % (new_rev))
def test_osc_reset_hard(self): fix = self.fixtures fix.commit_file_with_tag('0.0.1', 'file.1') fix.commit_file_with_tag('0.0.2', 'file.2') fix.remove('file.2') fix.commit_file_with_tag('0.0.3', 'file.3') fix.commit_file_with_tag('0.0.4', 'file.4') # prepare local cache like osc would do # otherwise the git repo would only contain the .git dir and # git._stash_and_merge() would not be executed repo_dir = os.path.join(self.pkgdir, 'repo') fix.safe_run('clone %s %s' % (fix.wdir, repo_dir)) test_txt = os.path.join(repo_dir, 'test.txt') fix.touch(test_txt) file4 = os.path.join(repo_dir, 'file.4') file_write_legacy(file4, "just for testing") # disable cachedirectory (would not be used with osc by default) os.environ['CACHEDIRECTORY'] = "" # enable osc mode os.environ['OSC_VERSION'] = "1" self.tar_scm_std("--revision", '0.0.3', '--version', '0.0.3') # reset osc mode del os.environ['OSC_VERSION'] # check result expected = [ 'repo-0.0.3', 'repo-0.0.3/a', 'repo-0.0.3/c', 'repo-0.0.3/file.1', 'repo-0.0.3/file.3', 'repo-0.0.3/subdir', 'repo-0.0.3/subdir/b', 'repo-0.0.3/test.txt' ] tar = os.path.join(self.outdir, 'repo-0.0.3.tar') self.assertTarIsDeeply(tar, expected) cwd = os.getcwd() os.chdir(repo_dir) status = fix.safe_run('status -s') os.chdir(cwd) self.assertTrue(status[0] == b' M file.4\n?? test.txt\n')
def test_scm_tar_invalid_params(self): tc_name = inspect.stack()[0][3] cl_name = self.__class__.__name__ scm_object = TarSCM.scm.Tar(self.cli, self.tasks) wdir = os.path.join(self.tmp_dir, cl_name, tc_name) os.makedirs(os.path.join(wdir, 'test')) info = os.path.join(wdir, "test.obsinfo") print("INFOFILE: '%s'" % info) # check for slash in name string = "name: test/test\n" \ "version: 0.1.1\n" \ "mtime: 1476683264\n" \ "commit: fea6eb5f43841d57424843c591b6c8791367a9e5\n" file_write_legacy(info, string) os.chdir(wdir) six.assertRaisesRegex(self, SystemExit, re.compile("name in obsinfo contains '/'."), scm_object.fetch_upstream) # check for slash in version string = "name: test\n" \ "version: a/0.1.1\n" \ "mtime: 1476683264\n" \ "commit: fea6eb5f43841d57424843c591b6c8791367a9e5\n" file_write_legacy(info, string) os.chdir(wdir) six.assertRaisesRegex( self, SystemExit, re.compile("verion in obsinfo contains '/' or '..'."), scm_object.fetch_upstream) # check for .. in version string = "name: test\n" \ "version: ..0.1.1\n" \ "mtime: 1476683264\n" \ "commit: fea6eb5f43841d57424843c591b6c8791367a9e5\n" file_write_legacy(info, string) os.chdir(wdir) six.assertRaisesRegex( self, SystemExit, re.compile("verion in obsinfo contains '/' or '..'."), scm_object.fetch_upstream)
def annotate(self, msg): print(msg) file_write_legacy(self.current_log_path, '# ' + msg + "\n", 'a')