Skip to content

Commit 2d12927

Browse files
authored
Merge pull request #690 from redhatci/gitea_mirror_all_branches
setup_gitea | Mirror all branches from reference repository
2 parents 29f2119 + 6adabdf commit 2d12927

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

roles/setup_gitea/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Role tasks:
2626
| sg_repository | *undefined* | No | Initial repository name. Mandatory if an external repository to mirror (sg_repo_mirror_url) is set.
2727
| sg_repo_branch | main | No | Main branch in the initial repository
2828
| sg_repo_mirror_url | *undefined* | No | Git URL to mirror into the initial repository
29-
| sg_repo_mirror_branch | main | No | Branch to mirror from the repository
3029
| sg_repo_sshkey | *undefined* | No | The sshkey to clone the initial repository when the repo requires ssh authentication.
3130

3231
## Role requirements

roles/setup_gitea/defaults/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ sg_namespace: gitea
33
sg_action: install
44
sg_gitea_image: mirror.gcr.io/gitea/gitea:latest-rootless
55
sg_repo_branch: main
6-
sg_repo_mirror_branch: main
76
sg_url: http://localhost:3000
87
...

roles/setup_gitea/tasks/cleanup.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,4 @@
1616
delay: 5
1717
until: _sg_gitea_namespace.resources | length == 0
1818

19-
- name: Clear mirror temp dir
20-
ansible.builtin.file:
21-
path: "{{ _sg_mirror_repo.path }}"
22-
state: absent
2319
...

roles/setup_gitea/tasks/install.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,23 @@
155155
ansible.builtin.git:
156156
dest: "{{ _sg_mirror_repo.path }}/mirror"
157157
repo: "{{ sg_repo_mirror_url }}"
158-
version: "{{ sg_repo_mirror_branch }}"
158+
version: "{{ sg_repo_branch }}"
159159
key_file: "{{ keyfile | length | ternary(keyfile, omit) }}"
160160

161-
- name: Mirror the repository # noqa command-instead-of-module
161+
- name: Mirror all branches to the repository # noqa command-instead-of-module
162162
ansible.builtin.shell:
163163
cmd: |
164-
/usr/bin/git push http://{{ sg_username }}:{{ sg_password }}@{{ sg_gitea_domain }}/{{ sg_username }}/{{ sg_repository }}.git {{ sg_repo_mirror_branch }}:{{ sg_repo_branch }}
164+
/usr/bin/git remote add mirror http://{{ sg_username }}:{{ sg_password }}@{{ sg_gitea_domain }}/{{ sg_username }}/{{ sg_repository }}.git
165+
/usr/bin/git push mirror 'refs/remotes/origin/*:refs/heads/*'
165166
chdir: "{{ _sg_mirror_repo.path }}/mirror"
166-
changed_when: false
167+
register: _sg_git_push_result
168+
failed_when: _sg_git_push_result.rc != 0
169+
changed_when: "'Everything up-to-date' not in _sg_git_push_result.stderr"
167170
no_log: true
171+
172+
- name: Clear mirror temp dir
173+
ansible.builtin.file:
174+
path: "{{ _sg_mirror_repo.path }}"
175+
state: absent
176+
168177
...

0 commit comments

Comments
 (0)