Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 3 | # |
| 4 | # Copyright 2017 Google, Inc |
| 5 | # |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 6 | |
| 7 | import contextlib |
| 8 | import os |
| 9 | import re |
| 10 | import shutil |
| 11 | import sys |
| 12 | import tempfile |
| 13 | import unittest |
| 14 | |
Simon Glass | 945328b | 2020-04-17 18:08:55 -0600 | [diff] [blame] | 15 | from io import StringIO |
Simon Glass | 68475f9 | 2019-05-14 15:53:49 -0600 | [diff] [blame] | 16 | |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 17 | from patman import control |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 18 | from patman import gitutil |
| 19 | from patman import patchstream |
| 20 | from patman import settings |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 21 | from patman import terminal |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 22 | from patman import tools |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 23 | from patman.test_util import capture_sys_output |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 24 | |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 25 | try: |
| 26 | import pygit2 |
| 27 | HAVE_PYGIT2= True |
| 28 | except ModuleNotFoundError: |
| 29 | HAVE_PYGIT2 = False |
| 30 | |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 31 | |
| 32 | @contextlib.contextmanager |
| 33 | def capture(): |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 34 | oldout,olderr = sys.stdout, sys.stderr |
| 35 | try: |
| 36 | out=[StringIO(), StringIO()] |
| 37 | sys.stdout,sys.stderr = out |
| 38 | yield out |
| 39 | finally: |
| 40 | sys.stdout,sys.stderr = oldout, olderr |
| 41 | out[0] = out[0].getvalue() |
| 42 | out[1] = out[1].getvalue() |
| 43 | |
| 44 | |
| 45 | class TestFunctional(unittest.TestCase): |
| 46 | def setUp(self): |
| 47 | self.tmpdir = tempfile.mkdtemp(prefix='patman.') |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 48 | self.gitdir = os.path.join(self.tmpdir, 'git') |
| 49 | self.repo = None |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 50 | |
| 51 | def tearDown(self): |
| 52 | shutil.rmtree(self.tmpdir) |
| 53 | |
| 54 | @staticmethod |
| 55 | def GetPath(fname): |
| 56 | return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), |
| 57 | 'test', fname) |
| 58 | |
| 59 | @classmethod |
| 60 | def GetText(self, fname): |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 61 | return open(self.GetPath(fname), encoding='utf-8').read() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 62 | |
| 63 | @classmethod |
| 64 | def GetPatchName(self, subject): |
| 65 | fname = re.sub('[ :]', '-', subject) |
| 66 | return fname.replace('--', '-') |
| 67 | |
| 68 | def CreatePatchesForTest(self, series): |
| 69 | cover_fname = None |
| 70 | fname_list = [] |
| 71 | for i, commit in enumerate(series.commits): |
| 72 | clean_subject = self.GetPatchName(commit.subject) |
| 73 | src_fname = '%04d-%s.patch' % (i + 1, clean_subject[:52]) |
| 74 | fname = os.path.join(self.tmpdir, src_fname) |
| 75 | shutil.copy(self.GetPath(src_fname), fname) |
| 76 | fname_list.append(fname) |
| 77 | if series.get('cover'): |
| 78 | src_fname = '0000-cover-letter.patch' |
| 79 | cover_fname = os.path.join(self.tmpdir, src_fname) |
| 80 | fname = os.path.join(self.tmpdir, src_fname) |
| 81 | shutil.copy(self.GetPath(src_fname), fname) |
| 82 | |
| 83 | return cover_fname, fname_list |
| 84 | |
| 85 | def testBasic(self): |
| 86 | """Tests the basic flow of patman |
| 87 | |
| 88 | This creates a series from some hard-coded patches build from a simple |
| 89 | tree with the following metadata in the top commit: |
| 90 | |
| 91 | Series-to: u-boot |
| 92 | Series-prefix: RFC |
| 93 | Series-cc: Stefan Brüns <stefan.bruens@rwth-aachen.de> |
| 94 | Cover-letter-cc: Lord Mëlchett <clergy@palace.gov> |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 95 | Series-version: 3 |
| 96 | Patch-cc: fred |
| 97 | Series-process-log: sort, uniq |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 98 | Series-changes: 4 |
| 99 | - Some changes |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 100 | - Multi |
| 101 | line |
| 102 | change |
| 103 | |
| 104 | Commit-changes: 2 |
| 105 | - Changes only for this commit |
| 106 | |
| 107 | Cover-changes: 4 |
| 108 | - Some notes for the cover letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 109 | |
| 110 | Cover-letter: |
| 111 | test: A test patch series |
| 112 | This is a test of how the cover |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 113 | letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 114 | works |
| 115 | END |
| 116 | |
| 117 | and this in the first commit: |
| 118 | |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 119 | Commit-changes: 2 |
| 120 | - second revision change |
| 121 | |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 122 | Series-notes: |
| 123 | some notes |
| 124 | about some things |
| 125 | from the first commit |
| 126 | END |
| 127 | |
| 128 | Commit-notes: |
| 129 | Some notes about |
| 130 | the first commit |
| 131 | END |
| 132 | |
| 133 | with the following commands: |
| 134 | |
| 135 | git log -n2 --reverse >/path/to/tools/patman/test/test01.txt |
| 136 | git format-patch --subject-prefix RFC --cover-letter HEAD~2 |
| 137 | mv 00* /path/to/tools/patman/test |
| 138 | |
| 139 | It checks these aspects: |
| 140 | - git log can be processed by patchstream |
| 141 | - emailing patches uses the correct command |
| 142 | - CC file has information on each commit |
| 143 | - cover letter has the expected text and subject |
| 144 | - each patch has the correct subject |
| 145 | - dry-run information prints out correctly |
| 146 | - unicode is handled correctly |
| 147 | - Series-to, Series-cc, Series-prefix, Cover-letter |
| 148 | - Cover-letter-cc, Series-version, Series-changes, Series-notes |
| 149 | - Commit-notes |
| 150 | """ |
| 151 | process_tags = True |
| 152 | ignore_bad_tags = True |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 153 | stefan = b'Stefan Br\xc3\xbcns <stefan.bruens@rwth-aachen.de>'.decode('utf-8') |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 154 | rick = 'Richard III <richard@palace.gov>' |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 155 | mel = b'Lord M\xc3\xablchett <clergy@palace.gov>'.decode('utf-8') |
| 156 | ed = b'Lond Edmund Blackadd\xc3\xabr <weasel@blackadder.org'.decode('utf-8') |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 157 | fred = 'Fred Bloggs <f.bloggs@napier.net>' |
| 158 | add_maintainers = [stefan, rick] |
| 159 | dry_run = True |
| 160 | in_reply_to = mel |
| 161 | count = 2 |
| 162 | settings.alias = { |
| 163 | 'fdt': ['simon'], |
| 164 | 'u-boot': ['u-boot@lists.denx.de'], |
| 165 | 'simon': [ed], |
| 166 | 'fred': [fred], |
| 167 | } |
| 168 | |
| 169 | text = self.GetText('test01.txt') |
| 170 | series = patchstream.GetMetaDataForTest(text) |
| 171 | cover_fname, args = self.CreatePatchesForTest(series) |
| 172 | with capture() as out: |
| 173 | patchstream.FixPatches(series, args) |
| 174 | if cover_fname and series.get('cover'): |
| 175 | patchstream.InsertCoverLetter(cover_fname, series, count) |
| 176 | series.DoChecks() |
| 177 | cc_file = series.MakeCcFile(process_tags, cover_fname, |
Chris Packham | b84fb48 | 2018-06-07 20:45:06 +1200 | [diff] [blame] | 178 | not ignore_bad_tags, add_maintainers, |
| 179 | None) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 180 | cmd = gitutil.EmailPatches(series, cover_fname, args, |
| 181 | dry_run, not ignore_bad_tags, cc_file, |
| 182 | in_reply_to=in_reply_to, thread=None) |
| 183 | series.ShowActions(args, cmd, process_tags) |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 184 | cc_lines = open(cc_file, encoding='utf-8').read().splitlines() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 185 | os.remove(cc_file) |
| 186 | |
| 187 | lines = out[0].splitlines() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 188 | self.assertEqual('Cleaned %s patches' % len(series.commits), lines[0]) |
| 189 | self.assertEqual('Change log missing for v2', lines[1]) |
| 190 | self.assertEqual('Change log missing for v3', lines[2]) |
| 191 | self.assertEqual('Change log for unknown version v4', lines[3]) |
| 192 | self.assertEqual("Alias 'pci' not found", lines[4]) |
| 193 | self.assertIn('Dry run', lines[5]) |
| 194 | self.assertIn('Send a total of %d patches' % count, lines[7]) |
| 195 | line = 8 |
| 196 | for i, commit in enumerate(series.commits): |
| 197 | self.assertEqual(' %s' % args[i], lines[line + 0]) |
| 198 | line += 1 |
| 199 | while 'Cc:' in lines[line]: |
| 200 | line += 1 |
| 201 | self.assertEqual('To: u-boot@lists.denx.de', lines[line]) |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 202 | self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), |
| 203 | lines[line + 1]) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 204 | self.assertEqual('Version: 3', lines[line + 2]) |
| 205 | self.assertEqual('Prefix:\t RFC', lines[line + 3]) |
| 206 | self.assertEqual('Cover: 4 lines', lines[line + 4]) |
| 207 | line += 5 |
Simon Glass | 3ab178f | 2019-05-14 15:53:51 -0600 | [diff] [blame] | 208 | self.assertEqual(' Cc: %s' % fred, lines[line + 0]) |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 209 | self.assertEqual(' Cc: %s' % tools.FromUnicode(ed), |
| 210 | lines[line + 1]) |
| 211 | self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), |
| 212 | lines[line + 2]) |
Simon Glass | 3ab178f | 2019-05-14 15:53:51 -0600 | [diff] [blame] | 213 | self.assertEqual(' Cc: %s' % rick, lines[line + 3]) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 214 | expected = ('Git command: git send-email --annotate ' |
| 215 | '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' |
| 216 | '--cc "%s" --cc-cmd "%s --cc-cmd %s" %s %s' |
| 217 | % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 218 | ' '.join(args))) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 219 | line += 4 |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 220 | self.assertEqual(expected, tools.ToUnicode(lines[line])) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 221 | |
Dmitry Torokhov | ef7f67d | 2019-10-21 20:09:56 -0700 | [diff] [blame] | 222 | self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 223 | tools.ToUnicode(cc_lines[0])) |
Dmitry Torokhov | ef7f67d | 2019-10-21 20:09:56 -0700 | [diff] [blame] | 224 | self.assertEqual(('%s %s\0%s\0%s\0%s' % (args[1], fred, ed, rick, |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 225 | stefan)), tools.ToUnicode(cc_lines[1])) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 226 | |
| 227 | expected = ''' |
| 228 | This is a test of how the cover |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 229 | letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 230 | works |
| 231 | |
| 232 | some notes |
| 233 | about some things |
| 234 | from the first commit |
| 235 | |
| 236 | Changes in v4: |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 237 | - Multi |
| 238 | line |
| 239 | change |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 240 | - Some changes |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 241 | - Some notes for the cover letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 242 | |
| 243 | Simon Glass (2): |
| 244 | pci: Correct cast for sandbox |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 245 | fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 246 | |
| 247 | cmd/pci.c | 3 ++- |
| 248 | fs/fat/fat.c | 1 + |
| 249 | lib/efi_loader/efi_memory.c | 1 + |
| 250 | lib/fdtdec.c | 3 ++- |
| 251 | 4 files changed, 6 insertions(+), 2 deletions(-) |
| 252 | |
| 253 | --\x20 |
| 254 | 2.7.4 |
| 255 | |
| 256 | ''' |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 257 | lines = open(cover_fname, encoding='utf-8').read().splitlines() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 258 | self.assertEqual( |
| 259 | 'Subject: [RFC PATCH v3 0/2] test: A test patch series', |
| 260 | lines[3]) |
| 261 | self.assertEqual(expected.splitlines(), lines[7:]) |
| 262 | |
| 263 | for i, fname in enumerate(args): |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 264 | lines = open(fname, encoding='utf-8').read().splitlines() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 265 | subject = [line for line in lines if line.startswith('Subject')] |
| 266 | self.assertEqual('Subject: [RFC %d/%d]' % (i + 1, count), |
| 267 | subject[0][:18]) |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 268 | |
| 269 | # Check that we got our commit notes |
| 270 | start = 0 |
| 271 | expected = '' |
| 272 | |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 273 | if i == 0: |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 274 | start = 17 |
| 275 | expected = '''--- |
| 276 | Some notes about |
| 277 | the first commit |
| 278 | |
| 279 | (no changes since v2) |
| 280 | |
| 281 | Changes in v2: |
| 282 | - second revision change''' |
| 283 | elif i == 1: |
| 284 | start = 17 |
| 285 | expected = '''--- |
| 286 | |
| 287 | Changes in v4: |
| 288 | - Multi |
| 289 | line |
| 290 | change |
| 291 | - Some changes |
| 292 | |
| 293 | Changes in v2: |
| 294 | - Changes only for this commit''' |
| 295 | |
| 296 | if expected: |
| 297 | expected = expected.splitlines() |
| 298 | self.assertEqual(expected, lines[start:(start+len(expected))]) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 299 | |
| 300 | def make_commit_with_file(self, subject, body, fname, text): |
| 301 | """Create a file and add it to the git repo with a new commit |
| 302 | |
| 303 | Args: |
| 304 | subject (str): Subject for the commit |
| 305 | body (str): Body text of the commit |
| 306 | fname (str): Filename of file to create |
| 307 | text (str): Text to put into the file |
| 308 | """ |
| 309 | path = os.path.join(self.gitdir, fname) |
| 310 | tools.WriteFile(path, text, binary=False) |
| 311 | index = self.repo.index |
| 312 | index.add(fname) |
| 313 | author = pygit2.Signature('Test user', 'test@email.com') |
| 314 | committer = author |
| 315 | tree = index.write_tree() |
| 316 | message = subject + '\n' + body |
| 317 | self.repo.create_commit('HEAD', author, committer, message, tree, |
| 318 | [self.repo.head.target]) |
| 319 | |
| 320 | def make_git_tree(self): |
| 321 | """Make a simple git tree suitable for testing |
| 322 | |
| 323 | It has three branches: |
| 324 | 'base' has two commits: PCI, main |
| 325 | 'first' has base as upstream and two more commits: I2C, SPI |
| 326 | 'second' has base as upstream and three more: video, serial, bootm |
| 327 | |
| 328 | Returns: |
| 329 | pygit2 repository |
| 330 | """ |
| 331 | repo = pygit2.init_repository(self.gitdir) |
| 332 | self.repo = repo |
| 333 | new_tree = repo.TreeBuilder().write() |
| 334 | |
| 335 | author = pygit2.Signature('Test user', 'test@email.com') |
| 336 | committer = author |
| 337 | commit = repo.create_commit('HEAD', author, committer, |
| 338 | 'Created master', new_tree, []) |
| 339 | |
| 340 | self.make_commit_with_file('Initial commit', ''' |
| 341 | Add a README |
| 342 | |
| 343 | ''', 'README', '''This is the README file |
| 344 | describing this project |
| 345 | in very little detail''') |
| 346 | |
| 347 | self.make_commit_with_file('pci: PCI implementation', ''' |
| 348 | Here is a basic PCI implementation |
| 349 | |
| 350 | ''', 'pci.c', '''This is a file |
| 351 | it has some contents |
| 352 | and some more things''') |
| 353 | self.make_commit_with_file('main: Main program', ''' |
| 354 | Hello here is the second commit. |
| 355 | ''', 'main.c', '''This is the main file |
| 356 | there is very little here |
| 357 | but we can always add more later |
| 358 | if we want to |
| 359 | |
| 360 | Series-to: u-boot |
| 361 | Series-cc: Barry Crump <bcrump@whataroa.nz> |
| 362 | ''') |
| 363 | base_target = repo.revparse_single('HEAD') |
| 364 | self.make_commit_with_file('i2c: I2C things', ''' |
| 365 | This has some stuff to do with I2C |
| 366 | ''', 'i2c.c', '''And this is the file contents |
| 367 | with some I2C-related things in it''') |
| 368 | self.make_commit_with_file('spi: SPI fixes', ''' |
| 369 | SPI needs some fixes |
| 370 | and here they are |
| 371 | ''', 'spi.c', '''Some fixes for SPI in this |
| 372 | file to make SPI work |
| 373 | better than before''') |
| 374 | first_target = repo.revparse_single('HEAD') |
| 375 | |
| 376 | target = repo.revparse_single('HEAD~2') |
| 377 | repo.reset(target.oid, pygit2.GIT_CHECKOUT_FORCE) |
| 378 | self.make_commit_with_file('video: Some video improvements', ''' |
| 379 | Fix up the video so that |
| 380 | it looks more purple. Purple is |
| 381 | a very nice colour. |
| 382 | ''', 'video.c', '''More purple here |
| 383 | Purple and purple |
| 384 | Even more purple |
| 385 | Could not be any more purple''') |
| 386 | self.make_commit_with_file('serial: Add a serial driver', ''' |
| 387 | Here is the serial driver |
| 388 | for my chip. |
| 389 | |
| 390 | Cover-letter: |
| 391 | Series for my board |
| 392 | This series implements support |
| 393 | for my glorious board. |
| 394 | END |
| 395 | ''', 'serial.c', '''The code for the |
| 396 | serial driver is here''') |
| 397 | self.make_commit_with_file('bootm: Make it boot', ''' |
| 398 | This makes my board boot |
| 399 | with a fix to the bootm |
| 400 | command |
| 401 | ''', 'bootm.c', '''Fix up the bootm |
| 402 | command to make the code as |
| 403 | complicated as possible''') |
| 404 | second_target = repo.revparse_single('HEAD') |
| 405 | |
| 406 | repo.branches.local.create('first', first_target) |
| 407 | repo.config.set_multivar('branch.first.remote', '', '.') |
| 408 | repo.config.set_multivar('branch.first.merge', '', 'refs/heads/base') |
| 409 | |
| 410 | repo.branches.local.create('second', second_target) |
| 411 | repo.config.set_multivar('branch.second.remote', '', '.') |
| 412 | repo.config.set_multivar('branch.second.merge', '', 'refs/heads/base') |
| 413 | |
| 414 | repo.branches.local.create('base', base_target) |
| 415 | return repo |
| 416 | |
| 417 | @unittest.skipIf(not HAVE_PYGIT2, 'Missing python3-pygit2') |
| 418 | def testBranch(self): |
| 419 | """Test creating patches from a branch""" |
| 420 | repo = self.make_git_tree() |
| 421 | target = repo.lookup_reference('refs/heads/first') |
| 422 | self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE) |
| 423 | control.setup() |
| 424 | try: |
| 425 | orig_dir = os.getcwd() |
| 426 | os.chdir(self.gitdir) |
| 427 | |
| 428 | # Check that it can detect the current branch |
Simon Glass | 2eb4da7 | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 429 | self.assertEqual(2, gitutil.CountCommitsToBranch(None)) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 430 | col = terminal.Color() |
| 431 | with capture_sys_output() as _: |
| 432 | _, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 433 | col, branch=None, count=-1, start=0, end=0, |
| 434 | ignore_binary=False) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 435 | self.assertIsNone(cover_fname) |
| 436 | self.assertEqual(2, len(patch_files)) |
Simon Glass | 2eb4da7 | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 437 | |
| 438 | # Check that it can detect a different branch |
| 439 | self.assertEqual(3, gitutil.CountCommitsToBranch('second')) |
| 440 | with capture_sys_output() as _: |
| 441 | _, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 442 | col, branch='second', count=-1, start=0, end=0, |
Simon Glass | 2eb4da7 | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 443 | ignore_binary=False) |
| 444 | self.assertIsNotNone(cover_fname) |
| 445 | self.assertEqual(3, len(patch_files)) |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 446 | |
| 447 | # Check that it can skip patches at the end |
| 448 | with capture_sys_output() as _: |
| 449 | _, cover_fname, patch_files = control.prepare_patches( |
| 450 | col, branch='second', count=-1, start=0, end=1, |
| 451 | ignore_binary=False) |
| 452 | self.assertIsNotNone(cover_fname) |
| 453 | self.assertEqual(2, len(patch_files)) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 454 | finally: |
| 455 | os.chdir(orig_dir) |