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 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 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 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 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 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 test0404_status_exception(self): with self.assertRaises(gitcmd.NotInRepositoryError): gitcmd.status('/tmp')