From 0f62dd05c9aaf6cb7e055f6d3cde375aa5998f47 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Wed, 21 Mar 2018 22:06:33 +0900 Subject: tests/testutils/repo/git.py: Add new add_file() convenience To write tests which add and commit a file. --- tests/testutils/repo/git.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests/testutils/repo') diff --git a/tests/testutils/repo/git.py b/tests/testutils/repo/git.py index 9d527f904..eea43d608 100644 --- a/tests/testutils/repo/git.py +++ b/tests/testutils/repo/git.py @@ -1,5 +1,7 @@ -import subprocess +import os import pytest +import shutil +import subprocess from .repo import Repo from ..site import HAVE_GIT @@ -36,6 +38,14 @@ class Git(Repo): env=GIT_ENV, cwd=self.repo) return self.latest_commit() + def add_file(self, filename): + shutil.copy(filename, self.repo) + subprocess.call(['git', 'add', os.path.basename(filename)], env=GIT_ENV, cwd=self.repo) + subprocess.call([ + 'git', 'commit', '-m', 'Added {}'.format(os.path.basename(filename)) + ], env=GIT_ENV, cwd=self.repo) + return self.latest_commit() + def add_submodule(self, subdir, url=None, checkout=None): submodule = {} if checkout is not None: -- cgit v1.2.1