Skip to content

Commit 34dfb13

Browse files
authored
Merge pull request #2341 from gitpython-developers/fix-ci
test: isolate repository fixtures and restore Windows reference coverage
2 parents f6db6e7 + 7e8aa8c commit 34dfb13

44 files changed

Lines changed: 532 additions & 532 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/alpine-test.yml‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,13 @@ jobs:
3434

3535
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3636
with:
37-
fetch-depth: 0
3837
persist-credentials: false
3938

4039
- name: Set workspace ownership
4140
run: |
4241
chown -R runner:docker -- "$GITHUB_WORKSPACE"
4342
shell: sh -exo pipefail {0} # Run this as root, not the "runner" user.
4443

45-
- name: Prepare this repo for tests
46-
run: |
47-
./init-tests-after-clone.sh
48-
4944
- name: Set git user identity and command aliases for the tests
5045
run: |
5146
git config --global user.email "travis@ci.com"
@@ -95,6 +90,9 @@ jobs:
9590
python --version
9691
python -c 'import os, sys; print(f"{sys.platform=}, {os.name=}")'
9792
93+
- name: Remove source Git metadata to verify fixture isolation
94+
run: .venv/bin/python -c "from pathlib import Path; from git.util import rmtree; rmtree('.git'); assert not Path('.git').exists()"
95+
9896
- name: Test with pytest
9997
run: |
10098
. .venv/bin/activate

‎.github/workflows/backend-benchmark.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1818
with:
19-
fetch-depth: 0
2019
persist-credentials: false
2120
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
2221
with:
@@ -50,7 +49,8 @@ jobs:
5049
.bench-gix/bin/python -m pip install '.[gix]' -r test/performance/benchmark-requirements.txt
5150
- name: Prepare the shared read-only benchmark fixture
5251
run: |
53-
.bench-cli/bin/python -c 'from pathlib import Path; from gix import testtools; print("BENCH_REPO=" + str((testtools.scripted_fixture_read_only_with_args("benchmark.sh", [str(Path.cwd())]) / "repo").resolve()))' >> "$GITHUB_ENV"
52+
rm -rf .git
53+
.bench-cli/bin/python -c 'from gix import testtools; print("BENCH_REPO=" + str((testtools.scripted_fixture_read_only_with_args("benchmark.sh", []) / "repo").resolve()))' >> "$GITHUB_ENV"
5454
mkdir benchmark-results
5555
- name: Measure GixPython operations, opening and discovery first
5656
env:

‎.github/workflows/cygwin-test.yml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030

3131
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3232
with:
33-
fetch-depth: 0
3433
persist-credentials: false
3534

3635
- name: Install Cygwin
@@ -61,10 +60,6 @@ jobs:
6160
git config --global --add safe.directory "$(pwd)/.git"
6261
git config --global core.autocrlf false
6362
64-
- name: Prepare this repo for tests
65-
run: |
66-
./init-tests-after-clone.sh
67-
6863
- name: Set git user identity and command aliases for the tests
6964
run: |
7065
git config --global user.email "travis@ci.com"

‎.github/workflows/dependencies.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
steps:
3131
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3232
with:
33-
fetch-depth: 0
3433
persist-credentials: false
3534
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
3635
with:
@@ -45,8 +44,9 @@ jobs:
4544
run: flake8 "$PROJECT/$PROJECT" --count --select=E9,F63,F7,F82 --show-source --statistics
4645
- name: Test
4746
run: |
47+
rm -rf .git
4848
if test "$PROJECT" = gitdb; then
49-
GITDB_TEST_GIT_REPO_BASE="$(git rev-parse --git-common-dir)" pytest -o addopts= -v gitdb/gitdb/test
49+
pytest -o addopts= -v gitdb/gitdb/test
5050
else
5151
pytest -o addopts= -v smmap/smmap/test
5252
fi

‎.github/workflows/pythonpackage.yml‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ jobs:
6161
steps:
6262
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6363
with:
64-
fetch-depth: 0
6564
persist-credentials: false
6665

6766
- name: Set up Python ${{ matrix.python-version }}
@@ -115,10 +114,6 @@ jobs:
115114
brew install git
116115
echo "$(brew --prefix git)/bin" >> "$GITHUB_PATH"
117116
118-
- name: Prepare this repo for tests
119-
run: |
120-
./init-tests-after-clone.sh
121-
122117
- name: Set git user identity and command aliases for the tests
123118
run: |
124119
git config --global user.email "travis@ci.com"
@@ -219,6 +214,9 @@ jobs:
219214
run: |
220215
basedpyright --warnings
221216
217+
- name: Remove source Git metadata to verify fixture isolation
218+
run: python -c "from pathlib import Path; from git.util import rmtree; rmtree('.git'); assert not Path('.git').exists()"
219+
222220
- name: Test with pytest
223221
run: |
224222
if [[ "$RUNNER_OS" == "Windows" && -z "${GIT_PYTHON_GIT_EXECUTABLE+x}" ]]; then

