Repository: ansible/ansible
Pull request: test: remove ansible-examples.git repo
##### SUMMARY

* To speed up git tests remove reference to ansible-examples.git

Fixes: #81327

##### ISSUE TYPE



- Test Pull Request

Problem statement:
`git` integration test uses excessive network bandwidth
### Summary

The `git` integration test clones the `ansible-examples` repo (which has grown to > 50MB) numerous times from its Github source, and none of the tests appear to be getting additional benefit from the repeated internet access. This test should be rewritten in one or two steps to:

1) clone the repo *once* from Github to a local tempdir, then all subsequent clone/fetch/checkout/etc tests should reference the local copy in the tempdir

2) be entirely rewritten to use a much more compact integrated repo (thus requiring minimal-to-no internet access at all for the test)


### Issue Type

Bug Report

### Component Name

git integration test

### Ansible Version

```console
$ ansible --version

2.16 devel
```


### Configuration

```console
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
```


### OS / Environment

NA

### Steps to Reproduce

NA

### Expected Results

Low bandwidth usage, fast tests

### Actual Results

```console
High bandwidth usage, resulting in slow/flaky tests
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct

Hints from issue discussion:
Files identified in the description:

* [`lib/ansible/modules/git.py`](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/git.py)
* [`test`](https://github.com/ansible/ansible/blob/devel/test)

If these files are incorrect, please update the `component name` section of the description or use the [component](https://github.com/mkrizek/ansibotmini/blob/main/README.md) bot command.

<!--- boilerplate: components_banner --->

Commit message: Make CI green

Signed-off-by: Ansible Test Runner <noreply@example.com>

Patch to review:
diff --git a/test/integration/targets/git/tasks/setup-local-repos.yml b/test/integration/targets/git/tasks/setup-local-repos.yml
index 4626f1028bf74a..3723f4dda4cbf7 100644
--- a/test/integration/targets/git/tasks/setup-local-repos.yml
+++ b/test/integration/targets/git/tasks/setup-local-repos.yml
@@ -56,6 +56,16 @@
   args:
     chdir: "{{ repo_dir }}/shallow_branches"
 
+- name: SETUP-LOCAL-REPOS | get ref head for test_branch
+  shell: git checkout test_branch && git rev-parse HEAD
+  args:
+    chdir: "{{ repo_dir }}/shallow_branches"
+  register: ref_head_id
+
+- name: SETUP-LOCAL-REPOS | store ref head for test_branch
+  set_fact:
+    test_branch_ref_head_id: "{{ ref_head_id.stdout }}"
+
 # Make this a bare one, we need to be able to push to it from clones
 # We make the repo here for consistency with the other repos,
 # but we finish setting it up in forcefully-fetch-tag.yml.
diff --git a/test/integration/targets/git/tasks/specific-revision.yml b/test/integration/targets/git/tasks/specific-revision.yml
index f1fe41d56268bf..95d2ccdccb99f1 100644
--- a/test/integration/targets/git/tasks/specific-revision.yml
+++ b/test/integration/targets/git/tasks/specific-revision.yml
@@ -70,11 +70,11 @@
 # Same as the previous test, but this time we specify which ref
 # contains the SHA1
 - name: SPECIFIC-REVISION | update to revision by specifying the refspec
-  git:
-    repo: https://github.com/ansible/ansible-examples.git
+  git: &git_ref_spec
+    repo: "{{ repo_dir }}/shallow_branches"
     dest: '{{ checkout_dir }}'
-    version: 5473e343e33255f2da0b160f53135c56921d875c
-    refspec: refs/pull/7/merge
+    version: "{{ test_branch_ref_head_id }}"
+    refspec: refs/heads/test_branch
 
 - name: SPECIFIC-REVISION | check HEAD after update with refspec
   command: git rev-parse HEAD
@@ -84,7 +84,7 @@
 
 - assert:
     that:
-      - 'git_result.stdout == "5473e343e33255f2da0b160f53135c56921d875c"'
+      - 'git_result.stdout == test_branch_ref_head_id'
 
 # try out combination of refspec and depth
 - name: SPECIFIC-REVISION | clear checkout_dir
@@ -94,11 +94,8 @@
 
 - name: SPECIFIC-REVISION | update to revision by specifying the refspec with depth=1
   git:
-    repo: https://github.com/ansible/ansible-examples.git
-    dest: '{{ checkout_dir }}'
-    version: 5473e343e33255f2da0b160f53135c56921d875c
-    refspec: refs/pull/7/merge
     depth: 1
+    <<: *git_ref_spec
 
 - name: SPECIFIC-REVISION | check HEAD after update with refspec
   command: git rev-parse HEAD
@@ -108,7 +105,7 @@
 
 - assert:
     that:
-      - 'git_result.stdout == "5473e343e33255f2da0b160f53135c56921d875c"'
+      - 'git_result.stdout == test_branch_ref_head_id'
 
 - name: SPECIFIC-REVISION | try to access other commit
   shell: git checkout 0ce1096
@@ -130,11 +127,7 @@
     path: "{{ checkout_dir }}"
 
 - name: SPECIFIC-REVISION | clone to revision by specifying the refspec
-  git:
-    repo: https://github.com/ansible/ansible-examples.git
-    dest: "{{ checkout_dir }}"
-    version: 5473e343e33255f2da0b160f53135c56921d875c
-    refspec: refs/pull/7/merge
+  git: *git_ref_spec
 
 - name: SPECIFIC-REVISION | check HEAD after update with refspec
   command: git rev-parse HEAD
@@ -144,7 +137,7 @@
 
 - assert:
     that:
-      - 'git_result.stdout == "5473e343e33255f2da0b160f53135c56921d875c"'
+      - 'git_result.stdout == test_branch_ref_head_id'
 
 # Test that a forced shallow checkout referincing branch only always fetches latest head
 


Code review comments:
diff_hunk: @@ -70,11 +70,11 @@
 # Same as the previous test, but this time we specify which ref
 # contains the SHA1
 - name: SPECIFIC-REVISION | update to revision by specifying the refspec
-  git:
-    repo: https://github.com/ansible/ansible-examples.git
+  git: &git_ref_spec
+    repo: "{{ repo_dir }}/shallow_branches"
path: test/integration/targets/git/tasks/specific-revision.yml
text: @user1:
observation: pretty sure this should be pointing to the bare repo to work and be equivalent. It's concerning that the test doesn't fail with your variant... The original test uses a bare repo so the new one should do the same, I think.
```suggestion
    repo: "{{ repo_dir }}/shallow_branches/.git"
```