Merge ~nacc/git-ubuntu:lp1708203-lint-do-not-clobber-working-tree into git-ubuntu:master

Proposed by Nish Aravamudan
Status: Merged
Approved by: Nish Aravamudan
Approved revision: 6455fd2a387064fafca47b7c8494a619acc3020a
Merged at revision: bf0c2c109ff9b283e1c9781132e80e92752c7ed3
Proposed branch: ~nacc/git-ubuntu:lp1708203-lint-do-not-clobber-working-tree
Merge into: git-ubuntu:master
Diff against target: 126 lines (+42/-51)
2 files modified
gitubuntu/git_repository.py (+26/-0)
gitubuntu/lint.py (+16/-51)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Robie Basak Pending
Andreas Hasenack Pending
Review via email: mp+330940@code.launchpad.net

This proposal supersedes a proposal from 2017-09-14.

Description of the change

Make jenkins happy.

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

PASSED: Continuous integration, rev:2df8748cf2a58aa40b37bc765698184abb7ae2ac
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/85/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

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

review: Approve (continuous-integration)
Revision history for this message
Robie Basak (racb) : Posted in a previous version of this proposal
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:6455fd2a387064fafca47b7c8494a619acc3020a
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/98/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

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

review: Approve (continuous-integration)
Revision history for this message
Robie Basak (racb) wrote : Posted in a previous version of this proposal

Looks good! Really tidy.

tree_hash_after_command may want to take multiple commands eventually but I suppose it's probably YAGNI right now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/gitubuntu/git_repository.py b/gitubuntu/git_repository.py
2index 7ed7bdb..2c3e410 100644
3--- a/gitubuntu/git_repository.py
4+++ b/gitubuntu/git_repository.py
5@@ -1509,3 +1509,29 @@ class GitUbuntuRepository:
6 else:
7 # No empty directories were added
8 return tree_hash_str # no replacement was needed
9+
10+ @contextmanager
11+ def temporary_worktree(self, commitish):
12+ with tempfile.TemporaryDirectory() as tempdir:
13+ self.git_run(['worktree', 'add', '--force', tempdir, commitish])
14+
15+ oldcwd = os.getcwd()
16+ os.chdir(tempdir)
17+
18+ yield
19+
20+ os.chdir(oldcwd)
21+ self.git_run(['worktree', 'prune'])
22+
23+ def tree_hash_after_command(self, commitish, cmd):
24+ with self.temporary_worktree(commitish):
25+ try:
26+ run(cmd)
27+ except CalledProcessError as e:
28+ logging.error("Unable to execute `%s`", ' '.join(cmd))
29+ raise
30+
31+ run(["git", "add", "-f", ".",])
32+ cp = run(["git", "write-tree"])
33+ tree_hash = decode_binary(cp.stdout).strip()
34+ return tree_hash
35diff --git a/gitubuntu/lint.py b/gitubuntu/lint.py
36index a5850a2..baa1492 100644
37--- a/gitubuntu/lint.py
38+++ b/gitubuntu/lint.py
39@@ -440,20 +440,15 @@ def hunk_in_patch(hunk, patch):
40 return False
41
42 def tree_after_merge_changelogs(repo, old, new):
43- if repo.raw_repo.head_is_detached:
44- head_string = str(repo.raw_repo.head.peel(pygit2.Commit).id)
45- else:
46- head_string = repo.raw_repo.head.name[len('refs/heads/'):]
47-
48- merge_base_id = str(
49- repo.raw_repo.merge_base(
50- repo.get_commitish(old).id,
51- repo.get_commitish(new).id
52- )
53- )
54- repo.checkout_commitish(new)
55 changelog_files = []
56 try:
57+ merge_base_id = str(
58+ repo.raw_repo.merge_base(
59+ repo.get_commitish(old).id,
60+ repo.get_commitish(new).id
61+ )
62+ )
63+
64 for tree in [merge_base_id, old, new]:
65 changelog_files.append(
66 repo.extract_file_from_treeish(
67@@ -461,50 +456,20 @@ def tree_after_merge_changelogs(repo, old, new):
68 "debian/changelog",
69 )
70 )
71- run(["dpkg-mergechangelogs"] + [f.name for f in changelog_files] +
72- ["debian/changelog"]
73- )
74- repo.git_run(
75- ["--work-tree", ".", "add", "-f", "debian/changelog"],
76- )
77- cp = repo.git_run(
78- ["--work-tree", ".", "write-tree"],
79- )
80- return decode_binary(cp.stdout).strip()
81- except (CalledProcessError, FileNotFoundError):
82- logging.error("Unable to find/execute dpkg-mergechangelogs")
83- return None
84+
85+ cmd = ["dpkg-mergechangelogs",]
86+ cmd.extend(f.name for f in changelog_files)
87+ cmd.extend(["debian/changelog",])
88+ return repo.tree_hash_after_command(new, cmd)
89 finally:
90 for f in changelog_files:
91 f.close()
92- repo.git_run(["clean", "-f", "-d"])
93- repo.reset_commitish(new)
94- repo.checkout_commitish(head_string)
95
96 def _tree_after_update_maintainer(repo, commitish_string):
97- if repo.raw_repo.head_is_detached:
98- head_string = str(repo.raw_repo.head.peel(pygit2.Commit).id)
99- else:
100- head_string = repo.raw_repo.head.name[len('refs/heads/'):]
101-
102- repo.checkout_commitish(commitish_string)
103- try:
104- run(["update-maintainer"])
105- except (CalledProcessError, FileNotFoundError):
106- logging.error("Unable to find/execute update-maintainer")
107- return None
108- else:
109- repo.git_run(
110- ["--work-tree", ".", "add", "-f", "-A"],
111- )
112- cp = repo.git_run(
113- ["--work-tree", ".", "write-tree"],
114- )
115- return decode_binary(cp.stdout).strip()
116- finally:
117- repo.git_run(["clean", "-f", "-d"])
118- repo.reset_commitish(commitish_string)
119- repo.checkout_commitish(head_string)
120+ return repo.tree_hash_after_command(
121+ commitish_string,
122+ ["update-maintainer",]
123+ )
124
125 def _check_update_maintainer(repo, commitish_string):
126 commitish = repo.get_commitish(commitish_string)

Subscribers

People subscribed via source and target branches