コード例 #1
0
ファイル: test_gitcmd.py プロジェクト: elisehardy/gitcmd
    def test0902_reset_value_error(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        with self.assertRaises(ValueError):
            gitcmd.reset(local, mode="error")
コード例 #2
0
    def test0900_reset(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'file.txt')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        with open(test_file, 'w+') as f:
            print("test", file=f)
        gitcmd.add(test_file)
        ret, out, err = gitcmd.status(local)
        self.assertEqual(ret, 0)
        self.assertIn("Changes to be committed", out)
        ret, out, err = gitcmd.reset(local)
        self.assertEqual(ret, 0)
        self.assertEqual("Unstaged changes after reset:\nM\tfile.txt", out)
        ret, out, err = gitcmd.status(local)
        self.assertEqual(ret, 0)
        self.assertIn("Changes not staged for commit:", out)

        with open(test_file, 'w+') as f:
            print("test", file=f)
        gitcmd.add(test_file)
        ret, out, err = gitcmd.status(local)
        self.assertEqual(ret, 0)
        self.assertIn("Changes to be committed", out)
        ret, out, err = gitcmd.reset(test_file)
        self.assertEqual(ret, 0)
        self.assertEqual("Unstaged changes after reset:\nM\tfile.txt", out)
        ret, out, err = gitcmd.status(local)
        self.assertEqual(ret, 0)
        self.assertIn("Changes not staged for commit:", out)
コード例 #3
0
    def test1002_pull_useless(self):
        local2 = os.path.join(LOCAL_DIRS, 'local2')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local2')
        ret, out, err = gitcmd.pull(local2, HOST_DIR)
        self.assertEqual(ret, 0)
        self.assertEqual("Already up to date.", out.replace('-', ' '))
コード例 #4
0
    def test0400_status_clean(self):
        local = os.path.join(LOCAL_DIRS, 'local')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        ret, out, err = gitcmd.status(local)

        self.assertEqual(ret, 0)
        self.assertTrue('nothing to commit' in out)
コード例 #5
0
    def test0703_checkout_nonexistent_branch(self):
        local = os.path.join(LOCAL_DIRS, 'local')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        ret, out, err = gitcmd.checkout(local, 'test_branch')
        self.assertEqual(ret, 1)
        self.assertIn(
            "pathspec 'test_branch' did not match any file(s) known to git",
            err)
コード例 #6
0
    def test0701_checkout_new_branch(self):
        local = os.path.join(LOCAL_DIRS, 'local')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        ret, out, err = gitcmd.checkout(local, 'test_branch', True)
        self.assertEqual(ret, 0)
        self.assertIn("Switched to a new branch 'test_branch'", err)
        ret, out, err = gitcmd.branch(local)
        self.assertEqual("  master\n* test_branch", out)
コード例 #7
0
    def test0702_checkout_branch(self):
        local = os.path.join(LOCAL_DIRS, 'local')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        gitcmd.checkout(local, 'test_branch', True)
        gitcmd.branch(local)
        gitcmd.checkout(local, 'master')
        ret, out, err = gitcmd.branch(local)
        self.assertEqual(ret, 0)
        self.assertEqual("* master\n  test_branch", out)
コード例 #8
0
    def test0401_status_to_add(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        open(test_file, 'w+').close()
        ret, out, err = gitcmd.status(local)

        self.assertEqual(ret, 0)
        self.assertTrue('Untracked files:' in out)
コード例 #9
0
    def test0402_status_to_commit(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        open(test_file, 'w+').close()
        gitcmd.add(test_file)
        ret, out, err = gitcmd.status(local)

        self.assertEqual(ret, 0)
        self.assertTrue('Changes to be committed:' in out)
コード例 #10
0
    def test1100_remote_url(self):
        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        test_file = os.path.join(LOCAL_DIRS, 'local/file.txt')

        ret, out, err = gitcmd.remote_url(os.path.join(LOCAL_DIRS, 'local'))
        self.assertEqual(ret, 0)
        self.assertEqual(out, HOST_DIR)

        ret, out, err = gitcmd.remote_url(test_file)
        self.assertEqual(ret, 0)
        self.assertEqual(out, HOST_DIR)
コード例 #11
0
    def test0501_push_no_url(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        open(test_file, 'w+').close()
        gitcmd.add(test_file)
        gitcmd.commit(test_file, 'test')
        ret, out, err = gitcmd.push(local)

        self.assertEqual(ret, 0)
        self.assertIn("master -> master", err)
コード例 #12
0
ファイル: test_gitcmd.py プロジェクト: elisehardy/gitcmd
    def test0800_current_branch(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        ret, out, err = gitcmd.current_branch(local)
        self.assertEqual(ret, 0)
        self.assertEqual(out, "master\n")
        gitcmd.checkout(local, branch="test_branch", new=True)
        ret, out, err = gitcmd.current_branch(local)
        self.assertEqual(ret, 0)
        self.assertEqual(out, "test_branch\n")
コード例 #13
0
ファイル: test_gitcmd.py プロジェクト: elisehardy/gitcmd
    def test0600_branch(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        open(test_file, 'w+').close()
        gitcmd.add(test_file)
        gitcmd.commit(test_file, 'test')
        gitcmd.push(local, HOST_DIR)

        ret, out, err = gitcmd.branch(local)
        self.assertEqual(ret, 0)
        self.assertEqual(out, "* master\n")
コード例 #14
0
    def test0700_checkout(self):
        local = os.path.join(LOCAL_DIRS, 'local')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        with open(os.path.join(local, 'file.txt'), 'w+') as f:
            print("test", file=f)
        ret, out, err = gitcmd.status(local)
        self.assertEqual(ret, 0)
        self.assertIn("Changes not staged for commit", out)
        ret, out, err = gitcmd.checkout(os.path.join(local, 'file.txt'))
        self.assertEqual(ret, 0)
        ret, out, err = gitcmd.status(local)
        self.assertIn("working tree clean", out)
コード例 #15
0
ファイル: test_gitcmd.py プロジェクト: elisehardy/gitcmd
    def test0403_status_to_commit(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        open(test_file, 'w+').close()
        gitcmd.add(test_file)
        gitcmd.commit(test_file, 'test')
        ret, out, err = gitcmd.status(local)

        self.assertEqual(ret, 0)
        self.assertTrue(
            'Your branch is ahead of \'origin/master\' by 1 commit.' in out)
コード例 #16
0
    def test1005_pull_exception(self):
        with self.assertRaises(gitcmd.NotInRepositoryError):
            gitcmd.pull('/tmp', 'url')

        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'testfile')
        test_file2 = os.path.join(local, 'testfile')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local2')
        open(test_file, 'w+').close()
        gitcmd.add(test_file)
        gitcmd.commit(test_file, 'test')
        gitcmd.push(local, HOST_DIR)
        with self.assertRaises(ValueError):
            gitcmd.pull(test_file2, HOST_DIR, "username")
コード例 #17
0
    def test1001_pull_no_url(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        local2 = os.path.join(LOCAL_DIRS, 'local2')
        test_file = os.path.join(local, 'testfile')
        test_file2 = os.path.join(local, 'testfile')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local2')
        open(test_file, 'w+').close()
        gitcmd.add(test_file)
        gitcmd.commit(test_file, 'test')
        gitcmd.push(local, HOST_DIR)
        ret, out, err = gitcmd.pull(local2)
        self.assertEqual(ret, 0)
        self.assertIn("Fast-forward\n testfile", out)
        self.assertTrue(os.path.isfile(test_file2))
コード例 #18
0
    def test1300_set_url(self):
        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        url = 'https://github.com/qcoumes/gitcmd'
        test_file = os.path.join(LOCAL_DIRS, 'local/file.txt')

        ret, out, err = gitcmd.remote_url(os.path.join(LOCAL_DIRS, 'local'))
        self.assertEqual(ret, 0)
        self.assertEqual(out, HOST_DIR)

        ret, out, err = gitcmd.set_url(os.path.join(LOCAL_DIRS, 'local'), url)
        self.assertEqual(ret, 0)

        ret, out, err = gitcmd.set_url(test_file, url)
        self.assertEqual(ret, 0)

        ret, out, err = gitcmd.remote_url(os.path.join(LOCAL_DIRS, 'local'))
        self.assertEqual(ret, 0)
        self.assertEqual(out, url)
コード例 #19
0
    def test0403_status_committed(self):
        local = os.path.join(LOCAL_DIRS, 'local')
        test_file = os.path.join(local, 'test')
        test_file2 = os.path.join(local, 'test2')

        gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
        open(test_file, 'w+').close()
        gitcmd.add(test_file)
        gitcmd.commit(test_file, 'test')
        ret, out, err = gitcmd.status(local)
        self.assertEqual(ret, 0)
        self.assertIn("Your branch is ahead of 'origin/master' by 1 commit.",
                      out)

        open(test_file2, 'w+').close()
        gitcmd.add(test_file2)
        gitcmd.commit(test_file2, 'test')
        ret, out, err = gitcmd.status(test_file2)
        self.assertEqual(ret, 0)
        self.assertIn("Your branch is ahead of 'origin/master' by 2 commits.",
                      out)
コード例 #20
0
 def test0102_clone_exception(self):
     with self.assertRaises(ValueError):
         gitcmd.clone(os.path.join(LOCAL_DIRS, 'local/file2.txt'),
                      HOST_DIR,
                      to='test',
                      username="******")
コード例 #21
0
 def test0101_clone_to(self):
     self.assertEqual(0, gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='test')[0])
     self.assertTrue(os.path.isdir(os.path.join(LOCAL_DIRS, 'test')))
コード例 #22
0
 def test0100_clone(self):
     self.assertEqual(0, gitcmd.clone(LOCAL_DIRS, HOST_DIR)[0])
     self.assertTrue(os.path.isdir(os.path.join(LOCAL_DIRS, 'host')))
コード例 #23
0
ファイル: test_gitcmd.py プロジェクト: elisehardy/gitcmd
 def test_1100_remote_url(self):
     gitcmd.clone(LOCAL_DIRS, HOST_DIR, to='local')
     ret, out, err = gitcmd.remote_url(os.path.join(LOCAL_DIRS, 'local'))
     self.assertEqual(ret, 0)
     self.assertEqual(out[:-1], HOST_DIR)