Initial hacking to start handling explicit file/contents

Change-Id: I359dd280ce9edef56789c086cc377238238700e4
This commit is contained in:
Darragh Bailey 2018-03-10 11:18:17 +00:00 committed by Darragh Bailey
parent 3f753dfac9
commit 5083834643
3 changed files with 57 additions and 16 deletions

View File

@ -299,29 +299,36 @@ class GitFixture(fixtures.Fixture):
if self._graph:
self.gittree = GitTree(self, self._graph, self._branches)
def _create_file(self):
contents = "\n\n".join(loremipsum.get_paragraphs(3))
def _create_file(self, filename=None, contents=None):
if not contents:
contents = "\n\n".join(loremipsum.get_paragraphs(3))
# always want to ensure the files added to the repo are unique no
# matter which branch they are added to, as otherwise there may
# be conflicts caused by replaying local changes and performing
# merges
while True:
tmpfile = tempfile.NamedTemporaryFile(
dir=self.repo.working_dir, delete=False)
if tmpfile.name not in self._file_list:
self._file_list.add(tmpfile.name)
break
# case where same filename in use on a different branch
tmpfile.close()
os.remove(tmpfile.name)
if filename is None:
while True:
tmpfile = tempfile.NamedTemporaryFile(
dir=self.repo.working_dir, delete=False)
# close immediately to ensure code at the end of this can
# be reopened for writing
tmpfile.close()
if tmpfile.name not in self._file_list:
self._file_list.add(tmpfile.name)
filename = tmpfile.name
break
# remove file as name in use elsewhere in the git repo
os.remove(tmpfile.name)
tmpfile.write(contents.encode('utf-8'))
tmpfile.close()
return tmpfile.name
with open(filename, 'w') as f:
f.write(contents.encode('utf-8'))
def _create_file_commit(self, change_id=None, message_prefix=None):
filename = self._create_file()
return filename
def _create_file_commit(self, message=None, contents=None,
change_id=None, message_prefix=None):
filename = self._create_file(contents)
self.repo.git.add(filename)
message = "Adding %s" % os.path.basename(filename)
if message_prefix:

View File

View File

@ -0,0 +1,34 @@
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import testtools
import fixtures_git
class TestBuildTree(testtools.TestCase):
def test_basic(self):
pass
def test_merge(self):
pass
def test_merge_and_replace(self):
pass
def test_merge_unrelated_history(self):
pass