1 |
commit: 8aa1a070921dc643d615a3c38b4f60e55e709850 |
2 |
Author: Manuel RĂ¼ger <mrueg <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri May 26 11:59:27 2017 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jun 6 01:56:05 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=8aa1a070 |
7 |
|
8 |
GitSync: Support setting environment variables for git |
9 |
|
10 |
This can be used to provide private SSH keys to portage in order to |
11 |
clone repositories from a non-public repository. |
12 |
|
13 |
An exemplary usage would be setting this in the repositories' repos.conf: |
14 |
sync-git-env = "GIT_SSH_COMMAND=ssh -i /etc/portage/.ssh/id_rsa -o UserKnownHostsFile=/etc/portage/.ssh/known_hosts" GIT_TRACE=false |
15 |
sync-git-pull-env = "GIT_SSH_COMMAND=ssh -i /etc/portage/.ssh/id_rsa -o UserKnownHostsFile=/etc/portage/.ssh/known_hosts" GIT_TRACE=true |
16 |
sync-git-clone-env = "GIT_SSH_COMMAND=ssh -i /etc/portage/.ssh/id_rsa -o UserKnownHostsFile=/etc/portage/.ssh/known_hosts" GIT_TRACE=true |
17 |
|
18 |
Closes: https://github.com/gentoo/portage/pull/165 |
19 |
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org> |
20 |
|
21 |
man/portage.5 | 24 +++++++++++++++++++++++- |
22 |
pym/portage/sync/modules/git/__init__.py | 5 ++++- |
23 |
pym/portage/sync/modules/git/git.py | 24 ++++++++++++++++++++++-- |
24 |
3 files changed, 49 insertions(+), 4 deletions(-) |
25 |
|
26 |
diff --git a/man/portage.5 b/man/portage.5 |
27 |
index 366a1fa85..5f1f2bbb0 100644 |
28 |
--- a/man/portage.5 |
29 |
+++ b/man/portage.5 |
30 |
@@ -1,4 +1,4 @@ |
31 |
-.TH "PORTAGE" "5" "Jan 2017" "Portage VERSION" "Portage" |
32 |
+.TH "PORTAGE" "31" "May 2017" "Portage VERSION" "Portage" |
33 |
.SH NAME |
34 |
portage \- the heart of Gentoo |
35 |
.SH "DESCRIPTION" |
36 |
@@ -979,9 +979,31 @@ Specifies CVS repository. |
37 |
.B sync\-depth |
38 |
This is a deprecated alias for the \fBclone\-depth\fR option. |
39 |
.TP |
40 |
+.B sync\-git\-clone\-env |
41 |
+Set environment variables for git when cloning repository (git clone). |
42 |
+This will override settings from sync-git-env. |
43 |
+.RS |
44 |
+.TP |
45 |
+.I Example: |
46 |
+sync-git-clone-env="VAR1=word1 word2" VAR2=word3 "VAR3=$word 5 6" |
47 |
+.br |
48 |
+Gives three variables "VAR1", "VAR2", "VAR3" with the values "word1 word2", |
49 |
+"word3", "$word 5 6". |
50 |
+.RE |
51 |
+.TP |
52 |
.B sync\-git\-clone\-extra\-opts |
53 |
Extra options to give to git when cloning repository (git clone). |
54 |
.TP |
55 |
+.B sync\-git\-env |
56 |
+Set environment variables for git when cloning or pulling the repository. |
57 |
+These will be overridden by setting them again in sync-git-clone-env and sync-git-pull-env. |
58 |
+See also example for sync-git-clone-env. |
59 |
+.TP |
60 |
+.B sync\-git\-pull\-env |
61 |
+Set environment variables for git when updating repository (git pull). |
62 |
+This will override settings from sync-git-env. |
63 |
+See also example for sync-git-clone-env. |
64 |
+.TP |
65 |
.B sync\-git\-pull\-extra\-opts |
66 |
Extra options to give to git when updating repository (git pull). |
67 |
.TP |
68 |
|
69 |
diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py |
70 |
index 60b7395b8..e7206e12d 100644 |
71 |
--- a/pym/portage/sync/modules/git/__init__.py |
72 |
+++ b/pym/portage/sync/modules/git/__init__.py |
73 |
@@ -1,4 +1,4 @@ |
74 |
-# Copyright 2014 Gentoo Foundation |
75 |
+# Copyright 2014-2017 Gentoo Foundation |
76 |
# Distributed under the terms of the GNU General Public License v2 |
77 |
|
78 |
doc = """Git plug-in module for portage. |
79 |
@@ -52,7 +52,10 @@ module_spec = { |
80 |
}, |
81 |
'validate_config': CheckGitConfig, |
82 |
'module_specific_options': ( |
83 |
+ 'sync-git-clone-env', |
84 |
'sync-git-clone-extra-opts', |
85 |
+ 'sync-git-env', |
86 |
+ 'sync-git-pull-env', |
87 |
'sync-git-pull-extra-opts', |
88 |
), |
89 |
} |
90 |
|
91 |
diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py |
92 |
index d432886dd..bea79c7e7 100644 |
93 |
--- a/pym/portage/sync/modules/git/git.py |
94 |
+++ b/pym/portage/sync/modules/git/git.py |
95 |
@@ -1,4 +1,4 @@ |
96 |
-# Copyright 2005-2015 Gentoo Foundation |
97 |
+# Copyright 2005-2017 Gentoo Foundation |
98 |
# Distributed under the terms of the GNU General Public License v2 |
99 |
|
100 |
import logging |
101 |
@@ -6,7 +6,7 @@ import subprocess |
102 |
|
103 |
import portage |
104 |
from portage import os |
105 |
-from portage.util import writemsg_level |
106 |
+from portage.util import writemsg_level, shlex_split |
107 |
from portage.output import create_color_func |
108 |
good = create_color_func("GOOD") |
109 |
bad = create_color_func("BAD") |
110 |
@@ -50,6 +50,16 @@ class GitSync(NewBase): |
111 |
sync_uri = sync_uri[6:] |
112 |
|
113 |
git_cmd_opts = "" |
114 |
+ if self.repo.module_specific_options.get('sync-git-env'): |
115 |
+ shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-env']) |
116 |
+ env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k) |
117 |
+ self.spawn_kwargs['env'].update(env) |
118 |
+ |
119 |
+ if self.repo.module_specific_options.get('sync-git-clone-env'): |
120 |
+ shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-clone-env']) |
121 |
+ clone_env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k) |
122 |
+ self.spawn_kwargs['env'].update(clone_env) |
123 |
+ |
124 |
if self.settings.get("PORTAGE_QUIET") == "1": |
125 |
git_cmd_opts += " --quiet" |
126 |
if self.repo.clone_depth is not None: |
127 |
@@ -86,6 +96,16 @@ class GitSync(NewBase): |
128 |
''' |
129 |
|
130 |
git_cmd_opts = "" |
131 |
+ if self.repo.module_specific_options.get('sync-git-env'): |
132 |
+ shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-env']) |
133 |
+ env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k) |
134 |
+ self.spawn_kwargs['env'].update(env) |
135 |
+ |
136 |
+ if self.repo.module_specific_options.get('sync-git-pull-env'): |
137 |
+ shlexed_env = shlex_split(self.repo.module_specific_options['sync-git-pull-env']) |
138 |
+ pull_env = dict((k, v) for k, _, v in (assignment.partition('=') for assignment in shlexed_env) if k) |
139 |
+ self.spawn_kwargs['env'].update(pull_env) |
140 |
+ |
141 |
if self.settings.get("PORTAGE_QUIET") == "1": |
142 |
git_cmd_opts += " --quiet" |
143 |
if self.repo.module_specific_options.get('sync-git-pull-extra-opts'): |