Merge ~racb/git-ubuntu:commit-message-spec into git-ubuntu:master

Proposed by Robie Basak
Status: Merged
Approved by: Bryce Harrington
Approved revision: 1c54cd378f08b9d6e28ba5deb3c9612a4114e504
Merged at revision: 1c54cd378f08b9d6e28ba5deb3c9612a4114e504
Proposed branch: ~racb/git-ubuntu:commit-message-spec
Merge into: git-ubuntu:master
Diff against target: 625 lines (+200/-184)
5 files modified
gitubuntu/clone.py (+2/-0)
gitubuntu/git_repository.py (+7/-0)
gitubuntu/importer.py (+103/-126)
gitubuntu/importer_tag_test.py (+4/-0)
gitubuntu/importer_test.py (+84/-58)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Bryce Harrington Needs Fixing
Review via email: mp+381765@code.launchpad.net

Commit message

Make Jenkins happy

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:49d62ab97b7107abfb3dc2a993b50a74cf79215b
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/485/
Executed test runs:
    SUCCESS: VM Setup
    SUCCESS: Build
    SUCCESS: Unit Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/485//rebuild

review: Approve (continuous-integration)
Revision history for this message
Bryce Harrington (bryce) wrote :
Download full text (3.8 KiB)

Looks good, I just ask for a couple comments for the refs fetch and push, and a couple minor inline notes. Otherwise looks solid, some really good refactoring, and I'm looking forward to seeing the new notes feature in practice. I'm still a bit nervous that this will uncover warts in git, but maybe not, and in any case it feels like the right way to go technically.

If you agree with the comment suggestions, please go ahead and land after adding, no need for second round of review.

* Review
  √ python3 setup.py build
  √ python3 setup.py check
  √ ./snap-wrappers/wrappers/git-ubuntu-self-test
    No broken requirements found.
    pip3 found all required dependencies
    pylint passed!
    PASS (syntax) source-package-walker.py
    PASS (compilation) source-package-walker.py
    PASS (syntax) update-repository-alias.py
    PASS (compilation) update-repository-alias.py
    PASS (syntax) import-source-packages.py
    PASS (compilation) import-source-packages.py
    332 passed, 3 xfailed in 187.90 seconds
  ! Per-patch code review
    √ ef26b8a077b6ff3a8c455d38fc838dad4625df00
      + Die wrappers!
      + LGTM
    √ 4bdd58db60bad113b1eb6a87621554f8f8bedef6
      + Pythonic objects FTW
      + LGTM
    √ 69bc94052dbd1793fce7f4f9f32b76cb2c8f3b98
      + Verified the promised skip of test_get_import_commit_msg() is
        indeed dropped in 061371a7 (next patch).
      + LGTM
    √ 061371a77089930b27a261ff0447ba60d517fa82
      + This is the key patch in the set. Moves change info from the
        commit message into the git note.
      + add_changelog_note_to_commit() is added, and has corresponding
        test cases test_add_changelog_note_to_commit() and
        test_double_changelog_note_add_does_not_fail()
      + Uses the new gitubuntu.spec module
      + LGTM
    √ 224684300a41a929492f981c453a3f71d77175d6
      + Largely cleanup/refactor from prior commit. Uses patch_state.
      + LGTM, nice cleanup
    √ 9323899deab7a1d57e3c0ac9f92a47f552602502
      + Verified all call points are updated with correct argument list.
      + LGTM
    √ 37ea80888ea65deaeeb509e3624e2a0f6b92d61c
      + Verified no consumers for _commit_import() other than importer.py, and all
        call points are updated with correct argument list.
      + LGTM
    ! a133d0da5316cedf72c220649ffa8691057a3c2c
      + If I understand the refspecs properly, then the fetch with this
        refspec:
        'refs/notes/commits:refs/notes/usd-import-team/changelog'
        will import the notes from 'refs/notes/commits' in the remote
        repository, into 'refs/notes/usd-import-team/changelog' in the
        local checkout. Then later, there is a repo.git_run() call that
        pushes them back in the opposite direction.
      + The commit message explains this sufficiently, but the
        _main_with_repo() itself is lengthy (250+ lines!) and only
        lightly commented, so this notes pushing/pulling feature may not
        be clear to future readers. This would be a good opportunity to
        add a comment each for the repo.fetch_remote_refspecs() and
        git_run() calls, to define the refspec's being fetched and
        pulled. Hopefully over time this ro...

