Gentoo Archives: gentoo-commits

From: Mike Gilbert <floppym@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/sync/modules/git/
Date: Sun, 03 Jul 2022 00:56:37
Message-Id: 1656702078.28d8d469ed8db68225fd50755655dcda61bd9a78.floppym@gentoo
1 commit: 28d8d469ed8db68225fd50755655dcda61bd9a78
2 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
3 AuthorDate: Fri Jul 1 18:53:30 2022 +0000
4 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
5 CommitDate: Fri Jul 1 19:01:18 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=28d8d469
7
8 git: mark repository as safe for newer gits
9
10 While this doesn't solve the odd permissions issue for communication
11 b/t gemato & git & portage, it does stop it manifesting.
12
13 This fixes compatibility with >=dev-vcs/git-2.35.2.
14
15 Bug: https://bugs.gentoo.org/838223
16 Bug: https://bugs.gentoo.org/838271
17 Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
18
19 lib/portage/sync/modules/git/git.py | 43 ++++++++++++++++++++++++++++++++-----
20 1 file changed, 38 insertions(+), 5 deletions(-)
21
22 diff --git a/lib/portage/sync/modules/git/git.py b/lib/portage/sync/modules/git/git.py
23 index 98670e1f9..381e31700 100644
24 --- a/lib/portage/sync/modules/git/git.py
25 +++ b/lib/portage/sync/modules/git/git.py
26 @@ -1,8 +1,9 @@
27 -# Copyright 2005-2020 Gentoo Authors
28 +# Copyright 2005-2022 Gentoo Authors
29 # Distributed under the terms of the GNU General Public License v2
30
31 import io
32 import logging
33 +import re
34 import subprocess
35
36 import portage
37 @@ -104,15 +105,19 @@ class GitSync(NewBase):
38
39 exitcode = portage.process.spawn_bash(
40 "cd %s ; exec %s" % (portage._shell_quote(self.repo.location), git_cmd),
41 - **self.spawn_kwargs
42 + **self.spawn_kwargs,
43 )
44 if exitcode != os.EX_OK:
45 msg = "!!! git clone error in %s" % self.repo.location
46 self.logger(self.xterm_titles, msg)
47 writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
48 return (exitcode, False)
49 +
50 + self.add_safe_directory()
51 +
52 if not self.verify_head():
53 return (1, False)
54 +
55 return (os.EX_OK, True)
56
57 def update(self):
58 @@ -152,6 +157,8 @@ class GitSync(NewBase):
59 " %s" % self.repo.module_specific_options["sync-git-pull-extra-opts"]
60 )
61
62 + self.add_safe_directory()
63 +
64 try:
65 remote_branch = portage._unicode_decode(
66 subprocess.check_output(
67 @@ -184,7 +191,7 @@ class GitSync(NewBase):
68 exitcode = portage.process.spawn(
69 gc_cmd,
70 cwd=portage._unicode_encode(self.repo.location),
71 - **self.spawn_kwargs
72 + **self.spawn_kwargs,
73 )
74 if exitcode != os.EX_OK:
75 msg = "!!! git gc error in %s" % self.repo.location
76 @@ -207,7 +214,7 @@ class GitSync(NewBase):
77
78 exitcode = portage.process.spawn_bash(
79 "cd %s ; exec %s" % (portage._shell_quote(self.repo.location), git_cmd),
80 - **self.spawn_kwargs
81 + **self.spawn_kwargs,
82 )
83
84 if exitcode != os.EX_OK:
85 @@ -231,7 +238,7 @@ class GitSync(NewBase):
86 exitcode = portage.process.spawn(
87 merge_cmd,
88 cwd=portage._unicode_encode(self.repo.location),
89 - **self.spawn_kwargs
90 + **self.spawn_kwargs,
91 )
92
93 if exitcode != os.EX_OK:
94 @@ -341,3 +348,29 @@ class GitSync(NewBase):
95 except subprocess.CalledProcessError:
96 ret = (1, False)
97 return ret
98 +
99 + def add_safe_directory(self):
100 + # Add safe.directory to system gitconfig if not already configured.
101 + # Workaround for bug #838271 and bug #838223.
102 + location_escaped = re.escape(self.repo.location)
103 + result = subprocess.run(
104 + [
105 + self.bin_command,
106 + "config",
107 + "--get",
108 + "safe.directory",
109 + f"^{location_escaped}$",
110 + ]
111 + )
112 + if result.returncode == 1:
113 + result = subprocess.run(
114 + [
115 + self.bin_command,
116 + "config",
117 + "--system",
118 + "--add",
119 + "safe.directory",
120 + self.repo.location,
121 + ]
122 + )
123 + return result.returncode == 0