def test_diff(self): """Tests the `diff` method""" r = Repo.init(self.path, mkdir=True) with open(os.path.join(r.root, 'test'), 'w') as fp: fp.write('hello world') r.add(all=True) c1 = r.commit(committer='Test McGee', message='testing diff 1') with open(os.path.join(r.root, 'test'), 'w') as fp: fp.write('hello world!') r.add(all=True) c2 = r.commit(committer='Test McGee', message='testing diff 2') expected = \ """*** --- *************** *** 1 **** ! hello world! --- 1 ---- ! hello world""" result = r.diff(c2.id, c1.id, 'test') assert result == expected
def test_constructor(self): r1 = Repo.init(self.path, mkdir=True) # verify that an existing repository can be initialized r2 = Repo(r1.root) # make sure it's a Repo object. assert type(r2) is Repo # a new repo should have no HEAD try: r2.head() except NoHeadSet: pass
def _repo_with_commits(self, num_commits=1): """ Returns a repo with one or more commits, on master branch, with a tag 'v1.0' that points to the last commit. """ r = Repo.init(self.path, mkdir=True) for c in range(num_commits): for i in range(4): self._rand_file('spam-%d' % i) # add the files/changes r.add(all=True) # commit the changes r.commit(committer='Joe Sixpack', message='Commit %d' % c) r.tag('v1.0') return r
def test_init(self): """Tests the `init` method""" # NOTE init refers not to __init__, but the classmethod for creating # repositories. See test_constructor() for __init__. r = Repo.init(self.path, mkdir=True) # make sure it created something. assert os.path.isdir(self.path) # does the dir have a .git? assert os.path.isdir(os.path.join(self.path, '.git')) # make sure it returns a Repo object. assert type(r) is Repo
def test_commit(self): """Tests the `commit` method""" r = Repo.init(self.path, mkdir=True) self._rand_file('spam') r.add('spam') c = r.commit(committer='GOB Bluth', message='Come on!') # make sure the commit got set right assert type(c) is Commit assert c.author == 'GOB Bluth' assert c.message == 'Come on!' # the commit should be the same as the Repo.head assert c == r.head()