Skip to content

Commit 4365ec8

Browse files
committed
Fix fork remote handling and test authentication for staging group command
- staging_group: Handle missing 'fork' remote by adding it instead of trying to update a non-existent remote. Use try/except to gracefully fall back to 'git remote add' when 'set-url' fails. - behave tests: Set git identity env vars (GIT_AUTHOR_NAME/EMAIL, GIT_COMMITTER_NAME/EMAIL) when switching logins so commits are attributed to the correct user. - behave tests: Clear GIT_SSH_COMMAND when switching logins to allow git-obs to use its own SSH key management (core.sshCommand) without being overridden by keys from previous test users. - Add test scenario for fork creation in a specified organization, verifying that --fork-owner works with org-owned forks. Fixes authentication issues where git operations were incorrectly attributed to Admin when running as Alice due to persisting GIT_SSH_COMMAND environment variable. Fixes: #2057
1 parent 29cdde2 commit 4365ec8

3 files changed

Lines changed: 305 additions & 3 deletions

File tree

behave/features/git-staging-group.feature

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,80 @@ Feature: `git-obs staging group` command
44
Background:
55
Given I set working directory to "{context.osc.temp}"
66

7+
@destructive
8+
Scenario: Conflicts check for --fork-repo and --target
9+
When I execute git-obs with args "staging group --target pool/test-GitPkgA#1 --fork-repo myfork pool/test-GitPkgA#2 pool/test-GitPkgA#3"
10+
Then the exit code is 2
11+
And stderr contains "--fork-repo conflicts with --target"
12+
13+
@destructive
14+
Scenario: User is a collaborator in the project repository
15+
# setup: create package PRs and then two staging project PRs
16+
Given I use git-obs login "alice"
17+
# Package PR 1
18+
And I execute git-obs with args "repo fork pool/test-GitPkgA"
19+
And I execute git-obs with args "repo clone Alice/test-GitPkgA --no-ssh-strict-host-key-checking"
20+
And I set working directory to "{context.osc.temp}/test-GitPkgA"
21+
And I execute "git checkout -b pkg1"
22+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.1@' *.spec"
23+
And I execute "git commit -m 'v1.1' -a"
24+
And I execute "git push origin pkg1"
25+
And I execute git-obs with args "pr create --title 'Package update 1' --description='some text' --target-branch factory"
26+
# Package PR 2
27+
And I set working directory to "{context.osc.temp}"
28+
And I execute git-obs with args "repo fork pool/test-GitPkgB"
29+
And I execute git-obs with args "repo clone Alice/test-GitPkgB --no-ssh-strict-host-key-checking"
30+
And I set working directory to "{context.osc.temp}/test-GitPkgB"
31+
And I execute "git checkout factory"
32+
And I execute "git checkout -b pkg2"
33+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.2@' *.spec"
34+
And I execute "git commit -m 'v1.2' -a"
35+
And I execute "git push origin pkg2"
36+
And I execute git-obs with args "pr create --title 'Package update 2' --description='some text' --target-branch factory"
37+
Given I use git-obs login "admin"
38+
# Staging Project PR 1 (update submodule to Alice/test-GitPkgA pkg1)
39+
And I set working directory to "{context.osc.temp}"
40+
And I execute git-obs with args "repo clone openSUSE/Leap --no-ssh-strict-host-key-checking"
41+
And I set working directory to "{context.osc.temp}/Leap"
42+
And I execute "git checkout -b leap-pkgA"
43+
And I set env "GIT_SSH_COMMAND" to "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -i {context.fixtures}/ssh-keys/admin"
44+
And I execute "git submodule update --init --recursive"
45+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgA"
46+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgA.git"
47+
And I execute "git fetch alice pkg1"
48+
And I execute "git checkout FETCH_HEAD"
49+
And I set working directory to "{context.osc.temp}/Leap"
50+
And I execute "git add test-GitPkgA"
51+
And I execute "git commit -m 'Update test-GitPkgA submodule'"
52+
And I execute "git push origin leap-pkgA"
53+
And I execute git-obs with args "pr create --title 'Staging Group A' --description='PR: pool/test-GitPkgA!1' --target-branch factory --self"
54+
# Staging Project PR 2 (update submodule to Alice/test-GitPkgB pkg2)
55+
And I set working directory to "{context.osc.temp}/Leap"
56+
And I execute "git checkout factory"
57+
And I execute "git checkout -b leap-pkgB"
58+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgB"
59+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgB.git"
60+
And I execute "git fetch alice pkg2"
61+
And I execute "git checkout FETCH_HEAD"
62+
And I set working directory to "{context.osc.temp}/Leap"
63+
And I execute "git add test-GitPkgB"
64+
And I execute "git commit -m 'Update test-GitPkgB submodule'"
65+
And I execute "git push origin leap-pkgB"
66+
And I execute git-obs with args "pr create --title 'Staging Group B' --description='PR: pool/test-GitPkgB!1' --target-branch factory --self"
67+
# Add labels and create devel org
68+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/Backlog", "color": "ffffff"}}'"
69+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/In Progress", "color": "afafaf"}}'"
70+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/1/labels --data='{{"labels": ["staging/Backlog"]}}'"
71+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/2/labels --data='{{"labels": ["staging/Backlog"]}}'"
72+
And I execute git-obs with args "api -X PUT '/repos/openSUSE/leap/collaborators/Alice' --data='{{"permission": "write"}}'"
73+
Given I use git-obs login "alice"
74+
When I execute git-obs with args "staging group openSUSE/Leap#1 openSUSE/Leap#2"
75+
Then the exit code is 0
76+
And stdout contains "You have push access to the target repository openSUSE/Leap, the pull request will be created from a branch in the target repository."
77+
And I execute git-obs with args "api -X GET /repos/openSUSE/Leap/pulls/3 | jq .body"
78+
And stdout contains "PR: pool/test-gitpkga!1"
79+
And stdout contains "PR: pool/test-gitpkgb!1"
80+
781
@destructive
882
Scenario: Warning when --fork-owner is not specified with multiple PRs
983
# setup: create package PRs and then two staging project PRs
@@ -69,4 +143,210 @@ Scenario: Warning when --fork-owner is not specified with multiple PRs
69143
And stderr contains "WARNING: No fork organization specified. Defaulting to a private fork in 'Alice'."
70144
And I execute git-obs with args "api -X GET /repos/openSUSE/Leap/pulls/3 | jq .body"
71145
And stdout contains "PR: pool/test-gitpkga!1"
146+
And stdout contains "PR: pool/test-gitpkgb!1"
147+
148+
@destructive
149+
Scenario: Warning when --fork-owner is not specified with multiple PRs, but --fork-repo is specified
150+
# setup: create package PRs and then two staging project PRs
151+
Given I use git-obs login "alice"
152+
# Package PR 1
153+
And I execute git-obs with args "repo fork pool/test-GitPkgA"
154+
And I execute git-obs with args "repo clone Alice/test-GitPkgA --no-ssh-strict-host-key-checking"
155+
And I set working directory to "{context.osc.temp}/test-GitPkgA"
156+
And I execute "git checkout -b pkg1"
157+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.1@' *.spec"
158+
And I execute "git commit -m 'v1.1' -a"
159+
And I execute "git push origin pkg1"
160+
And I execute git-obs with args "pr create --title 'Package update 1' --description='some text' --target-branch factory"
161+
# Package PR 2
162+
And I set working directory to "{context.osc.temp}"
163+
And I execute git-obs with args "repo fork pool/test-GitPkgB"
164+
And I execute git-obs with args "repo clone Alice/test-GitPkgB --no-ssh-strict-host-key-checking"
165+
And I set working directory to "{context.osc.temp}/test-GitPkgB"
166+
And I execute "git checkout factory"
167+
And I execute "git checkout -b pkg2"
168+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.2@' *.spec"
169+
And I execute "git commit -m 'v1.2' -a"
170+
And I execute "git push origin pkg2"
171+
And I execute git-obs with args "pr create --title 'Package update 2' --description='some text' --target-branch factory"
172+
Given I use git-obs login "admin"
173+
# Staging Project PR 1 (update submodule to Alice/test-GitPkgA pkg1)
174+
And I set working directory to "{context.osc.temp}"
175+
And I execute git-obs with args "repo clone openSUSE/Leap --no-ssh-strict-host-key-checking"
176+
And I set working directory to "{context.osc.temp}/Leap"
177+
And I execute "git checkout -b leap-pkgA"
178+
And I set env "GIT_SSH_COMMAND" to "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -i {context.fixtures}/ssh-keys/admin"
179+
And I execute "git submodule update --init --recursive"
180+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgA"
181+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgA.git"
182+
And I execute "git fetch alice pkg1"
183+
And I execute "git checkout FETCH_HEAD"
184+
And I set working directory to "{context.osc.temp}/Leap"
185+
And I execute "git add test-GitPkgA"
186+
And I execute "git commit -m 'Update test-GitPkgA submodule'"
187+
And I execute "git push origin leap-pkgA"
188+
And I execute git-obs with args "pr create --title 'Staging Group A' --description='PR: pool/test-GitPkgA!1' --target-branch factory --self"
189+
# Staging Project PR 2 (update submodule to Alice/test-GitPkgB pkg2)
190+
And I set working directory to "{context.osc.temp}/Leap"
191+
And I execute "git checkout factory"
192+
And I execute "git checkout -b leap-pkgB"
193+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgB"
194+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgB.git"
195+
And I execute "git fetch alice pkg2"
196+
And I execute "git checkout FETCH_HEAD"
197+
And I set working directory to "{context.osc.temp}/Leap"
198+
And I execute "git add test-GitPkgB"
199+
And I execute "git commit -m 'Update test-GitPkgB submodule'"
200+
And I execute "git push origin leap-pkgB"
201+
And I execute git-obs with args "pr create --title 'Staging Group B' --description='PR: pool/test-GitPkgB!1' --target-branch factory --self"
202+
# Add labels
203+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/Backlog", "color": "ffffff"}}'"
204+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/In Progress", "color": "afafaf"}}'"
205+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/1/labels --data='{{"labels": ["staging/Backlog"]}}'"
206+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/2/labels --data='{{"labels": ["staging/Backlog"]}}'"
207+
Given I use git-obs login "alice"
208+
When I execute git-obs with args "staging group openSUSE/Leap#1 openSUSE/Leap#2 --fork-repo myLeap"
209+
Then the exit code is 0
210+
And stderr contains "WARNING: No fork organization specified. Defaulting to a private fork in 'Alice'."
211+
And I execute git-obs with args "api -X GET /repos/openSUSE/Leap/pulls/3 | jq .body"
212+
And stdout contains "PR: pool/test-gitpkga!1"
213+
And stdout contains "PR: pool/test-gitpkgb!1"
214+
215+
216+
@destructive
217+
Scenario: Create a fork in the specified organization
218+
# setup: create package PRs and then two staging project PRs
219+
Given I use git-obs login "alice"
220+
# Package PR 1
221+
And I execute git-obs with args "repo fork pool/test-GitPkgA"
222+
And I execute git-obs with args "repo clone Alice/test-GitPkgA --no-ssh-strict-host-key-checking"
223+
And I set working directory to "{context.osc.temp}/test-GitPkgA"
224+
And I execute "git checkout -b pkg1"
225+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.1@' *.spec"
226+
And I execute "git commit -m 'v1.1' -a"
227+
And I execute "git push origin pkg1"
228+
And I execute git-obs with args "pr create --title 'Package update 1' --description='some text' --target-branch factory"
229+
# Package PR 2
230+
And I set working directory to "{context.osc.temp}"
231+
And I execute git-obs with args "repo fork pool/test-GitPkgB"
232+
And I execute git-obs with args "repo clone Alice/test-GitPkgB --no-ssh-strict-host-key-checking"
233+
And I set working directory to "{context.osc.temp}/test-GitPkgB"
234+
And I execute "git checkout factory"
235+
And I execute "git checkout -b pkg2"
236+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.2@' *.spec"
237+
And I execute "git commit -m 'v1.2' -a"
238+
And I execute "git push origin pkg2"
239+
And I execute git-obs with args "pr create --title 'Package update 2' --description='some text' --target-branch factory"
240+
Given I use git-obs login "admin"
241+
# Staging Project PR 1 (update submodule to Alice/test-GitPkgA pkg1)
242+
And I set working directory to "{context.osc.temp}"
243+
And I execute git-obs with args "repo clone openSUSE/Leap --no-ssh-strict-host-key-checking"
244+
And I set working directory to "{context.osc.temp}/Leap"
245+
And I execute "git checkout -b leap-pkgA"
246+
And I set env "GIT_SSH_COMMAND" to "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -i {context.fixtures}/ssh-keys/admin"
247+
And I execute "git submodule update --init --recursive"
248+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgA"
249+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgA.git"
250+
And I execute "git fetch alice pkg1"
251+
And I execute "git checkout FETCH_HEAD"
252+
And I set working directory to "{context.osc.temp}/Leap"
253+
And I execute "git add test-GitPkgA"
254+
And I execute "git commit -m 'Update test-GitPkgA submodule'"
255+
And I execute "git push origin leap-pkgA"
256+
And I execute git-obs with args "pr create --title 'Staging Group A' --description='PR: pool/test-GitPkgA!1' --target-branch factory --self"
257+
# Staging Project PR 2 (update submodule to Alice/test-GitPkgB pkg2)
258+
And I set working directory to "{context.osc.temp}/Leap"
259+
And I execute "git checkout factory"
260+
And I execute "git checkout -b leap-pkgB"
261+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgB"
262+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgB.git"
263+
And I execute "git fetch alice pkg2"
264+
And I execute "git checkout FETCH_HEAD"
265+
And I set working directory to "{context.osc.temp}/Leap"
266+
And I execute "git add test-GitPkgB"
267+
And I execute "git commit -m 'Update test-GitPkgB submodule'"
268+
And I execute "git push origin leap-pkgB"
269+
And I execute git-obs with args "pr create --title 'Staging Group B' --description='PR: pool/test-GitPkgB!1' --target-branch factory --self"
270+
# Add labels and create devel org
271+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/Backlog", "color": "ffffff"}}'"
272+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/In Progress", "color": "afafaf"}}'"
273+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/1/labels --data='{{"labels": ["staging/Backlog"]}}'"
274+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/2/labels --data='{{"labels": ["staging/Backlog"]}}'"
275+
And I execute git-obs with args "api -X POST /orgs --data='{{"username": "devel"}}'"
276+
And I execute git-obs with args "api -X PUT '/teams/3/members/Alice'"
277+
Given I use git-obs login "alice"
278+
When I execute git-obs with args "staging group openSUSE/Leap#1 openSUSE/Leap#2 --fork-owner devel"
279+
Then the exit code is 0
280+
And stderr contains "Cannot find a matching fork of openSUSE/Leap for devel, creating one..."
281+
And I execute git-obs with args "api -X GET /repos/openSUSE/Leap/pulls/3 | jq .body"
282+
And stdout contains "PR: pool/test-gitpkga!1"
283+
And stdout contains "PR: pool/test-gitpkgb!1"
284+
285+
@destructive
286+
Scenario: Create a fork in a specified organization with a different repo name
287+
# setup: create package PRs and then two staging project PRs
288+
Given I use git-obs login "alice"
289+
# Package PR 1
290+
And I execute git-obs with args "repo fork pool/test-GitPkgA"
291+
And I execute git-obs with args "repo clone Alice/test-GitPkgA --no-ssh-strict-host-key-checking"
292+
And I set working directory to "{context.osc.temp}/test-GitPkgA"
293+
And I execute "git checkout -b pkg1"
294+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.1@' *.spec"
295+
And I execute "git commit -m 'v1.1' -a"
296+
And I execute "git push origin pkg1"
297+
And I execute git-obs with args "pr create --title 'Package update 1' --description='some text' --target-branch factory"
298+
# Package PR 2
299+
And I set working directory to "{context.osc.temp}"
300+
And I execute git-obs with args "repo fork pool/test-GitPkgB"
301+
And I execute git-obs with args "repo clone Alice/test-GitPkgB --no-ssh-strict-host-key-checking"
302+
And I set working directory to "{context.osc.temp}/test-GitPkgB"
303+
And I execute "git checkout factory"
304+
And I execute "git checkout -b pkg2"
305+
And I execute "sed -i 's@^\(Version: *\) .*@\1 v1.2@' *.spec"
306+
And I execute "git commit -m 'v1.2' -a"
307+
And I execute "git push origin pkg2"
308+
And I execute git-obs with args "pr create --title 'Package update 2' --description='some text' --target-branch factory"
309+
Given I use git-obs login "admin"
310+
# Staging Project PR 1 (update submodule to Alice/test-GitPkgA pkg1)
311+
And I set working directory to "{context.osc.temp}"
312+
And I execute git-obs with args "repo clone openSUSE/Leap --no-ssh-strict-host-key-checking"
313+
And I set working directory to "{context.osc.temp}/Leap"
314+
And I execute "git checkout -b leap-pkgA"
315+
And I set env "GIT_SSH_COMMAND" to "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -i {context.fixtures}/ssh-keys/admin"
316+
And I execute "git submodule update --init --recursive"
317+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgA"
318+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgA.git"
319+
And I execute "git fetch alice pkg1"
320+
And I execute "git checkout FETCH_HEAD"
321+
And I set working directory to "{context.osc.temp}/Leap"
322+
And I execute "git add test-GitPkgA"
323+
And I execute "git commit -m 'Update test-GitPkgA submodule'"
324+
And I execute "git push origin leap-pkgA"
325+
And I execute git-obs with args "pr create --title 'Staging Group A' --description='PR: pool/test-GitPkgA!1' --target-branch factory --self"
326+
# Staging Project PR 2 (update submodule to Alice/test-GitPkgB pkg2)
327+
And I set working directory to "{context.osc.temp}/Leap"
328+
And I execute "git checkout factory"
329+
And I execute "git checkout -b leap-pkgB"
330+
And I set working directory to "{context.osc.temp}/Leap/test-GitPkgB"
331+
And I execute "git remote add alice ssh://gitea@localhost:$GITEA_SERVER_SSH_PORT/Alice/test-GitPkgB.git"
332+
And I execute "git fetch alice pkg2"
333+
And I execute "git checkout FETCH_HEAD"
334+
And I set working directory to "{context.osc.temp}/Leap"
335+
And I execute "git add test-GitPkgB"
336+
And I execute "git commit -m 'Update test-GitPkgB submodule'"
337+
And I execute "git push origin leap-pkgB"
338+
And I execute git-obs with args "pr create --title 'Staging Group B' --description='PR: pool/test-GitPkgB!1' --target-branch factory --self"
339+
# Add labels and create devel org
340+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/Backlog", "color": "ffffff"}}'"
341+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/labels --data='{{"name": "staging/In Progress", "color": "afafaf"}}'"
342+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/1/labels --data='{{"labels": ["staging/Backlog"]}}'"
343+
And I execute git-obs with args "api -X POST /repos/openSUSE/Leap/issues/2/labels --data='{{"labels": ["staging/Backlog"]}}'"
344+
And I execute git-obs with args "api -X POST /orgs --data='{{"username": "devel"}}'"
345+
And I execute git-obs with args "api -X PUT '/teams/3/members/Alice'"
346+
Given I use git-obs login "alice"
347+
When I execute git-obs with args "staging group openSUSE/Leap#1 openSUSE/Leap#2 --fork-owner devel --fork-repo myLeap"
348+
Then the exit code is 0
349+
And stderr contains "Fork devel/myLeap doesn't exist, creating it..."
350+
And I execute git-obs with args "api -X GET /repos/openSUSE/Leap/pulls/3 | jq .body"
351+
And stdout contains "PR: pool/test-gitpkga!1"
72352
And stdout contains "PR: pool/test-gitpkgb!1"

0 commit comments

Comments
 (0)