def test_init_specified_directory(self): """Initialize a Git repository in another directory. """ with Tempdir(cwd=True) as tempdir: directory = join(tempdir, "repo") git = Git(directory) git.init(quiet=True) self.assertEquals(directory, git.git_work_tree) self.assertEquals(join(directory, ".git"), git.git_dir) self.assertTrue(isdir(join(directory, ".git"))) git.destroy() self.assertFalse(isdir(directory)) self.assertTrue(isdir(tempdir))
def test_init_working_directory(self): """Initialize a Git repository in the working directory. """ with Tempdir(cwd=True) as tempdir: git = Git() self.assertEquals(tempdir, git.git_work_tree) self.assertEquals(join(tempdir, ".git"), git.git_dir) git.init(quiet=True) self.assertEquals(tempdir, git.git_work_tree) self.assertEquals(join(tempdir, ".git"), git.git_dir) self.assertTrue(isdir(join(tempdir, ".git"))) git.destroy() self.assertFalse(isdir(tempdir))
def setUp(self): """Clone the initial CVS repository into a temporary directory and change the working directory to the new work tree. """ self.oldcwd = getcwd() self.tempdir = tempfile.mkdtemp() self.cvsroot = join(self.tempdir, 'cvs') self.worktree = join(self.tempdir, 'git') # Clone the initial CVS repository. TarFile('cvsroot').extract(self.cvsroot) TarFile('import').extract(self.cvsroot) chdir(self.tempdir) self.assertEquals(Clone().eval('--quiet', '--no-skip-latest', join(self.cvsroot, 'src'), self.worktree), 0) # Enter the work tree and make sure the clone was successful before # running the actual test case. chdir(self.worktree) self.assertEquals(Verify().eval(), 0) # Verify the intial Git state after cloning from "cvs import". self.git = Git(self.worktree) self.assertEquals( ['21d3c522acefc5d240848876968504d8ea85347f'], split(self.git.rev_list('HEAD')))
def test_init_bare_working_directory(self): """Initialize a bare repository in the working directory. """ with Tempdir(cwd=True) as tempdir: git = Git() self.assertEquals(tempdir, git.git_work_tree) self.assertEquals(join(tempdir, ".git"), git.git_dir) git.init(bare=True, quiet=True) self.assertEquals(None, git.git_work_tree) self.assertEquals(tempdir, git.git_dir) self.assertFalse(isdir(join(tempdir, ".git"))) self.assertTrue(isfile(join(tempdir, "config"))) self.assertTrue(isdir(join(tempdir, "objects"))) git.destroy() self.assertFalse(isdir(tempdir))
def test_config_set_and_get(self): """Set and get per-repository config values. """ with Tempdir(cwd=True) as tempdir: git = Git() self.assertEquals(None, git.config_get("foo.bar")) git.init(quiet=True) git.config_set("foo.bar", "baz") self.assertEquals("baz", git.config_get("foo.bar"))
def __init__(self, directory=None): self.git = Git(directory) self.branch = 'refs/heads/cvs/HEAD' self._cvs = None self._config = {}
class Conduit(object): """CVS-to-Git conduit logic """ def __init__(self, directory=None): self.git = Git(directory) self.branch = 'refs/heads/cvs/HEAD' self._cvs = None self._config = {} def config_get(self, varname): """Get a Git variable from the 'cvs' section """ if self._config.has_key(varname): return self._config[varname] else: value = self.git.config_get('cvs.' + varname) self._config[varname] = value return value def config_set(self, varname, value): """Set a Git variable in the 'cvs' section """ self.git.config_set('cvs.' + varname, value) self._config[varname] = value def get_source(self): """Get the CVS repository source path """ source = self.config_get('source') if source is None: raise NoSourceError return source def set_source(self, directory): """Set the CVS repository source path """ self.config_set('source', directory) source = property(get_source, set_source) def get_domain(self): return self.config_get('domain') def set_domain(self, directory): self.config_set('domain', directory) domain = property(get_domain, set_domain) def get_cvs(self): if self._cvs == None: filename = os.path.join(self.git.git_dir, 'cvsgit.db') metadb = MetaDb(filename) self._cvs = CVS(self.source, metadb) return self._cvs cvs = property(get_cvs) def init(self, repository, domain=None, bare=False, quiet=True): self.git.init(bare=bare, quiet=quiet) if not self.git.is_bare() and \ self.git.config_get('branch.master.remote') == None: self.git.config_set('branch.master.remote', '.') self.git.config_set('branch.master.merge', self.branch) self.git.config_set('branch.master.rebase', 'true') self.source = repository if domain: self.domain = domain def fetch(self, limit=None, quiet=True, verbose=False, authors=None, stop_on_unknown_author=False): """Fetch new changesets into the CVS tracking branch. """ if quiet or verbose: progress = None else: progress = Progress() self.cvs.fetch(progress=progress, limit=limit) # XXX: Should not access private self.cvs.metadb. if authors and stop_on_unknown_author: unknown = [] for author in self.cvs.metadb.all_authors(): if not authors.has_key(author): unknown.append(author) if len(unknown) > 0: raise UnknownAuthorFullnames(unknown) self.git.import_changesets(self.cvs.changesets(), self.branch, domain=self.domain, limit=limit, verbose=verbose, progress=progress, total=self.cvs.count_changesets(), authors=authors, stop_on_unknown_author=\ stop_on_unknown_author) def pull(self, limit=None, quiet=True, verbose=False, authors=None, stop_on_unknown_author=False): self.fetch(limit=limit, quiet=quiet, verbose=verbose, authors=authors, stop_on_unknown_author=\ stop_on_unknown_author) args = [] if quiet: args.append('--quiet') # XXX: --quiet is not enough if branch.<branch>.rebase is true #self.git.pull(*args) import subprocess self.git.check_command('pull', *args, stdout=subprocess.PIPE)
class Test(unittest.TestCase): def setUp(self): """Clone the initial CVS repository into a temporary directory and change the working directory to the new work tree. """ self.oldcwd = getcwd() self.tempdir = tempfile.mkdtemp() self.cvsroot = join(self.tempdir, 'cvs') self.worktree = join(self.tempdir, 'git') # Clone the initial CVS repository. TarFile('cvsroot').extract(self.cvsroot) TarFile('import').extract(self.cvsroot) chdir(self.tempdir) self.assertEquals(Clone().eval('--quiet', '--no-skip-latest', join(self.cvsroot, 'src'), self.worktree), 0) # Enter the work tree and make sure the clone was successful before # running the actual test case. chdir(self.worktree) self.assertEquals(Verify().eval(), 0) # Verify the intial Git state after cloning from "cvs import". self.git = Git(self.worktree) self.assertEquals( ['21d3c522acefc5d240848876968504d8ea85347f'], split(self.git.rev_list('HEAD'))) def tearDown(self): """Return to the original working directory and remove the whole temporary directory. """ # Ensure that the working copy is the same as cloning from CVS at # the end of each test fixture. self.assertEquals(Verify().eval(), 0) # Restore the original working directory. chdir(self.oldcwd) if isdir(self.tempdir): shutil.rmtree(self.tempdir) def test_initial_clone(self): """Pull without changes in CVS does nothing. Running "git cvs pull" right after an initial "git cvs clone" should not change the working copy in any way, even if an RCS file has an updated timestamp and is therefore parsed again. """ touch_existing(join(self.cvsroot, 'src', 'file_a,v')) old_content = directory_listing(self.worktree) with redirect_stdout() as stdout: self.assertEquals(pull().eval('--no-skip-latest'), 0) self.assertEquals(stdout.getvalue(), re.sub('^\s*', '', """\ Collecting RCS files: 1 Parsing RCS files: done. (1/1) Processing changes: done. (0/0) """, 0, re.MULTILINE)) new_content = directory_listing(self.worktree) self.assertEquals(old_content, new_content) def test_pull_new_file(self): """Pull a change that adds a new file. """ TarFile('add-file_b').extract(self.cvsroot) self.assertEquals(isfile('file_a'), True) self.assertEquals(isfile('file_b'), False) with redirect_stdout() as stdout: self.assertEquals(pull().eval('--no-skip-latest'), 0) self.assertEquals( re.sub('^\s*', '', """\ Collecting RCS files: 2 Parsing RCS files: done. (1/1) Processing changes: done. (1/1) Importing changesets: done. (1/1) """, 0, re.MULTILINE), stdout.getvalue()) self.assertEquals(isfile('file_b'), True) self.assertEquals( ['675ccc10b5cdca1ead0eec6020a16e3d51b8e548', '21d3c522acefc5d240848876968504d8ea85347f'], split(self.git.rev_list('HEAD'))) def test_incomplete_commit(self): """Incomplete change sets are ignored by default. """ TarFile('add-file_b').extract(self.cvsroot) TarFile('split-commit-part1').extract(self.cvsroot) with redirect_stdout() as stdout: self.assertEquals(pull().eval(), 0) self.assertEquals( ['Collecting RCS files: 2', 'Parsing RCS files: done. (2/2)', 'Processing changes: done. (3/3)', 'Retained changesets: 1', 'Importing changesets: 50% (1/2)', 'Importing changesets: done. (2/2)'], splitlines(stdout.getvalue())) self.assertEquals( ['24231f1cd29a5e1caaf9c0167283b8aa5955ea7f', '8d60be7401bafc50256ec624d1aa2ef3b63a2a41', '21d3c522acefc5d240848876968504d8ea85347f'], split(self.git.rev_list('HEAD')))