Merge "Use python for pre/post scripts"

This commit is contained in:
Jenkins
2016-10-04 10:13:14 +00:00
committed by Gerrit Code Review
3 changed files with 42 additions and 21 deletions

View File

@@ -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')))

View File

@@ -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

View File

@@ -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()