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")
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)
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('-', ' '))
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)
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)
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)
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)
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)
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)
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)
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)
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")
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")
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)
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)
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")
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))
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)
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)
def test0102_clone_exception(self): with self.assertRaises(ValueError): gitcmd.clone(os.path.join(LOCAL_DIRS, 'local/file2.txt'), HOST_DIR, to='test', username="******")
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')))
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')))
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)