Read more...

review: Needs Fixing
Revision history for this message
Robie Basak (racb) wrote :

Thank you for the review! Comments addressed and pushed. Just waiting now for CI before landing.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:1c54cd378f08b9d6e28ba5deb3c9612a4114e504
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/486/
Executed test runs:
    SUCCESS: VM Setup
    SUCCESS: Build
    SUCCESS: Unit Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/486//rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/gitubuntu/clone.py b/gitubuntu/clone.py
index ea8dee9..0eca56e 100644
--- a/gitubuntu/clone.py
+++ b/gitubuntu/clone.py
@@ -114,6 +114,8 @@ def main(
114 'pkg/ubuntu/devel branch exist?'114 'pkg/ubuntu/devel branch exist?'
115 )115 )
116116
117 local_repo.git_run(['config', 'notes.displayRef', 'refs/notes/changelog'])
118
117 if os.path.isfile(os.path.join(directory, '.gitignore')):119 if os.path.isfile(os.path.join(directory, '.gitignore')):
118 logging.warning('A .gitignore file exists in the source '120 logging.warning('A .gitignore file exists in the source '
119 'package. This will affect the behavior of git. Consider '121 'package. This will affect the behavior of git. Consider '
diff --git a/gitubuntu/git_repository.py b/gitubuntu/git_repository.py
index 49bd9b8..ce7ebe8 100644
--- a/gitubuntu/git_repository.py
+++ b/gitubuntu/git_repository.py
@@ -1305,6 +1305,13 @@ class GitUbuntuRepository:
1305 remote_name,1305 remote_name,
1306 '+refs/tags/*:refs/tags/%s/*' % remote_name,1306 '+refs/tags/*:refs/tags/%s/*' % remote_name,
1307 )1307 )
1308 # The changelog notes are kept at refs/notes/commits on
1309 # Launchpad due to LP: #1871838 even though our standard place for
1310 # them is refs/notes/changelog.
1311 self.raw_repo.remotes.add_fetch(
1312 remote_name,
1313 '+refs/notes/commits:refs/notes/changelog',
1314 )
1308 if push_url:1315 if push_url:
1309 self.raw_repo.remotes.set_push_url(1316 self.raw_repo.remotes.set_push_url(
1310 remote_name,1317 remote_name,
diff --git a/gitubuntu/importer.py b/gitubuntu/importer.py
index 6d546bc..604b478 100644
--- a/gitubuntu/importer.py
+++ b/gitubuntu/importer.py
@@ -66,6 +66,7 @@ from gitubuntu.source_information import (
66 SourceExtractionException,66 SourceExtractionException,
67 launchpad_login_auth,67 launchpad_login_auth,
68)68)
69import gitubuntu.spec as spec
69from gitubuntu.version import VERSION70from gitubuntu.version import VERSION
70from gitubuntu.versioning import version_compare71from gitubuntu.versioning import version_compare
71try:72try:
@@ -181,8 +182,16 @@ def _main_with_repo(
181182
182 if not no_fetch and not reimport:183 if not no_fetch and not reimport:
183 try:184 try:
185 # This is a normal import run. Fetch in to the "namespaced" local
186 # refs the tags and changelog notes (the branch fetches are handled
187 # elsewhere). The changelog notes are kept at refs/notes/commits on
188 # Launchpad due to LP: #1871838 even though our standard place for
189 # them is refs/notes/changelog.
184 repo.fetch_remote_refspecs('pkg',190 repo.fetch_remote_refspecs('pkg',
185 refspecs=['refs/tags/*:refs/tags/%s/*' % namespace],191 refspecs=[
192 'refs/tags/*:refs/tags/%s/*' % namespace,
193 'refs/notes/commits:refs/notes/%s/changelog' % namespace,
194 ],
186 )195 )
187 except GitUbuntuRepositoryFetchError:196 except GitUbuntuRepositoryFetchError:
188 pass197 pass
@@ -365,6 +374,8 @@ def _main_with_repo(
365 'push', '--atomic', 'pkg',374 'push', '--atomic', 'pkg',
366 '+refs/heads/%s/*:refs/heads/*' % namespace,375 '+refs/heads/%s/*:refs/heads/*' % namespace,
367 'refs/tags/%s/*:refs/tags/*' % namespace,376 'refs/tags/%s/*:refs/tags/*' % namespace,
377 # Changelog notes go to refs/notes/commits due to LP: #1871838
378 'refs/notes/%s/changelog:refs/notes/commits' % namespace,
368 ])379 ])
369 # update our reference380 # update our reference
370 lp_git_repo = lp.git_repositories.getByPath(path=repo_path)381 lp_git_repo = lp.git_repositories.getByPath(path=repo_path)
@@ -530,12 +541,7 @@ def get_changelog_for_commit(
530def get_import_commit_msg(541def get_import_commit_msg(
531 repo,542 repo,
532 version,543 version,
533 target_head_name,544 patch_state,
534 namespace,
535 tree_hash,
536 changelog_parent_commits,
537 upload_parent_commit,
538 unapplied_parent_commit,
539):545):
540 """Compose an appropriate commit message546 """Compose an appropriate commit message
541547
@@ -546,62 +552,30 @@ def get_import_commit_msg(
546 :param GitUbuntuRepository repo: the repository in which the tree being552 :param GitUbuntuRepository repo: the repository in which the tree being
547 committed can be found553 committed can be found
548 :param str version: the package version string being committed554 :param str version: the package version string being committed
549 :param str target_head_name: the nominal name of the branch to which the555 :param PatchState patch_state: whether the commit is for an unapplied or
550 commit is being made556 applied import
551 :param str namespace: the namespace name to prefix to the nominal branch557 :rtype: bytes
552 name to determine the final branch name558 :returns: the commit message to use
553 :param str tree_hash: the hash of the tree object being committed
554 :param list(str) changelog_parent_commits: any changelog parents to use in
555 the commit
556 :param str upload_parent_commit: the upload parent to use in the commit, or
557 None if there isn't one
558 :param str unapplied_parent_commit: the unapplied parent to use in the
559 commit, or None if this is an applied branch commit
560
561 """559 """
562 if unapplied_parent_commit:560 import_type = {
563 import_type = 'patches-applied'561 PatchState.UNAPPLIED: 'patches unapplied',
564 else:562 PatchState.APPLIED: 'patches applied',
565 import_type = 'patches-unapplied'563 }[patch_state]
566564
567 # Do not show importer/ namespace to user565 return (
568 _, _, pretty_head_name = target_head_name.partition('%s/' % namespace)566 b'%b (%b)\n\nImported using git-ubuntu import.' % (
569 changelog_entry = get_changelog_for_commit(
570 repo,
571 tree_hash,
572 changelog_parent_commits
573 )
574
575 msg = (
576 b'Import %s version %b to %b\n\nImported using git-ubuntu import.' % (
577 import_type.encode(),
578 version.encode(),567 version.encode(),
579 pretty_head_name.encode(),568 import_type.encode(),
580 )569 )
581 )570 )
582571
583 if any([changelog_parent_commits, upload_parent_commit, unapplied_parent_commit]):
584 msg += b'\n'
585
586 for changelog_parent_commit in changelog_parent_commits:
587 msg += b'\nChangelog parent: %b' % changelog_parent_commit.encode()
588 if upload_parent_commit is not None:
589 msg += b'\nUpload parent: %b' % upload_parent_commit.encode()
590 if unapplied_parent_commit is not None:
591 msg += b'\nUnapplied parent: %b' % unapplied_parent_commit.encode()
592
593 msg += b'%b' % changelog_entry
594
595 return msg
596572
597def _commit_import(573def _commit_import(
598 repo,574 repo,
599 version,575 version,
600 target_head_name,
601 tree_hash,576 tree_hash,
602 namespace,577 namespace,
603 changelog_parent_commits,578 changelog_parent_commits,
604 upload_parent_commit,
605 unapplied_parent_commit,579 unapplied_parent_commit,
606 commit_date,580 commit_date,
607):581):
@@ -617,19 +591,16 @@ def _commit_import(
617 which the source package contents corresponding to @spi should591 which the source package contents corresponding to @spi should
618 be imported.592 be imported.
619 :param version str Changelog version593 :param version str Changelog version
620 :param target_head_name str Git branch name to import to
621 :param namespace str Namespace under which relevant refs can be594 :param namespace str Namespace under which relevant refs can be
622 found.595 found.
623 :param list(str) changelog_parent_commits Git commit hashes of changelog596 :param list(str) changelog_parent_commits Git commit hashes of changelog
624 parents.597 parents.
625 :param upload_parent_commit str Git commit hash of
626 upload parent. Should be None if patches-applied import.
627 :param unapplied_parent_commit str Git commit hash of unapplied598 :param unapplied_parent_commit str Git commit hash of unapplied
628 parent. Should be None if patches-unapplied import.599 parent. Should be None if patches-unapplied import.
629 :param str commit_date: committer date to use for the git commit metadata600 :param str commit_date: committer date to use for the git commit metadata
630601
631 :rtype str602 :rtype: pygit2.Commit
632 :returns Hash of created commit603 :returns: created commit object
633 """604 """
634 parents = []605 parents = []
635606
@@ -637,75 +608,27 @@ def _commit_import(
637 pygit2.Oid(hex=changelog_parent_commit)608 pygit2.Oid(hex=changelog_parent_commit)
638 for changelog_parent_commit in changelog_parent_commits609 for changelog_parent_commit in changelog_parent_commits
639 )610 )
640 if upload_parent_commit is not None:
641 parents.append(pygit2.Oid(hex=upload_parent_commit))
642 if unapplied_parent_commit is not None:611 if unapplied_parent_commit is not None:
643 parents.append(pygit2.Oid(hex=unapplied_parent_commit))612 parents.append(pygit2.Oid(hex=unapplied_parent_commit))
644613
614 if unapplied_parent_commit:
615 patch_state = PatchState.APPLIED
616 else:
617 patch_state = PatchState.UNAPPLIED
618
645 commit_hash = repo.commit_source_tree(619 commit_hash = repo.commit_source_tree(
646 tree=pygit2.Oid(hex=tree_hash),620 tree=pygit2.Oid(hex=tree_hash),
647 parents=parents,621 parents=parents,
648 log_message=get_import_commit_msg(622 log_message=get_import_commit_msg(
649 repo=repo,623 repo=repo,
650 version=version,624 version=version,
651 target_head_name=target_head_name,625 patch_state=patch_state,
652 namespace=namespace,
653 tree_hash=tree_hash,
654 changelog_parent_commits=changelog_parent_commits,
655 upload_parent_commit=upload_parent_commit,
656 unapplied_parent_commit=unapplied_parent_commit,
657 ),626 ),
658 commit_date=commit_date,627 commit_date=commit_date,
659 )628 )
660629
661 return str(commit_hash)630 return repo.raw_repo.get(str(commit_hash))
662631
663def commit_unapplied_patches_import(
664 repo,
665 version,
666 head_name,
667 import_tree_hash,
668 namespace,
669 changelog_parent_commits,
670 upload_parent_commit,
671 commit_date,
672):
673 return _commit_import(
674 repo,
675 version,
676 head_name,
677 import_tree_hash,
678 namespace,
679 changelog_parent_commits,
680 upload_parent_commit,
681 # unapplied trees do not have a distinct unapplied parent
682 None,
683 commit_date,
684 )
685
686def commit_applied_patches_import(
687 repo,
688 version,
689 head_name,
690 import_tree_hash,
691 namespace,
692 changelog_parent_commits,
693 unapplied_parent_commit,
694 commit_date,
695):
696 return _commit_import(
697 repo,
698 version,
699 head_name,
700 import_tree_hash,
701 namespace,
702 changelog_parent_commits,
703 # uploads will be unapplied trees currently, so applied trees
704 # can not have them as direct parents
705 None,
706 unapplied_parent_commit,
707 commit_date,
708 )
709632
710def import_dsc(repo, dsc, namespace, version, dist):633def import_dsc(repo, dsc, namespace, version, dist):
711 """Imports the dsc file to importer/{debian,ubuntu}/dsc634 """Imports the dsc file to importer/{debian,ubuntu}/dsc
@@ -1526,6 +1449,61 @@ def validate_upload_tag(
1526 return True1449 return True
15271450
15281451
1452def add_changelog_note_to_commit(
1453 repo,
1454 namespace,
1455 commit,
1456 changelog_parents,
1457):
1458 """Compute and add a changelog note to the given commit.
1459
1460 For user convenience, changelog notes allow for "git log" and similar tools
1461 to display the debian/changelog entry associated with a
1462 importer-synthesized commit. See LP #1633114 for details.
1463
1464 If a changelog note already exists for the given commit, then return
1465 without doing anything.
1466
1467 :param gitubuntu.GitUbuntuRepository repo: the repository that is the
1468 target of this import.
1469 :param str namespace: the namespace under which relevant refs can be found.
1470 :param pygit2.Commit commit: the commit for which the changelog note should
1471 be calculated and added.
1472 :param list(str) changelog_parents: the list of commit hashes that are the
1473 parents of the provided commit, from which the changelog note may be
1474 calculated.
1475 :returns: None
1476 """
1477 # If the note already exists, return without doing anything.
1478 try:
1479 repo.raw_repo.lookup_note(
1480 str(commit.id),
1481 'refs/notes/%s/changelog' % namespace,
1482 )
1483 except KeyError:
1484 pass
1485 else:
1486 return
1487
1488 # The note doesn't exist, so figure out what it should be and add it.
1489 changelog_summary = get_changelog_for_commit(
1490 repo=repo,
1491 tree_hash=str(commit.peel(pygit2.Tree).id),
1492 changelog_parent_commits=changelog_parents,
1493 )
1494 changelog_signature = pygit2.Signature(
1495 spec.SYNTHESIZED_COMMITTER_NAME,
1496 spec.SYNTHESIZED_COMMITTER_EMAIL,
1497 )
1498 repo.raw_repo.create_note(
1499 changelog_summary.decode(),
1500 changelog_signature,
1501 changelog_signature,
1502 str(commit.id),
1503 'refs/notes/%s/changelog' % namespace,
1504 )
1505
1506
1529def find_or_create_unapplied_commit(1507def find_or_create_unapplied_commit(
1530 repo,1508 repo,
1531 version,1509 version,
@@ -1533,7 +1511,6 @@ def find_or_create_unapplied_commit(
1533 import_tree,1511 import_tree,
1534 parent_overrides,1512 parent_overrides,
1535 commit_date,1513 commit_date,
1536 head_name,
1537):1514):
1538 """Return the commit to be used for an unapplied import1515 """Return the commit to be used for an unapplied import
15391516
@@ -1559,9 +1536,6 @@ def find_or_create_unapplied_commit(
1559 :param dict parent_overrides: see parse_parentfile()1536 :param dict parent_overrides: see parse_parentfile()
1560 :param str commit_date: committer date to use for the git commit metadata.1537 :param str commit_date: committer date to use for the git commit metadata.
1561 If None, use the current date.1538 If None, use the current date.
1562 :param str head_name: git branch name that is the target of this import.
1563 This is currently used in the generated commit message, but will go
1564 away when the commit messages are overhauled to the new spec.
1565 :rtype: tuple(pygit2.Commit, pygit2.Reference or None)1539 :rtype: tuple(pygit2.Commit, pygit2.Reference or None)
1566 :returns: the commit that has been found or created, and the import tag1540 :returns: the commit that has been found or created, and the import tag
1567 corresponding to an existing import if it had previously existed.1541 corresponding to an existing import if it had previously existed.
@@ -1596,21 +1570,26 @@ def find_or_create_unapplied_commit(
1596 return upload_tag.peel(), None1570 return upload_tag.peel(), None
15971571
1598 # Create a commit1572 # Create a commit
1599 commit = repo.raw_repo.get(commit_unapplied_patches_import(1573 commit = _commit_import(
1600 repo=repo,1574 repo=repo,
1601 version=version,1575 version=version,
1602 head_name=head_name,1576 tree_hash=str(import_tree.id),
1603 import_tree_hash=str(import_tree.id),
1604 namespace=namespace,1577 namespace=namespace,
1605 changelog_parent_commits=changelog_parents,1578 changelog_parent_commits=changelog_parents,
1606 upload_parent_commit=None,1579 # unapplied trees do not have a distinct unapplied parent
1580 unapplied_parent_commit=None,
1607 commit_date=commit_date,1581 commit_date=commit_date,
1608 ))1582 )
1609 logging.debug(1583 logging.debug(
1610 "Committed patches-unapplied import of %s as %s in %s",1584 "Committed patches-unapplied import of %s as %s",
1611 version,1585 version,
1612 str(commit.id),1586 str(commit.id),
1613 head_name.partition('%s/' % namespace)[2],1587 )
1588 add_changelog_note_to_commit(
1589 repo=repo,
1590 namespace=namespace,
1591 commit=commit,
1592 changelog_parents=changelog_parents,
1614 )1593 )
1615 return commit, None1594 return commit, None
16161595
@@ -1686,7 +1665,6 @@ def import_unapplied_dsc(
1686 import_tree=repo.raw_repo.get(unapplied_import_tree_hash),1665 import_tree=repo.raw_repo.get(unapplied_import_tree_hash),
1687 parent_overrides=parent_overrides,1666 parent_overrides=parent_overrides,
1688 commit_date=commit_date,1667 commit_date=commit_date,
1689 head_name=head_name,
1690 )1668 )
1691 except ParentOverrideError as e:1669 except ParentOverrideError as e:
1692 logging.error("%s" % e)1670 logging.error("%s" % e)
@@ -1917,16 +1895,15 @@ def import_applied_dsc(
1917 return1895 return
1918 raise1896 raise
19191897
1920 commit_hash = commit_applied_patches_import(1898 commit_hash = str(_commit_import(
1921 repo=repo,1899 repo=repo,
1922 version=version,1900 version=version,
1923 head_name=head_name,1901 tree_hash=applied_import_tree_hash,
1924 import_tree_hash=applied_import_tree_hash,
1925 namespace=namespace,1902 namespace=namespace,
1926 changelog_parent_commits=applied_changelog_parent_commits,1903 changelog_parent_commits=applied_changelog_parent_commits,
1927 unapplied_parent_commit=str(unapplied_parent_commit),1904 unapplied_parent_commit=str(unapplied_parent_commit),
1928 commit_date=commit_date,1905 commit_date=commit_date,
1929 )1906 ).id)
1930 logging.debug(1907 logging.debug(
1931 "Committed patches-applied import of %s as %s in %s",1908 "Committed patches-applied import of %s as %s in %s",
1932 version,1909 version,
diff --git a/gitubuntu/importer_tag_test.py b/gitubuntu/importer_tag_test.py
index a216e73..3573d9b 100644
--- a/gitubuntu/importer_tag_test.py
+++ b/gitubuntu/importer_tag_test.py
@@ -205,6 +205,7 @@ from gitubuntu.importer_test import MockSPI, patch_get_commit_environment
205 'refs/tags/importer/upstream/ubuntu/1.gz',205 'refs/tags/importer/upstream/ubuntu/1.gz',
206 'refs/heads/importer/importer/ubuntu/dsc',206 'refs/heads/importer/importer/ubuntu/dsc',
207 'refs/heads/importer/importer/ubuntu/pristine-tar',207 'refs/heads/importer/importer/ubuntu/pristine-tar',
208 'refs/notes/importer/changelog',
208 ],209 ],
209 # validation_repo_delta:210 # validation_repo_delta:
210 {211 {
@@ -255,6 +256,7 @@ from gitubuntu.importer_test import MockSPI, patch_get_commit_environment
255 'refs/tags/importer/upstream/ubuntu/1.gz',256 'refs/tags/importer/upstream/ubuntu/1.gz',
256 'refs/heads/importer/importer/ubuntu/dsc',257 'refs/heads/importer/importer/ubuntu/dsc',
257 'refs/heads/importer/importer/ubuntu/pristine-tar',258 'refs/heads/importer/importer/ubuntu/pristine-tar',
259 'refs/notes/importer/changelog',
258 ],260 ],
259 # validation_repo_delta:261 # validation_repo_delta:
260 {262 {
@@ -335,6 +337,7 @@ from gitubuntu.importer_test import MockSPI, patch_get_commit_environment
335 'refs/tags/importer/upstream/ubuntu/1.gz',337 'refs/tags/importer/upstream/ubuntu/1.gz',
336 'refs/heads/importer/importer/ubuntu/dsc',338 'refs/heads/importer/importer/ubuntu/dsc',
337 'refs/heads/importer/importer/ubuntu/pristine-tar',339 'refs/heads/importer/importer/ubuntu/pristine-tar',
340 'refs/notes/importer/changelog',
338 ],341 ],
339 # validation_repo_delta:342 # validation_repo_delta:
340 {343 {
@@ -372,6 +375,7 @@ from gitubuntu.importer_test import MockSPI, patch_get_commit_environment
372 'refs/tags/importer/upstream/ubuntu/1.gz',375 'refs/tags/importer/upstream/ubuntu/1.gz',
373 'refs/heads/importer/importer/ubuntu/dsc',376 'refs/heads/importer/importer/ubuntu/dsc',
374 'refs/heads/importer/importer/ubuntu/pristine-tar',377 'refs/heads/importer/importer/ubuntu/pristine-tar',
378 'refs/notes/importer/changelog',
375 ],379 ],
376 # validation_repo_delta:380 # validation_repo_delta:
377 {381 {
diff --git a/gitubuntu/importer_test.py b/gitubuntu/importer_test.py
index 54f1f2b..f94150d 100644
--- a/gitubuntu/importer_test.py
+++ b/gitubuntu/importer_test.py
@@ -73,58 +73,21 @@ def test_get_import_tag_msg():
7373
7474
75@pytest.mark.parametrize(75@pytest.mark.parametrize(
76 'head_name_value, changelog_parent_commits, upload_parent_commit, unapplied_parent_commit, expected',76 'patch_state, expected',
77 [77 [
78 (78 (
79 'importer/ubuntu/trusty',79 PatchState.UNAPPLIED,
80 [],80 b'1-1 (patches unapplied)\n\nImported using git-ubuntu import.',
81 None,
82 None,
83 b'Import patches-unapplied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.',
84 ),
85 (
86 'importer/ubuntu/trusty',
87 ['123456'],
88 None,
89 None,
90 b'Import patches-unapplied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nChangelog parent: 123456',
91 ),
92 (
93 'importer/ubuntu/trusty',
94 [],
95 '123456',
96 None,
97 b'Import patches-unapplied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nUpload parent: 123456',
98 ),
99 (
100 'importer/ubuntu/trusty',
101 ['123456', '234567'],
102 None,
103 None,
104 b'Import patches-unapplied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nChangelog parent: 123456\nChangelog parent: 234567',
105 ),
106 (
107 'importer/ubuntu/trusty',
108 [],
109 None,
110 '123456',
111 b'Import patches-applied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nUnapplied parent: 123456',
112 ),81 ),
113 (82 (
114 'importer/ubuntu/trusty',83 PatchState.APPLIED,
115 ['123456'],84 b'1-1 (patches applied)\n\nImported using git-ubuntu import.',
116 '789123',
117 '456789',
118 b'Import patches-applied version 1-1 to ubuntu/trusty\n\nImported using git-ubuntu import.\n\nChangelog parent: 123456\nUpload parent: 789123\nUnapplied parent: 456789'
119 ),85 ),
120 ],86 ],
121)87)
122def test_get_import_commit_msg(88def test_get_import_commit_msg(
123 repo,89 repo,
124 head_name_value,90 patch_state,
125 changelog_parent_commits,
126 upload_parent_commit,
127 unapplied_parent_commit,
128 expected,91 expected,
129):92):
130 """Test that get_import_commit_msg is generally correct93 """Test that get_import_commit_msg is generally correct
@@ -138,17 +101,10 @@ def test_get_import_commit_msg(
138101
139 :param GitUbuntuRepository repo: fixture providing a temporary102 :param GitUbuntuRepository repo: fixture providing a temporary
140 GitUbuntuRepository instance to use103 GitUbuntuRepository instance to use
141 :param str head_name_value: passed through to get_import_commit_msg as104 :param PatchState patch_state: whether the commit is for an unapplied or
142 target_head_name105 applied import, as passed through to the function under test
143 :param list(str) changelog_parent_commits: passed through to
144 get_import_commit_msg
145 :param str upload_parent_commit: passed through to get_import_commit_msg
146 :param str unapplied_parent_commit: passed through to get_import_commit_msg
147 :param bytes expected: the expected return value from get_import_commit_msg106 :param bytes expected: the expected return value from get_import_commit_msg
148 """107 """
149 target.get_changelog_for_commit = Mock()
150 target.get_changelog_for_commit.return_value = b''
151
152 publish_spec = source_builder.SourceSpec()108 publish_spec = source_builder.SourceSpec()
153 publish_source = source_builder.Source(publish_spec)109 publish_source = source_builder.Source(publish_spec)
154110
@@ -160,12 +116,7 @@ def test_get_import_commit_msg(
160 assert target.get_import_commit_msg(116 assert target.get_import_commit_msg(
161 repo,117 repo,
162 publish_spec.version,118 publish_spec.version,
163 head_name_value,119 patch_state,
164 'importer',
165 publish_tree_hash,
166 changelog_parent_commits,
167 upload_parent_commit,
168 unapplied_parent_commit,
169 ) == expected120 ) == expected
170121
171122
@@ -862,6 +813,81 @@ def test_validate_upload_tag(
862 assert result == expected_result813 assert result == expected_result
863814
864815
816def test_add_changelog_note_to_commit(repo):
817 """add_changelog_note_to_commit should add the expected note"""
818 repo_builder.Repo(
819 commits=[
820 repo_builder.Commit.from_spec(name='1-1'),
821 repo_builder.Commit.from_spec(
822 name='1-2',
823 changelog_versions=['1-1', '1-2'],
824 parents=[Placeholder('1-1')],
825 ),
826 ],
827 tags={'1-1': Placeholder('1-1'), '1-2': Placeholder('1-2')},
828 ).write(repo.raw_repo)
829
830 parent_commit_ref = repo.raw_repo.lookup_reference('refs/tags/1-1')
831 parent_commit = parent_commit_ref.peel(pygit2.Commit)
832
833 child_commit_ref = repo.raw_repo.lookup_reference('refs/tags/1-2')
834 child_commit = child_commit_ref.peel(pygit2.Commit)
835
836 target.add_changelog_note_to_commit(
837 repo=repo,
838 namespace='importer',
839 commit=child_commit,
840 changelog_parents=[str(parent_commit.id)],
841 )
842
843 note = repo.raw_repo.lookup_note(
844 str(child_commit.id),
845 'refs/notes/importer/changelog',
846 )
847 assert note.message == (
848 "\n\nNew changelog entries:\n"
849 " * Test build from source_builder.\n"
850 )
851
852
853def test_double_changelog_note_add_does_not_fail(repo):
854 """add_changelog_note_to_commit shouldn't fail if a note already exists"""
855 repo_builder.Repo(
856 commits=[
857 repo_builder.Commit.from_spec(name='1-1'),
858 repo_builder.Commit.from_spec(
859 name='1-2',
860 changelog_versions=['1-1', '1-2'],
861 parents=[Placeholder('1-1')],
862 ),
863 ],
864 tags={'1-1': Placeholder('1-1'), '1-2': Placeholder('1-2')},
865 ).write(repo.raw_repo)
866
867 parent_commit_ref = repo.raw_repo.lookup_reference('refs/tags/1-1')
868 parent_commit = parent_commit_ref.peel(pygit2.Commit)
869
870 child_commit_ref = repo.raw_repo.lookup_reference('refs/tags/1-2')
871 child_commit = child_commit_ref.peel(pygit2.Commit)
872
873 # The first call should create the note (tested elsewhere)
874 target.add_changelog_note_to_commit(
875 repo=repo,
876 namespace='importer',
877 commit=child_commit,
878 changelog_parents=[str(parent_commit.id)],
879 )
880
881 # The second call should not fail even though the note already exists (as
882 # created by the previous call)
883 target.add_changelog_note_to_commit(
884 repo=repo,
885 namespace='importer',
886 commit=child_commit,
887 changelog_parents=[str(parent_commit.id)],
888 )
889
890
865def patch_get_commit_environment(repo):891def patch_get_commit_environment(repo):
866 """Patch a repository to use constant metadata892 """Patch a repository to use constant metadata
867893

Subscribers

People subscribed via source and target branches