def test_populate_super_ref2(self): cmdx(giftp, "init", "--sub", cwd=superp) # commit --sub should populate super/head cmdx(giftp, *ident_args, "commit", "--sub", cwd=superp) self._check_initial_superhead() head_of_bar = cmdx(giftp, "rev-parse", "refs/remotes/super/head", cwd=subbarp) state0 = fread(pjoin(superp, ".gift-refs")) self._add_file_to_subbar() cmdx(giftp, *ident_args, "commit", "--sub", cwd=superp) head1 = cmdx(giftp, "rev-parse", "refs/remotes/super/head", cwd=subbarp) self.assertNotEqual(head_of_bar, head1) state1 = fread(pjoin(superp, ".gift-refs")) self.assertNotEqual(state0, state1) # changing HEAD in super repo should repopulate super/head ref in sub repo cmdx(giftp, "reset", "HEAD~", cwd=superp) head2 = cmdx(giftp, "rev-parse", "refs/remotes/super/head", cwd=subbarp) self.assertNotEqual(head_of_bar, head2)
def test_opt_big_c(self): with tempfile.TemporaryDirectory() as tmpdir: out = cmdout(giftp, '-C', this_base, '--git-dir=' + pjoin('testdata', 'supergit'), '--work-tree=' + pjoin("testdata", 'super'), "ls-files", cwd=tmpdir) self.assertEqual(['.gift', 'imsuperman'], out)
def _clean_case(): for d in ("empty", ): p = pjoin(this_base, "testdata", d) if os.path.exists(pjoin(p, ".git")): cmdx(origit, "reset", "--hard", cwd=p) cmdx(origit, "clean", "-dxf", cwd=p) force_remove(pjoin(this_base, "testdata", "empty", "bar")) force_remove(pjoin(this_base, "testdata", "empty", ".git")) force_remove(pjoin(this_base, "testdata", "super", ".git")) force_remove(barp) cmdx(origit, "reset", "testdata", cwd=this_base) cmdx(origit, "checkout", "testdata", cwd=this_base) cmdx(origit, "clean", "-dxf", cwd=this_base)
def test_clone_not_in_git(self): with tempfile.TemporaryDirectory() as tmpdir: cmdx(giftp, "clone", bargitp, "bar", cwd=tmpdir) self._gitoutput([giftp, "ls-files"], ["bar"], cwd=pjoin(tmpdir, 'bar')) self._fcontent("bar\n", tmpdir, "bar/bar")
def test_init_4_already_checkout(self): cmdx(origit, "init", "--bare", self.sb['env']['GIT_DIR']) cmdx(origit, "remote", "add", self.sb['upstream']['name'], self.sb['upstream']['url'], env=self.sb['bareenv']) cmdx(origit, "fetch", self.sb['upstream']['name'], env=self.sb['bareenv'], cwd=superp) os.makedirs(self.sb['env']['GIT_WORK_TREE'], mode=0o755) cmdx(origit, "checkout", self.sb['upstream']['branch'], env=self.sb['env']) self._fcontent("bar\n", subbarp, "bar") os.unlink(pjoin(subbarp, "bar")) # init --sub should not checkout again to modify work tree cmdx(giftp, "init", "--sub", cwd=superp) self._nofile(subbarp, "bar")
def setUp(self): self.maxDiff = None _clean_case() # .git can not be track in a git repo. # need to manually create it. fwrite(pjoin(this_base, "testdata", "super", ".git"), "gitdir: ../supergit")
def _add_commit_to_bar_from_other_clone(self): cmdx(origit, "clone", bargitp, barp) fwrite(pjoin(barp, "for_fetch"), "for_fetch") cmdx(origit, "add", "for_fetch", cwd=barp) cmdx(origit, *ident_args, "commit", "-m", "add for_fetch", cwd=barp) cmdx(origit, "push", "origin", "master", cwd=barp) headhash = cmd0(origit, "rev-parse", "HEAD", cwd=barp) return headhash
def setUp(self): super(TestGiftPartialInit, self).setUp() gg = Gift(GitOpt().update({ 'startpath': [superp], 'git_dir': None, 'work_tree': None, })) gg.init_git_config() rel, sb = gg.get_subrepo_config(pjoin(superp, "foo/bar")) self.gg = gg self.sb = sb self.rel = rel
def test_get_subrepo_config(self): gg = Gift(GitOpt().update({ 'startpath': [superp], 'git_dir': None, 'work_tree': None, })) gg.init_git_config() rel, sb = gg.get_subrepo_config(pjoin(superp, "f")) self.assertEqual(('', None), (rel, sb), "inexistent path") rel, sb = gg.get_subrepo_config(pjoin(superp, "foo")) self.assertEqual(('', None), (rel, sb), "inexistent path foo") rel, sb = gg.get_subrepo_config(pjoin(superp, "foo/bar")) self.assertEqual('foo/bar', rel) self.assertEqual( { 'bareenv': { 'GIT_DIR': this_base + '/testdata/supergit/gift/subdir/foo/bar' }, 'dir': 'foo/bar', 'env': { 'GIT_DIR': this_base + '/testdata/supergit/gift/subdir/foo/bar', 'GIT_WORK_TREE': this_base + '/testdata/super/foo/bar' }, 'refhead': 'refs/gift/sub/foo/bar', 'sub_gitdir': 'gift/subdir/foo/bar', 'upstream': { 'branch': 'master', 'name': 'origin', 'url': '../bargit' } }, sb)
def test_clone_in_other_repo(self): cmdx(giftp, "init", cwd=emptyp) cmdx(giftp, "clone", "../bargit", "bar", cwd=emptyp) self._gitoutput([giftp, "ls-files"], ["bar"], cwd=pjoin(emptyp, "bar")) self._fcontent("bar\n", emptyp, "bar/bar")
def _fcontent(self, txt, *ps): self.assertTrue(os.path.isfile(pjoin(*ps)), pjoin(*ps) + " should exist") actual = fread(pjoin(*ps)) self.assertEqual(txt, actual, "check file content")
def _nofile(self, *ps): self.assertFalse(os.path.isfile(pjoin(*ps)), "no file in " + pjoin(*ps))
def _add_file_to_subbar(self): fwrite(pjoin(subbarp, "newbar"), "newbar") cmdx(giftp, "add", "newbar", cwd=subbarp) cmdx(giftp, *ident_args, "commit", "-m", "add newbar", cwd=subbarp)
from k3handy import cmdtty from k3handy import cmdx from k3handy import dd from k3handy import pjoin gift = imp.load_source('gift', './gift') CalledProcessError = gift.CalledProcessError Git = gift.Git Gift = gift.Gift # root of this repo this_base = os.path.dirname(__file__) giftp = pjoin(this_base, "gift") origit = "git" emptyp = pjoin(this_base, "testdata", "empty") superp = pjoin(this_base, "testdata", "super") supergitp = pjoin(this_base, "testdata", "supergit") subbarp = pjoin(this_base, "testdata", "super", "foo", "bar") subwowp = pjoin(this_base, "testdata", "super", "foo", "wow") bargitp = pjoin(this_base, "testdata", "bargit") barp = pjoin(this_base, "testdata", "bar") execpath = cmd0(origit, '--exec-path') ident_args = [ '-c', 'user.name=fooUser',