示例#1
0
    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")
示例#2
0
    def test_clone_sub(self):
        cmdx(giftp, "init", cwd=emptyp)
        code, out, err = cmdx(giftp,
                              *ident_args,
                              "clone",
                              "--sub",
                              "../bargit@master",
                              "path/to/bar",
                              cwd=emptyp)
        for l in (
                'GIFT: path/to/bar: add remote: origin ../bargit',
                'GIFT: path/to/bar: fetch origin ../bargit',
                "From ../bargit",
        ):
            self.assertIn(l, "\n".join(err),
                          "it should output fetching status")

        self._gitoutput([giftp, "ls-files"], [
            ".gift",
            ".gift-refs",
            "path/to/bar/bar",
        ],
                        cwd=emptyp)

        self._fcontent("dirs:\n  path/to/bar: ../bargit@master\n", emptyp,
                       ".gift")
        self._fcontent(
            "\n".join([
                "- - path/to/bar",
                "  - 466f0bbdf56b1428edf2aed4f6a99c1bd1d4c8af",
                "",
            ]), emptyp, ".gift-refs")
        self._fcontent("bar\n", emptyp, "path/to/bar/bar")
示例#3
0
    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")
示例#4
0
    def _check_initial_superhead(self):
        _, out, _ = cmdx(giftp,
                         "rev-parse",
                         "refs/remotes/super/head",
                         cwd=subbarp)
        self.assertEqual("466f0bbdf56b1428edf2aed4f6a99c1bd1d4c8af", out[0])

        _, out, _ = cmdx(giftp,
                         "rev-parse",
                         "refs/remotes/super/head",
                         cwd=subwowp)
        self.assertEqual("6bf37e52cbafcf55ff4710bb2b63309b55bf8e54", out[0])
示例#5
0
    def test_fetch_sub(self):

        cmdx(giftp, "init", "--sub", cwd=superp)

        headhash = self._add_commit_to_bar_from_other_clone()

        # we should fetch and got the latest commit.

        cmdx(giftp, "fetch", "--sub", cwd=superp)

        fetched_hash = cmd0(giftp, "rev-parse", "origin/master", cwd=subbarp)

        self.assertEqual(headhash, fetched_hash)
示例#6
0
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)
示例#7
0
    def test_error_output(self):
        e = None
        try:
            cmdx(giftp, "abc")
        except CalledProcessError as ee:
            e = ee

        self.assertEqual(1, e.returncode)
        self.assertEqual([], e.out)
        self.assertEqual("git: 'abc' is not a git command. See 'git --help'.",
                         e.err[0])

        # there should not raw python error returned
        self.assertNotIn('Traceback', "".join(e.out))
        self.assertNotIn('Traceback', "".join(e.err))
示例#8
0
    def test_no_cmd(self):
        e = None
        try:
            cmdx(giftp)
        except CalledProcessError as ee:
            e = ee

        self.assertEqual(1, e.returncode)
        self.assertIn("usage: git", e.out[0], "stderr output git help")
        self.assertIn('Gift extended command:', e.out, "help with gift info")
        self.assertEqual([], e.err)

        # there should not raw python error returned
        self.assertNotIn('Traceback', "".join(e.out))
        self.assertNotIn('Traceback', "".join(e.err))
示例#9
0
    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
示例#10
0
    def test_init_sub(self):
        self._nofile(subbarp, "bar")
        self._nofile(subwowp, "wow")

        for _ in range(2):
            cmdx(giftp, "init", "--sub", cwd=superp)

            self._fcontent("bar\n", subbarp, "bar")
            self._fcontent("wow\n", subwowp, "wow")

            self._gitoutput([giftp, "symbolic-ref", "--short", "HEAD"],
                            ["master"],
                            cwd=subbarp)
            self._gitoutput([giftp, "symbolic-ref", "--short", "HEAD"],
                            ["master"],
                            cwd=subwowp)
            self._gitoutput([giftp, "ls-files"], [".gift", "imsuperman"],
                            cwd=superp)
示例#11
0
    def test_op_in_sub(self):

        cmdx(giftp, "init", "--sub", cwd=superp)

        superhash = cmd0(origit, "rev-parse", "HEAD", cwd=superp)
        dd(superhash)

        gift_super_hash = cmd0(giftp, "rev-parse", "HEAD", cwd=superp)
        self.assertEqual(superhash, gift_super_hash,
                         "gift should get the right super HEAD hash")

        barhash = cmd0(giftp, "rev-parse", "HEAD", cwd=subbarp)
        self.assertNotEqual(barhash, superhash,
                            "gift should get a different hash in sub dir bar")

        self._add_file_to_subbar()

        superhash2 = cmd0(origit, "rev-parse", "HEAD", cwd=superp)
        self.assertEqual(superhash, superhash2,
                         "commit in sub dir should not change super dir HEAD")
示例#12
0
    def test_reset_sub(self):

        cmdx(giftp, "init", "--sub", cwd=superp)
        cmdx(giftp, *ident_args, "commit", "--sub", cwd=superp)

        ori_hash = cmd0(giftp, "rev-parse", "HEAD", cwd=subbarp)

        headhash = self._add_commit_to_bar_from_other_clone()

        # we should fetch and got the latest commit.

        cmdx(giftp, "fetch", "--sub", cwd=superp)
        cmdx(giftp, "merge", "origin/master", cwd=subbarp)
        fetched_hash = cmd0(giftp, "rev-parse", "HEAD", cwd=subbarp)

        self.assertEqual(headhash, fetched_hash,
                         "HEAD is updated to latest master")

        cmdx(giftp, "reset", "--sub", cwd=superp)
        reset_hash = cmd0(giftp, "rev-parse", "HEAD", cwd=subbarp)
        self.assertEqual(ori_hash, reset_hash,
                         "HEAD is reset to original master")