‎CONTRIBUTING.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
The following is a short step-by-step rundown of what one typically would do to contribute.
44

55
- [Fork this project](https://github.com/gitpython-developers/GitPython/fork) on GitHub.
6-
- For setting up the environment to run the self tests, please run `init-tests-after-clone.sh`.
6+
- Install the `test` extra and select a backend before running `pytest`. Test
7+
repositories are generated automatically; no source Git history is required.
78
- Please try to **write a test that fails unless the contribution is present.**
89
- Try to avoid massive commits and prefer to take small steps, with one commit for each.
910
- Feel free to add yourself to AUTHORS file.
@@ -64,8 +65,10 @@ Put initial repository and filesystem states in `tests/fixtures/*.sh` and use
6465
`test.lib.fixtures` to run them through `gix.testtools`. Read-only tests share
6566
cached output; mutating tests use writable copies. Use `execute=True` only when
6667
the fixture cannot be copied, and explain the reason at its call site. Keep
67-
operations under test in Python. Immutable parser byte samples remain in
68-
`test/fixtures`; generated caches and archives are ignored.
68+
operations under test in Python. Generate histories from scratch and refer to
69+
named fixture revisions; do not clone the source checkout, fetch project history,
70+
or depend on its refs, object IDs, index, or working-tree state. Immutable parser
71+
byte samples remain in `test/fixtures`; generated caches and archives are ignored.
6972

7073
Use `test.cleanup.cleanup_directory` for cleanup outside the shared fixture
7174
owners. Close repository handles before removing their files. Cleanup is

‎README.md‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,8 @@ To clone the [the GitHub repository](https://github.com/gitpython-developers/Git
118118
```sh
119119
git clone https://github.com/gitpython-developers/GitPython
120120
cd GitPython
121-
./init-tests-after-clone.sh
122121
```
123122

124-
On Windows, `./init-tests-after-clone.sh` can be run in a Git Bash shell.
125-
126123
If you are cloning [your own fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks), then replace the above `git clone` command with one that gives the URL of your fork. Or use this [`gh`](https://cli.github.com/) command (assuming you have `gh` and your fork is called `GitPython`):
127124

128125
```sh
@@ -175,9 +172,8 @@ See [Issue #525](https://github.com/gitpython-developers/GitPython/issues/525).
175172

176173
### RUNNING TESTS
177174

178-
_Important_: Right after cloning this repository, please be sure to have executed
179-
the `./init-tests-after-clone.sh` script in the repository root. Otherwise
180-
you will encounter test failures.
175+
Test repositories are generated from scratch by fixture scripts. Tests work from
176+
a shallow clone or a source copy without `.git`; no checkout preparation is needed.
181177

182178
#### Install test dependencies
183179

‎doc/gix-backend.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ installation/import smoke coverage, including the Cygwin Python 3.9 job.
214214
Running tests also requires Bash and Git 2.52+; `gix` here is GixPython's module.
215215

216216
Initial repository and filesystem states live in `tests/fixtures/*.sh`.
217+
Histories are generated from scratch, including the shared sample repository and
218+
its nested dependency repositories. Tests use named revisions such as `root`,
219+
`release`, and `merge`, and require no source checkout history or Git metadata.
220+
CI removes the source `.git` directory before running the full suite.
217221
`test/lib/fixtures.py` calls `gix.testtools` with an explicit lifetime:
218222

219223
- `read_only_fixture()` and the default `fixture_repo()` reuse cached output.

‎gitdb/README.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ The source is available in the GitPython repository on GitHub:
4242

4343
https://github.com/gitpython-developers/GitPython/tree/main/gitdb
4444

45+
Tests require Git and Bash. Each test class gets a temporary repository generated
46+
from scratch with packed and loose objects; no source checkout history is needed.
47+
4548
Run the tests with::
4649

4750
pytest
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
git init -q --object-format=sha1 -b main repo
4+
cd repo
5+
for n in $(seq 1 30); do
6+
printf 'revision %s\n' "$n" >> file
7+
git add file
8+
git commit -qm "Revision $n"
9+
done
10+
git gc --prune=now
11+
# Keep both packed and loose objects for the compound database and tutorial tests.
12+
printf 'loose object\n' > loose
13+
git add loose
14+
git commit -qm 'Add loose objects'

0 commit comments

Comments
 (0)