@@ -108,17 +108,25 @@ def set_home(
108
108
monkeypatch .setenv ("HOME" , str (user_path ))
109
109
110
110
111
- @pytest .fixture
111
+ vcs_email = "libvcs@git-pull.com"
112
+
113
+
114
+ @pytest .fixture (scope = "session" )
112
115
@skip_if_git_missing
113
- def gitconfig (user_path : pathlib .Path ) -> pathlib .Path :
116
+ def gitconfig (
117
+ user_path : pathlib .Path ,
118
+ ) -> pathlib .Path :
114
119
"""Return git configuration, pytest fixture."""
115
120
gitconfig = user_path / ".gitconfig"
116
- user_email = "libvcs@git-pull.com"
121
+
122
+ if gitconfig .exists ():
123
+ return gitconfig
124
+
117
125
gitconfig .write_text (
118
126
textwrap .dedent (
119
127
f"""
120
128
[user]
121
- email = { user_email }
129
+ email = { vcs_email }
122
130
name = { getpass .getuser ()}
123
131
[color]
124
132
diff = auto
@@ -127,26 +135,26 @@ def gitconfig(user_path: pathlib.Path) -> pathlib.Path:
127
135
encoding = "utf-8" ,
128
136
)
129
137
130
- output = run (["git" , "config" , "--get" , "user.email" ])
131
- used_config_file_output = run (
132
- [
133
- "git" ,
134
- "config" ,
135
- "--show-origin" ,
136
- "--get" ,
137
- "user.email" ,
138
- ],
139
- )
140
- assert str (gitconfig ) in used_config_file_output
141
- assert user_email in output , "Should use our fixture config and home directory"
142
-
143
138
return gitconfig
144
139
145
140
146
141
@pytest .fixture
142
+ @skip_if_git_missing
143
+ def set_gitconfig (
144
+ monkeypatch : pytest .MonkeyPatch ,
145
+ gitconfig : pathlib .Path ,
146
+ ) -> pathlib .Path :
147
+ """Set git configuration."""
148
+ monkeypatch .setenv ("GIT_CONFIG" , str (gitconfig ))
149
+ return gitconfig
150
+
151
+
152
+ @pytest .fixture (scope = "session" )
147
153
@skip_if_hg_missing
148
- def hgconfig (user_path : pathlib .Path ) -> pathlib .Path :
149
- """Return Mercurial configuration, pytest fixture."""
154
+ def hgconfig (
155
+ user_path : pathlib .Path ,
156
+ ) -> pathlib .Path :
157
+ """Return Mercurial configuration."""
150
158
hgrc = <
10000
span class=pl-s1>user_path / ".hgrc"
151
159
hgrc .write_text (
152
160
textwrap .dedent (
@@ -164,6 +172,17 @@ def hgconfig(user_path: pathlib.Path) -> pathlib.Path:
164
172
return hgrc
165
173
166
174
175
+ @pytest .fixture
176
+ @skip_if_hg_missing
177
+ def set_hgconfig (
178
+ monkeypatch : pytest .MonkeyPatch ,
179
+ hgconfig : pathlib .Path ,
180
+ ) -> pathlib .Path :
181
+ """Set Mercurial configuration."""
182
+ monkeypatch .setenv ("HGRCPATH" , str (hgconfig ))
183
+ return hgconfig
184
+
185
+
167
186
@pytest .fixture
168
187
def projects_path (
169
188
user_path : pathlib .Path ,
0 commit comments