From 7897e3549116a2efe5abd5ea003a62a4e3daed59 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Fri, 30 Sep 2016 12:19:28 +0100 Subject: [PATCH] Use python for pre/post scripts Switch from "sh" to "python" based scripts to facilitate running the tests on other platforms where only python may be available. Change-Id: Ib7dea76b7cac1801521c84bce8bb61957509018f --- git_upstream/tests/base.py | 12 +++--- .../import/conflict_scenarios/basic.yaml | 38 +++++++++++++------ .../scenarios/ambiguous_argument.yaml | 13 +++++-- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/git_upstream/tests/base.py b/git_upstream/tests/base.py index 3617211..377fde1 100644 --- a/git_upstream/tests/base.py +++ b/git_upstream/tests/base.py @@ -366,9 +366,9 @@ class BaseTestCase(testtools.TestCase): # ensure we execute within context of the git repository with DiveDir(self.testrepo.path): try: - output = subprocess.check_output(self.pre_script, - stderr=subprocess.STDOUT, - shell=True) + output = subprocess.check_output( + ["python", "-c", self.pre_script], + stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: self.addDetail('pre-script-output', text_content(e.output.decode('utf-8'))) @@ -391,9 +391,9 @@ class BaseTestCase(testtools.TestCase): # ensure we execute within context of the git repository with DiveDir(self.testrepo.path): try: - output = subprocess.check_output(self.post_script, - stderr=subprocess.STDOUT, - shell=True) + output = subprocess.check_output( + ["python", "-c", self.post_script], + stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: self.addDetail('post-script-output', text_content(e.output.decode('utf-8'))) diff --git a/git_upstream/tests/commands/import/conflict_scenarios/basic.yaml b/git_upstream/tests/commands/import/conflict_scenarios/basic.yaml index 396123a..b95f9e7 100644 --- a/git_upstream/tests/commands/import/conflict_scenarios/basic.yaml +++ b/git_upstream/tests/commands/import/conflict_scenarios/basic.yaml @@ -39,18 +39,34 @@ parser-args: [import, upstream/master] pre-script: | - #!/bin/sh -e + import os - file_f=$(git diff --name-only upstream/master~1..upstream/master) - git checkout master - echo "hello world" > ${file_f} - git add ${file_f} - git commit --amend --no-edit + from git_upstream.lib.pygitcompat import Repo + + + repo = Repo(os.path.curdir) + repo.git.checkout("master") + + conflict_file = repo.git.diff("upstream/master~1..upstream/master", + name_only=True) + with open(conflict_file, "w") as f: + f.write("hello world") + + repo.git.add(conflict_file) + repo.git.commit(amend=True, no_edit=True) post-script: | - #!/bin/sh -e + import os + + from git_upstream.lib.pygitcompat import Repo + + + repo = Repo(os.path.curdir) + + conflict_file = repo.git.diff("upstream/master~1..upstream/master", + name_only=True) + repo.git.checkout("--ours", "--", conflict_file) + repo.git.add(conflict_file) + os.environ["GIT_EDITOR"] = "echo" + repo.git.rebase("--continue") - file_f=$(git diff --name-only upstream/master~1..upstream/master) - git checkout --ours -- ${file_f} - git add ${file_f} - GIT_EDITOR=cat git rebase --continue diff --git a/git_upstream/tests/searchers/scenarios/ambiguous_argument.yaml b/git_upstream/tests/searchers/scenarios/ambiguous_argument.yaml index e4817c3..f16dbe9 100644 --- a/git_upstream/tests/searchers/scenarios/ambiguous_argument.yaml +++ b/git_upstream/tests/searchers/scenarios/ambiguous_argument.yaml @@ -51,14 +51,19 @@ expected-changes: [B1, C1, F, G] pre-script: | - #!/bin/sh + import os + + from git_upstream.lib.pygitcompat import Repo + + + repo = Repo(os.path.curdir) + repo.git.checkout("master") # add a file with the same name as the SHA1 for node [C], which will # trigger an error unless the arguments are correct delimited from # paths when the searcher lists commits - git checkout master - touch $(git log -1 --format="%H" HEAD~2) + open(repo.git.log("-1", "HEAD~2", format="%H"), "w").close() # add one the same name as a merge-base commit which will be included in # a rev-list of all or the merge-bases to ensure correct ordering. - touch $(git merge-base master upstream/master) + open(repo.git.merge_base("master", "upstream/master"), "w").close()