def test_get_modified_file(self): sut = git.open_repository(self.repository_path) file_path = os.path.join(self.repository_path, 'test.txt') with open(file_path, 'w') as out_file: out_file.write("a") command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Added file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_a = sut.client.commit().binsha with open(file_path, 'w') as out_file: out_file.write("b") command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Updated file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_b = sut.client.commit().binsha changeset = sut.get_changeset() self.assertEqual(changeset.changes, [ change.Change(sut, "test.txt", revision_a, "test.txt", revision_b, change.ChangeType.modify) ])
def test_get_removed_file(self): sut = git.open_repository(self.repository_path) file_path = os.path.join(self.repository_path, 'test.txt') with open(file_path, 'w') as out_file: out_file.write("a") command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Remove file - initial add"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision = sut.client.commit().binsha command = 'git rm -f test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Remove file - remove file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) changeset = sut.get_changeset() self.assertEqual(changeset.changes, [ change.Change(sut, "test.txt", revision, None, None, change.ChangeType.remove) ])
def test_get_contents_at_head(self): file_path = os.path.join(self.repository_path, 'test.txt') with open(file_path, 'w') as out_file: out_file.write("ab") command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Added file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) sut = git.open_repository(self.repository_path) contents = sut.get_file_contents('test.txt') self.assertEqual(contents.read(), b"ab")
def test_get_derived_file(self): sut = git.open_repository(self.repository_path) old_file_path = os.path.join(self.repository_path, 'test_old.txt') new_file_path = os.path.join(self.repository_path, 'test.txt') with open(old_file_path, 'w') as out_file: out_file.write("abcdefghijklmnopqrstuvwxyz\n" * 100) command = 'git add test_old.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Derive: Added file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_a = sut.client.commit().binsha with open(new_file_path, 'w') as out_file: out_file.write("abcdefghijklmnopqrstuvwxyz\n" * 110) command = 'git rm -r test_old.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Derive: Updated file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_b = sut.client.commit().binsha print(sut.client.commit().message) changeset = sut.get_changeset() self.assertEqual(changeset.changes, [ change.Change(sut, "test_old.txt", revision_a, "test.txt", revision_b, change.ChangeType.derived) ])