示例#13
0
    def test_init_3_with_fetched(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)

        cmdx(giftp, "init", "--sub", cwd=superp)
        self._fcontent("bar\n", subbarp, "bar")
示例#14
0
    def test_commit_sub(self):
        cmdx(giftp, "init", "--sub", cwd=superp)
        _, out, err = cmdx(giftp, *ident_args, "commit", "--sub", cwd=superp)
        dd(out)
        dd(err)

        self._gitoutput([giftp, "ls-files"], [
            ".gift",
            ".gift-refs",
            "foo/bar/bar",
            "foo/wow/wow",
            "imsuperman",
        ],
                        cwd=superp)

        self._fcontent(
            "\n".join([
                "- - foo/bar", "  - 466f0bbdf56b1428edf2aed4f6a99c1bd1d4c8af",
                "- - foo/wow", "  - 6bf37e52cbafcf55ff4710bb2b63309b55bf8e54",
                ""
            ]),
            superp,
            ".gift-refs",
        )
示例#15
0
    def test_commit_in_super(self):
        cmdx(giftp, "init", "--sub", cwd=superp)
        cmdx(giftp, "add", "foo", cwd=superp)
        cmdx(giftp, *ident_args, "commit", "-m", "add foo", cwd=superp)

        self._gitoutput([giftp, "ls-files"], [
            ".gift",
            "foo/bar/bar",
            "foo/wow/wow",
            "imsuperman",
        ],
                        cwd=superp)
示例#16
0
    def test_display(self):

        for cmd, want in (
                ('display(1, "foo")', (["foo"], [])),
                ('display(2, "foo")', ([], ["foo"])),
                ('display(2, ["foo", "bar"])', ([], ["foo", "bar"])),
                ('display(None, ["foo", "bar"])', ([], ["foo", "bar"])),
                ('display(["foo", "bar"], None)', (["foo", "bar"], [])),
                ('display(["foo", "bar"])', (["foo", "bar"], [])),
                ('display(["foo", "bar"], ["woo"])', (["foo", "bar"], ["woo"])),
                ('display("foo", "bar")', (["foo"], ["bar"])),
        ):

            _, out, err = k3handy.cmdx(
                'python', '-c',
                'import k3handy; k3handy.{}'.format(cmd),
            )

            self.assertEqual(want, (out, err))
示例#17
0
    def test_populate_super_ref(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()

        self._add_file_to_subbar()
        self._remove_super_ref()

        # init --sub should populate super/head
        cmdx(giftp, "init", "--sub", cwd=superp)
        self._check_initial_superhead()
示例#18
0
    def test_in_git_dir(self):

        cmdx(giftp, "log", "-n1", cwd=supergitp)

        try:
            cmdx(giftp, "commit", "--sub", cwd=supergitp)
        except CalledProcessError as e:
            self.assertEqual(2, e.returncode)
            self.assertEqual([], e.out)
            self.assertEqual(["--sub can not be used in git-dir:" + supergitp],
                             e.err)

        try:
            cmdx(giftp, "status", cwd=supergitp)
        except CalledProcessError as e:
            self.assertEqual(128, e.returncode)
            self.assertEqual([], e.out)
            self.assertEqual(
                ['fatal: this operation must be run in a work tree'], e.err)
示例#19
0
 def _remove_super_ref(self):
     cmdx(giftp, "update-ref", "-d", "refs/remotes/super/head", cwd=subbarp)
     cmdx(giftp, "update-ref", "-d", "refs/remotes/super/head", cwd=subwowp)
示例#20
0
    def test_super_checkout_should_populate_super_ref(self):

        cmdx(giftp, "init", "--sub", cwd=superp)
        cmdx(giftp, *ident_args, "commit", "--sub", cwd=superp)
        head_of_bar = cmdx(giftp,
                           "rev-parse",
                           "refs/remotes/super/head",
                           cwd=subbarp)

        self._add_file_to_subbar()
        cmdx(giftp, *ident_args, "commit", "--sub", cwd=superp)
        head_of_bar1 = cmdx(giftp,
                            "rev-parse",
                            "refs/remotes/super/head",
                            cwd=subbarp)

        self.assertNotEqual(head_of_bar, head_of_bar1)

        # changing HEAD in super repo should repopulate super/head ref in sub repo
        cmdx(giftp, "checkout", "HEAD~", cwd=superp)
        head_of_bar_after_checkout = cmdx(giftp,
                                          "rev-parse",
                                          "refs/remotes/super/head",
                                          cwd=subbarp)

        self.assertNotEqual(head_of_bar, head_of_bar_after_checkout)
示例#21
0
    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)
示例#22
0
    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")
示例#23
0
    def test_init_1_with_inited(self):

        cmdx(origit, "init", "--bare", self.sb['env']['GIT_DIR'])

        cmdx(giftp, "init", "--sub", cwd=superp)
        self._fcontent("bar\n", subbarp, "bar")
示例#24
0
 def _gitoutput(self, cmds, lines, **kwargs):
     _, out, _ = cmdx(*cmds, **kwargs)
     self.assertEqual(lines, out)
示例#25
0
 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)