dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00317
Re: [PATCH] repo: fix error in repo.init{, _bare} where all repositories were marked bare
On Sun, 2010-12-05 at 09:38 -0600, Augie Fackler wrote:
> Not awake. Ignore this too (the other one where I finally *didn't* screw up already arrived here.)
Heh, join the club. :-) Thanks for the patch, it's been merged into
trunk.
Cheers,
Jelmer
> On Dec 5, 2010, at 9:36 AM, Augie Fackler wrote:
>
> > # HG changeset patch
> > # User Augie Fackler <durin42@xxxxxxxxx>
> > # Date 1290987945 -21600
> > # Node ID 93fdf6e95f5115e811d3d15fdce9f3730c1c2e84
> > # Parent 1acb5f1c39c3873890372f9f76d873d35f576002
> > repo: fix error in repo.init{,_bare} where all repositories were marked bare
> >
> > Includes simple tests to verify bare = (true|false) in .git/config is
> > correct.
> >
> > Change-Id: I607d16ae845c61eb1d3de4753dd810476735b5f1
> >
> > diff --git a/dulwich/repo.py b/dulwich/repo.py
> > --- a/dulwich/repo.py
> > +++ b/dulwich/repo.py
> > @@ -763,13 +763,13 @@
> > self.object_store = object_store
> > self.refs = refs
> >
> > - def _init_files(self):
> > + def _init_files(self, bare):
> > """Initialize a default set of named files."""
> > self._put_named_file('description', "Unnamed repository")
> > self._put_named_file('config', ('[core]\n'
> > 'repositoryformatversion = 0\n'
> > 'filemode = true\n'
> > - 'bare = ' + str(self.bare).lower() + '\n'
> > + 'bare = ' + str(bare).lower() + '\n'
> > 'logallrefupdates = true\n'))
> > self._put_named_file(os.path.join('info', 'exclude'), '')
> >
> > @@ -1187,23 +1187,27 @@
> > return "<Repo at %r>" % self.path
> >
> > @classmethod
> > + def _init_maybe_bare(cls, path, bare):
> > + for d in BASE_DIRECTORIES:
> > + os.mkdir(os.path.join(path, *d))
> > + DiskObjectStore.init(os.path.join(path, OBJECTDIR))
> > + ret = cls(path)
> > + ret.refs.set_symbolic_ref("HEAD", "refs/heads/master")
> > + ret._init_files(bare)
> > + return ret
> > +
> > + @classmethod
> > def init(cls, path, mkdir=False):
> > if mkdir:
> > os.mkdir(path)
> > controldir = os.path.join(path, ".git")
> > os.mkdir(controldir)
> > - cls.init_bare(controldir)
> > + cls._init_maybe_bare(controldir, False)
> > return cls(path)
> >
> > @classmethod
> > def init_bare(cls, path):
> > - for d in BASE_DIRECTORIES:
> > - os.mkdir(os.path.join(path, *d))
> > - DiskObjectStore.init(os.path.join(path, OBJECTDIR))
> > - ret = cls(path)
> > - ret.refs.set_symbolic_ref("HEAD", "refs/heads/master")
> > - ret._init_files()
> > - return ret
> > + return cls._init_maybe_bare(path, True)
> >
> > create = init_bare
> >
> > @@ -1254,5 +1258,5 @@
> > ret.object_store.add_object(obj)
> > for refname, sha in refs.iteritems():
> > ret.refs[refname] = sha
> > - ret._init_files()
> > + ret._init_files(True)
> > return ret
> > diff --git a/dulwich/tests/test_repository.py b/dulwich/tests/test_repository.py
> > --- a/dulwich/tests/test_repository.py
> > +++ b/dulwich/tests/test_repository.py
> > @@ -66,24 +66,35 @@
> > finally:
> > f.close()
> >
> > - def _check_repo_contents(self, repo):
> > - self.assertTrue(repo.bare)
> > + def _check_repo_contents(self, repo, expect_bare):
> > + self.assertEquals(expect_bare, repo.bare)
> > self.assertFileContentsEqual('Unnamed repository', repo, 'description')
> > self.assertFileContentsEqual('', repo, os.path.join('info', 'exclude'))
> > self.assertFileContentsEqual(None, repo, 'nonexistent file')
> > + barestr = 'bare = %s' % str(expect_bare).lower()
> > + self.assertTrue(barestr in repo.get_named_file('config').read())
> >
> > - def test_create_disk(self):
> > + def test_create_disk_bare(self):
> > tmp_dir = tempfile.mkdtemp()
> > try:
> > repo = Repo.init_bare(tmp_dir)
> > self.assertEquals(tmp_dir, repo._controldir)
> > - self._check_repo_contents(repo)
> > + self._check_repo_contents(repo, True)
> > + finally:
> > + shutil.rmtree(tmp_dir)
> > +
> > + def test_create_disk_non_bare(self):
> > + tmp_dir = tempfile.mkdtemp()
> > + try:
> > + repo = Repo.init(tmp_dir)
> > + self.assertEquals(os.path.join(tmp_dir, '.git'), repo._controldir)
> > + self._check_repo_contents(repo, False)
> > finally:
> > shutil.rmtree(tmp_dir)
> >
> > def test_create_memory(self):
> > repo = MemoryRepo.init_bare([], {})
> > - self._check_repo_contents(repo)
> > + self._check_repo_contents(repo, True)
> >
> >
> > class RepositoryTests(TestCase):
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~dulwich-users
> > Post to : dulwich-users@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~dulwich-users
> > More help : https://help.launchpad.net/ListHelp
>
Attachment:
signature.asc
Description: This is a digitally signed message part
References