wexample-helpers-git 7.1.6__tar.gz → 7.1.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. wexample_helpers_git-7.1.8/PKG-INFO +113 -0
  2. wexample_helpers_git-7.1.8/README.md +93 -0
  3. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/pyproject.toml +2 -2
  4. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/src/wexample_helpers_git/helper/gitignore.py +0 -0
  5. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/tests/.gitkeep +0 -0
  6. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/tests/helper/test_repo.py +0 -0
  7. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/tests/unit/helper/test_git.py +0 -0
  8. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/tests/unit/helper/test_git_retryable_callback_manager.py +0 -0
  9. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/tests/unit/helper/test_gitignore.py +0 -0
  10. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/tests/unit/helper/test_repo.py +0 -0
  11. wexample_helpers_git-7.1.6/PKG-INFO +0 -242
  12. wexample_helpers_git-7.1.6/README.md +0 -222
  13. wexample_helpers_git-7.1.6/tests/unit/__init__.py +0 -0
  14. wexample_helpers_git-7.1.6/tests/unit/helper/__init__.py +0 -0
  15. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/src/wexample_helpers_git/__init__.py +0 -0
  16. {wexample_helpers_git-7.1.6/src/wexample_helpers_git/__pycache__ → wexample_helpers_git-7.1.8/src/wexample_helpers_git/const}/__init__.py +0 -0
  17. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/src/wexample_helpers_git/const/common.py +0 -0
  18. {wexample_helpers_git-7.1.6/src/wexample_helpers_git/const → wexample_helpers_git-7.1.8/src/wexample_helpers_git/helper}/__init__.py +0 -0
  19. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/src/wexample_helpers_git/helper/git.py +0 -0
  20. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/src/wexample_helpers_git/helper/git_retryable_callback_manager.py +0 -0
  21. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/src/wexample_helpers_git/helper/repo.py +0 -0
  22. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/src/wexample_helpers_git/py.typed +0 -0
  23. {wexample_helpers_git-7.1.6/src/wexample_helpers_git → wexample_helpers_git-7.1.8/tests}/helper/__init__.py +0 -0
  24. {wexample_helpers_git-7.1.6 → wexample_helpers_git-7.1.8}/tests/helper/test_helper_git.py +0 -0
  25. {wexample_helpers_git-7.1.6/src/wexample_helpers_git/helper/__pycache__ → wexample_helpers_git-7.1.8/tests/unit}/__init__.py +0 -0
  26. {wexample_helpers_git-7.1.6/tests → wexample_helpers_git-7.1.8/tests/unit}/helper/__init__.py +0 -0
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.1
2
+ Name: wexample-helpers-git
3
+ Version: 7.1.8
4
+ Summary: Python helpers for common Git automation: branch switching, staged commits, push/pull with retries, tag management, and change detection
5
+ Author-Email: weeger <contact@wexample.com>
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Project-URL: homepage, https://github.com/wexample/python-helpers-git
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: attrs>=23.1.0
13
+ Requires-Dist: cattrs>=23.1.0
14
+ Requires-Dist: gitpython
15
+ Requires-Dist: wexample-helpers>=20.6.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest; extra == "dev"
18
+ Requires-Dist: pytest-cov; extra == "dev"
19
+ Description-Content-Type: text/markdown
20
+
21
+ # helpers_git
22
+
23
+ Version: 7.1.8
24
+
25
+ Python helpers for common Git automation: branch switching, staged commits, push/pull with retries, tag management, and change detection
26
+
27
+ ## Table of Contents
28
+
29
+ - [Install](#install)
30
+ - [Tests](#tests)
31
+ - [Roadmap](#roadmap)
32
+ - [Status Compatibility](#status-compatibility)
33
+ - [Useful Links](#useful-links)
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ pip install wexample-helpers-git
39
+ ```
40
+
41
+ Requires Python >=3.10.
42
+
43
+ ## Tests
44
+
45
+ This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
46
+
47
+ ### Installation
48
+
49
+ First, install the required testing dependencies:
50
+ ```bash
51
+ .venv/bin/python -m pip install pytest pytest-cov
52
+ ```
53
+
54
+ ### Basic Usage
55
+
56
+ Run all tests with coverage:
57
+ ```bash
58
+ .venv/bin/python -m pytest --cov --cov-report=html
59
+ ```
60
+
61
+ ### Common Commands
62
+ ```bash
63
+ # Run tests with coverage for a specific module
64
+ .venv/bin/python -m pytest --cov=your_module
65
+
66
+ # Show which lines are not covered
67
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
68
+
69
+ # Generate an HTML coverage report
70
+ .venv/bin/python -m pytest --cov=your_module --cov-report=html
71
+
72
+ # Combine terminal and HTML reports
73
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
74
+
75
+ # Run specific test file with coverage
76
+ .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
77
+ ```
78
+
79
+ ### Viewing HTML Reports
80
+
81
+ After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
82
+
83
+ ### Coverage Threshold
84
+
85
+ To enforce a minimum coverage percentage:
86
+ ```bash
87
+ .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
88
+ ```
89
+
90
+ This will cause the test suite to fail if coverage drops below 80%.
91
+
92
+ ## Known Limitations & Roadmap
93
+
94
+ Current limitations and planned features are tracked in the GitHub issues.
95
+
96
+ See the [project roadmap](https://github.com/wexample/python-helpers_git/issues) for upcoming features and improvements.
97
+
98
+ ## Status & Compatibility
99
+
100
+ **Maturity**: Production-ready
101
+
102
+ **Python Support**: >=3.10
103
+
104
+ **OS Support**: Linux, macOS, Windows
105
+
106
+ **Status**: Actively maintained
107
+
108
+ ## Useful Links
109
+
110
+ - **Homepage**: https://github.com/wexample/python-helpers-git
111
+ - **Issue Tracker**: https://github.com/wexample/python-helpers-git/issues
112
+ - **Discussions**: https://github.com/wexample/python-helpers-git/discussions
113
+ - **PyPI**: [pypi.org/project/wexample-helpers-git](https://pypi.org/project/wexample-helpers-git/)
@@ -0,0 +1,93 @@
1
+ # helpers_git
2
+
3
+ Version: 7.1.8
4
+
5
+ Python helpers for common Git automation: branch switching, staged commits, push/pull with retries, tag management, and change detection
6
+
7
+ ## Table of Contents
8
+
9
+ - [Install](#install)
10
+ - [Tests](#tests)
11
+ - [Roadmap](#roadmap)
12
+ - [Status Compatibility](#status-compatibility)
13
+ - [Useful Links](#useful-links)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install wexample-helpers-git
19
+ ```
20
+
21
+ Requires Python >=3.10.
22
+
23
+ ## Tests
24
+
25
+ This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
26
+
27
+ ### Installation
28
+
29
+ First, install the required testing dependencies:
30
+ ```bash
31
+ .venv/bin/python -m pip install pytest pytest-cov
32
+ ```
33
+
34
+ ### Basic Usage
35
+
36
+ Run all tests with coverage:
37
+ ```bash
38
+ .venv/bin/python -m pytest --cov --cov-report=html
39
+ ```
40
+
41
+ ### Common Commands
42
+ ```bash
43
+ # Run tests with coverage for a specific module
44
+ .venv/bin/python -m pytest --cov=your_module
45
+
46
+ # Show which lines are not covered
47
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
48
+
49
+ # Generate an HTML coverage report
50
+ .venv/bin/python -m pytest --cov=your_module --cov-report=html
51
+
52
+ # Combine terminal and HTML reports
53
+ .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
54
+
55
+ # Run specific test file with coverage
56
+ .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
57
+ ```
58
+
59
+ ### Viewing HTML Reports
60
+
61
+ After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
62
+
63
+ ### Coverage Threshold
64
+
65
+ To enforce a minimum coverage percentage:
66
+ ```bash
67
+ .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
68
+ ```
69
+
70
+ This will cause the test suite to fail if coverage drops below 80%.
71
+
72
+ ## Known Limitations & Roadmap
73
+
74
+ Current limitations and planned features are tracked in the GitHub issues.
75
+
76
+ See the [project roadmap](https://github.com/wexample/python-helpers_git/issues) for upcoming features and improvements.
77
+
78
+ ## Status & Compatibility
79
+
80
+ **Maturity**: Production-ready
81
+
82
+ **Python Support**: >=3.10
83
+
84
+ **OS Support**: Linux, macOS, Windows
85
+
86
+ **Status**: Actively maintained
87
+
88
+ ## Useful Links
89
+
90
+ - **Homepage**: https://github.com/wexample/python-helpers-git
91
+ - **Issue Tracker**: https://github.com/wexample/python-helpers-git/issues
92
+ - **Discussions**: https://github.com/wexample/python-helpers-git/discussions
93
+ - **PyPI**: [pypi.org/project/wexample-helpers-git](https://pypi.org/project/wexample-helpers-git/)
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "wexample-helpers-git"
9
- version = "7.1.6"
9
+ version = "7.1.8"
10
10
  description = "Python helpers for common Git automation: branch switching, staged commits, push/pull with retries, tag management, and change detection"
11
11
  authors = [
12
12
  { name = "weeger", email = "contact@wexample.com" },
@@ -21,7 +21,7 @@ dependencies = [
21
21
  "attrs>=23.1.0",
22
22
  "cattrs>=23.1.0",
23
23
  "gitpython",
24
- "wexample-helpers>=20.5.0",
24
+ "wexample-helpers>=20.6.0",
25
25
  ]
26
26
 
27
27
  [project.readme]
@@ -1,242 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: wexample-helpers-git
3
- Version: 7.1.6
4
- Summary: Python helpers for common Git automation: branch switching, staged commits, push/pull with retries, tag management, and change detection
5
- Author-Email: weeger <contact@wexample.com>
6
- License: MIT
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Project-URL: homepage, https://github.com/wexample/python-helpers-git
11
- Requires-Python: >=3.10
12
- Requires-Dist: attrs>=23.1.0
13
- Requires-Dist: cattrs>=23.1.0
14
- Requires-Dist: gitpython
15
- Requires-Dist: wexample-helpers>=20.5.0
16
- Provides-Extra: dev
17
- Requires-Dist: pytest; extra == "dev"
18
- Requires-Dist: pytest-cov; extra == "dev"
19
- Description-Content-Type: text/markdown
20
-
21
- # helpers_git
22
-
23
- Version: 7.1.6
24
-
25
- `wexample-helpers-git` is a Python library of focused helpers for scripting common Git operations: branch switching, staged commits, push and pull with automatic retries, tag management, change detection, and `.gitignore` canonicalization. It is aimed at Python tooling and automation code in the wexample ecosystem that needs reliable, programmatic control over local repositories and remote interactions without encoding raw subprocess calls inline. Network-facing operations such as `git_push_follow_tags`, `git_pull_rebase_autostash`, and `git_push_tag` include built-in retry logic via `GitRetryableCallbackManager`, which recognises transient server errors like HTTP 5xx and RPC failures automatically.
26
-
27
- ## Table of Contents
28
-
29
- - [Installation](#installation)
30
- - [Quickstart](#quickstart)
31
- - [Tests](#tests)
32
- - [Architecture](#architecture)
33
- - [Integration in the Suite](#integration-in-the-suite)
34
- - [Dependencies](#dependencies)
35
- - [Versioning & Compatibility Policy](#versioning--compatibility-policy)
36
- - [License](#license)
37
- - [About us](#about-us)
38
- - [Known Limitations & Roadmap](#known-limitations--roadmap)
39
- - [Status & Compatibility](#status--compatibility)
40
- - [Useful Links](#useful-links)
41
- - [Migration Notes](#migration-notes)
42
-
43
- ## Installation
44
-
45
- ```bash
46
- pip install wexample-helpers-git
47
- ```
48
-
49
- Requires Python >=3.10.
50
-
51
- ## Quickstart
52
-
53
- Install the package:
54
-
55
- ```bash
56
- pip install wexample-helpers-git
57
- ```
58
-
59
- The functions live in `wexample_helpers_git.helper.git`. Each one takes a `cwd` keyword argument pointing at the repository you want to operate on.
60
-
61
- ```python
62
- from wexample_helpers_git.helper.git import (
63
- git_current_branch,
64
- git_has_uncommitted_changes,
65
- git_get_current_commit_hash,
66
- )
67
-
68
- # Current branch name
69
- branch = git_current_branch(cwd="/path/to/repo")
70
- # → "main"
71
-
72
- # Whether there are any staged or unstaged changes
73
- dirty = git_has_uncommitted_changes(cwd="/path/to/repo")
74
- # → True
75
-
76
- # Full commit hash (pass short=True for the abbreviated form)
77
- sha = git_get_current_commit_hash(cwd="/path/to/repo")
78
- # → "a3f1c8d2e4b..."
79
- ```
80
-
81
- All three calls run `git` in a subprocess and return a Python value directly — no `Repo` object to construct, no intermediate result to parse.
82
-
83
- ## Tests
84
-
85
- This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
86
-
87
- ### Installation
88
-
89
- First, install the required testing dependencies:
90
- ```bash
91
- .venv/bin/python -m pip install pytest pytest-cov
92
- ```
93
-
94
- ### Basic Usage
95
-
96
- Run all tests with coverage:
97
- ```bash
98
- .venv/bin/python -m pytest --cov --cov-report=html
99
- ```
100
-
101
- ### Common Commands
102
- ```bash
103
- # Run tests with coverage for a specific module
104
- .venv/bin/python -m pytest --cov=your_module
105
-
106
- # Show which lines are not covered
107
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
108
-
109
- # Generate an HTML coverage report
110
- .venv/bin/python -m pytest --cov=your_module --cov-report=html
111
-
112
- # Combine terminal and HTML reports
113
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
114
-
115
- # Run specific test file with coverage
116
- .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
117
- ```
118
-
119
- ### Viewing HTML Reports
120
-
121
- After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
122
-
123
- ### Coverage Threshold
124
-
125
- To enforce a minimum coverage percentage:
126
- ```bash
127
- .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
128
- ```
129
-
130
- This will cause the test suite to fail if coverage drops below 80%.
131
-
132
- ## Architecture
133
-
134
- The package lives entirely under `src/wexample_helpers_git/` and has no runtime state. It is two sub-packages — `helper/` and `const/` — plus empty `__init__.py` stubs at each level.
135
-
136
- ### `helper/` — the functional layer
137
-
138
- Four modules, each with a distinct responsibility.
139
-
140
- **src/wexample_helpers_git/helper/git.py** is the main public API. It contains roughly thirty standalone functions covering branching (`git_create_or_switch_branch`, `git_switch_new_branch`, `git_checkout_new_branch`, `git_switch_branch`), staging and committing (`git_commit_all_with_message`), push and pull (`git_push_follow_tags`, `git_push_tag`, `git_pull_rebase_autostash`), tag operations (`git_tag_annotated`, `git_tag_lightweight`, `git_tag_exists`, `git_tag_points_to_head`), change detection (`git_has_uncommitted_changes`, `git_has_index_changes`, `git_has_working_changes`, `git_get_changed_paths`), and remote/upstream management (`git_ensure_upstream`, `git_set_upstream`, `git_get_upstream`, `git_get_remote_url`). Every function takes `cwd: FileStringOrPath` and resolves it via `file_resolve_path` from `wexample-helpers` before doing anything. All subprocess calls go through `git_run`, which is just:
141
-
142
- ```python
143
- def git_run(cmd: list[str], *args, **kwargs) -> ShellResult:
144
- return shell_run(cmd=["git", *cmd], *args, **kwargs)
145
- ```
146
-
147
- Network-facing calls pass `retries=3` to `git_run`, which forwards it to `shell_run` from `wexample-helpers`. `gitpython`'s `Repo` object is used only in `git_is_init` (to detect whether a path is a repository) and `git_remote_create_once` (to create a remote via the GitPython API when one does not already exist).
148
-
149
- **src/wexample_helpers_git/helper/repo.py** handles repository state fingerprinting. `repo_get_state` combines the HEAD hash with a hash of `git diff --name-only` output into a single string. `repo_has_changed` compares that string against a state file (`.last_git_state` by default) and updates it on change. `repo_has_changed_since` compares against a caller-held string instead of a file — useful when the caller wants to track state in memory.
150
-
151
- **src/wexample_helpers_git/helper/gitignore.py** is pure Python with no subprocess calls. `reorganize_gitignore_safe` takes the raw text of a `.gitignore`, checks every non-comment line for glob characters (`*`, `?`, `[`) or negations (`!`), and returns `None` if any are found — leaving the file untouched. When the file is safe, it splits it into blank-line-separated sections, deduplicates entries within each section, and sorts them case-insensitively, keeping leading comment blocks pinned to the top of each section and inline comments attached to their entry.
152
-
153
- **src/wexample_helpers_git/helper/git_retryable_callback_manager.py** defines `GitRetryableCallbackManager`, a subclass of `RetryableCallbackManager` from `wexample-helpers`. On construction it populates `transient_markers` with a list of lowercase strings (`"rpc failed"`, `"http 503"`, `"connection reset"`, etc.) and registers `_should_retry_git` as the `should_retry_callback`. That callback returns `True` when any marker appears in the lowercased error message. The class is designed to be instantiated directly for call-sites that need richer retry control beyond the `retries=` integer that `git_run` already accepts.
154
-
155
- ### `const/` — shared constants
156
-
157
- **src/wexample_helpers_git/const/common.py** declares five string constants: `GIT_BRANCH_MAIN`, `GIT_PROVIDER_GITHUB`, `GIT_PROVIDER_GITLAB`, `GIT_REMOTE_GITHUB`, and `GIT_REMOTE_ORIGIN`. Importing them avoids scattering the strings `"main"`, `"origin"`, and `"github"` across call-sites.
158
-
159
- ### Call path
160
-
161
- A typical call such as `git_commit_all_with_message("msg", cwd="/repo")` walks this path:
162
-
163
- 1. `file_resolve_path(cwd)` turns the argument into a `Path`.
164
- 2. `git_run(["add", "-A"], cwd=resolved)` prepends `"git"` and calls `shell_run`.
165
- 3. `shell_run` executes the subprocess and returns a `ShellResult` with `.stdout`, `.stderr`, and `.returncode`.
166
- 4. A second `git_run(["commit", "-m", message], ...)` follows the same path.
167
-
168
- For push and pull, step 2 also carries `retries=3`; `shell_run` re-runs the command on failure up to that limit.
169
-
170
- ### External dependencies
171
-
172
- `wexample-helpers` supplies `shell_run`, `ShellResult`, `file_resolve_path`, `RetryableCallbackManager`, and the `@base_class` decorator used by `GitRetryableCallbackManager`. `gitpython` is used only for the two functions that need a `Repo` object directly. `attrs` and `cattrs` are pulled in transitively through `@base_class`.
173
-
174
- ## Integration in the Suite
175
-
176
- This package is part of the Wexample Suite — a collection of high-quality, modular tools designed to work seamlessly together across multiple languages and environments.
177
-
178
- ### Related Packages
179
-
180
- The suite includes packages for configuration management, file handling, prompts, and more. Each package can be used independently or as part of the integrated suite.
181
-
182
- ## Dependencies
183
-
184
- - attrs: >=23.1.0
185
- - cattrs: >=23.1.0
186
- - gitpython:
187
- - wexample-helpers: >=20.5.0
188
-
189
- ## Versioning & Compatibility Policy
190
-
191
- Wexample packages follow **Semantic Versioning** (SemVer):
192
-
193
- - **MAJOR**: Breaking changes
194
- - **MINOR**: New features, backward compatible
195
- - **PATCH**: Bug fixes, backward compatible
196
-
197
- We maintain backward compatibility within major versions and provide clear migration guides for breaking changes.
198
-
199
- ## License
200
-
201
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
202
-
203
- Free to use in both personal and commercial projects.
204
-
205
- ## About us
206
-
207
- [Wexample](https://wexample.com) stands as a cornerstone of the digital ecosystem — a collective of seasoned engineers, researchers, and creators driven by a relentless pursuit of technological excellence. More than a media platform, it has grown into a vibrant community where innovation meets craftsmanship, and where every line of code reflects a commitment to clarity, durability, and shared intelligence.
208
-
209
- This packages suite embodies this spirit. Trusted by professionals and enthusiasts alike, it delivers a consistent, high-quality foundation for modern development — open, elegant, and battle-tested. Its reputation is built on years of collaboration, refinement, and rigorous attention to detail, making it a natural choice for those who demand both robustness and beauty in their tools.
210
-
211
- Wexample cultivates a culture of mastery. Each package, each contribution carries the mark of a community that values precision, ethics, and innovation — a community proud to shape the future of digital craftsmanship.
212
-
213
- Built and maintained by [Romain Weeger](https://weeger.io).
214
-
215
- ## Known Limitations & Roadmap
216
-
217
- Current limitations and planned features are tracked in the GitHub issues.
218
-
219
- See the [project roadmap](https://github.com/wexample/python-helpers_git/issues) for upcoming features and improvements.
220
-
221
- ## Status & Compatibility
222
-
223
- **Maturity**: Production-ready
224
-
225
- **Python Support**: >=3.10
226
-
227
- **OS Support**: Linux, macOS, Windows
228
-
229
- **Status**: Actively maintained
230
-
231
- ## Useful Links
232
-
233
- - **Homepage**: https://github.com/wexample/python-helpers-git
234
- - **Issue Tracker**: https://github.com/wexample/python-helpers-git/issues
235
- - **Discussions**: https://github.com/wexample/python-helpers-git/discussions
236
- - **PyPI**: [pypi.org/project/wexample-helpers-git](https://pypi.org/project/wexample-helpers-git/)
237
-
238
- ## Migration Notes
239
-
240
- When upgrading between major versions, refer to the migration guides in the documentation.
241
-
242
- Breaking changes are clearly documented with upgrade paths and examples.
@@ -1,222 +0,0 @@
1
- # helpers_git
2
-
3
- Version: 7.1.6
4
-
5
- `wexample-helpers-git` is a Python library of focused helpers for scripting common Git operations: branch switching, staged commits, push and pull with automatic retries, tag management, change detection, and `.gitignore` canonicalization. It is aimed at Python tooling and automation code in the wexample ecosystem that needs reliable, programmatic control over local repositories and remote interactions without encoding raw subprocess calls inline. Network-facing operations such as `git_push_follow_tags`, `git_pull_rebase_autostash`, and `git_push_tag` include built-in retry logic via `GitRetryableCallbackManager`, which recognises transient server errors like HTTP 5xx and RPC failures automatically.
6
-
7
- ## Table of Contents
8
-
9
- - [Installation](#installation)
10
- - [Quickstart](#quickstart)
11
- - [Tests](#tests)
12
- - [Architecture](#architecture)
13
- - [Integration in the Suite](#integration-in-the-suite)
14
- - [Dependencies](#dependencies)
15
- - [Versioning & Compatibility Policy](#versioning--compatibility-policy)
16
- - [License](#license)
17
- - [About us](#about-us)
18
- - [Known Limitations & Roadmap](#known-limitations--roadmap)
19
- - [Status & Compatibility](#status--compatibility)
20
- - [Useful Links](#useful-links)
21
- - [Migration Notes](#migration-notes)
22
-
23
- ## Installation
24
-
25
- ```bash
26
- pip install wexample-helpers-git
27
- ```
28
-
29
- Requires Python >=3.10.
30
-
31
- ## Quickstart
32
-
33
- Install the package:
34
-
35
- ```bash
36
- pip install wexample-helpers-git
37
- ```
38
-
39
- The functions live in `wexample_helpers_git.helper.git`. Each one takes a `cwd` keyword argument pointing at the repository you want to operate on.
40
-
41
- ```python
42
- from wexample_helpers_git.helper.git import (
43
- git_current_branch,
44
- git_has_uncommitted_changes,
45
- git_get_current_commit_hash,
46
- )
47
-
48
- # Current branch name
49
- branch = git_current_branch(cwd="/path/to/repo")
50
- # → "main"
51
-
52
- # Whether there are any staged or unstaged changes
53
- dirty = git_has_uncommitted_changes(cwd="/path/to/repo")
54
- # → True
55
-
56
- # Full commit hash (pass short=True for the abbreviated form)
57
- sha = git_get_current_commit_hash(cwd="/path/to/repo")
58
- # → "a3f1c8d2e4b..."
59
- ```
60
-
61
- All three calls run `git` in a subprocess and return a Python value directly — no `Repo` object to construct, no intermediate result to parse.
62
-
63
- ## Tests
64
-
65
- This project uses `pytest` for testing and `pytest-cov` for code coverage analysis.
66
-
67
- ### Installation
68
-
69
- First, install the required testing dependencies:
70
- ```bash
71
- .venv/bin/python -m pip install pytest pytest-cov
72
- ```
73
-
74
- ### Basic Usage
75
-
76
- Run all tests with coverage:
77
- ```bash
78
- .venv/bin/python -m pytest --cov --cov-report=html
79
- ```
80
-
81
- ### Common Commands
82
- ```bash
83
- # Run tests with coverage for a specific module
84
- .venv/bin/python -m pytest --cov=your_module
85
-
86
- # Show which lines are not covered
87
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing
88
-
89
- # Generate an HTML coverage report
90
- .venv/bin/python -m pytest --cov=your_module --cov-report=html
91
-
92
- # Combine terminal and HTML reports
93
- .venv/bin/python -m pytest --cov=your_module --cov-report=term-missing --cov-report=html
94
-
95
- # Run specific test file with coverage
96
- .venv/bin/python -m pytest tests/test_file.py --cov=your_module --cov-report=term-missing
97
- ```
98
-
99
- ### Viewing HTML Reports
100
-
101
- After generating an HTML report, open `htmlcov/index.html` in your browser to view detailed line-by-line coverage information.
102
-
103
- ### Coverage Threshold
104
-
105
- To enforce a minimum coverage percentage:
106
- ```bash
107
- .venv/bin/python -m pytest --cov=your_module --cov-fail-under=80
108
- ```
109
-
110
- This will cause the test suite to fail if coverage drops below 80%.
111
-
112
- ## Architecture
113
-
114
- The package lives entirely under `src/wexample_helpers_git/` and has no runtime state. It is two sub-packages — `helper/` and `const/` — plus empty `__init__.py` stubs at each level.
115
-
116
- ### `helper/` — the functional layer
117
-
118
- Four modules, each with a distinct responsibility.
119
-
120
- **src/wexample_helpers_git/helper/git.py** is the main public API. It contains roughly thirty standalone functions covering branching (`git_create_or_switch_branch`, `git_switch_new_branch`, `git_checkout_new_branch`, `git_switch_branch`), staging and committing (`git_commit_all_with_message`), push and pull (`git_push_follow_tags`, `git_push_tag`, `git_pull_rebase_autostash`), tag operations (`git_tag_annotated`, `git_tag_lightweight`, `git_tag_exists`, `git_tag_points_to_head`), change detection (`git_has_uncommitted_changes`, `git_has_index_changes`, `git_has_working_changes`, `git_get_changed_paths`), and remote/upstream management (`git_ensure_upstream`, `git_set_upstream`, `git_get_upstream`, `git_get_remote_url`). Every function takes `cwd: FileStringOrPath` and resolves it via `file_resolve_path` from `wexample-helpers` before doing anything. All subprocess calls go through `git_run`, which is just:
121
-
122
- ```python
123
- def git_run(cmd: list[str], *args, **kwargs) -> ShellResult:
124
- return shell_run(cmd=["git", *cmd], *args, **kwargs)
125
- ```
126
-
127
- Network-facing calls pass `retries=3` to `git_run`, which forwards it to `shell_run` from `wexample-helpers`. `gitpython`'s `Repo` object is used only in `git_is_init` (to detect whether a path is a repository) and `git_remote_create_once` (to create a remote via the GitPython API when one does not already exist).
128
-
129
- **src/wexample_helpers_git/helper/repo.py** handles repository state fingerprinting. `repo_get_state` combines the HEAD hash with a hash of `git diff --name-only` output into a single string. `repo_has_changed` compares that string against a state file (`.last_git_state` by default) and updates it on change. `repo_has_changed_since` compares against a caller-held string instead of a file — useful when the caller wants to track state in memory.
130
-
131
- **src/wexample_helpers_git/helper/gitignore.py** is pure Python with no subprocess calls. `reorganize_gitignore_safe` takes the raw text of a `.gitignore`, checks every non-comment line for glob characters (`*`, `?`, `[`) or negations (`!`), and returns `None` if any are found — leaving the file untouched. When the file is safe, it splits it into blank-line-separated sections, deduplicates entries within each section, and sorts them case-insensitively, keeping leading comment blocks pinned to the top of each section and inline comments attached to their entry.
132
-
133
- **src/wexample_helpers_git/helper/git_retryable_callback_manager.py** defines `GitRetryableCallbackManager`, a subclass of `RetryableCallbackManager` from `wexample-helpers`. On construction it populates `transient_markers` with a list of lowercase strings (`"rpc failed"`, `"http 503"`, `"connection reset"`, etc.) and registers `_should_retry_git` as the `should_retry_callback`. That callback returns `True` when any marker appears in the lowercased error message. The class is designed to be instantiated directly for call-sites that need richer retry control beyond the `retries=` integer that `git_run` already accepts.
134
-
135
- ### `const/` — shared constants
136
-
137
- **src/wexample_helpers_git/const/common.py** declares five string constants: `GIT_BRANCH_MAIN`, `GIT_PROVIDER_GITHUB`, `GIT_PROVIDER_GITLAB`, `GIT_REMOTE_GITHUB`, and `GIT_REMOTE_ORIGIN`. Importing them avoids scattering the strings `"main"`, `"origin"`, and `"github"` across call-sites.
138
-
139
- ### Call path
140
-
141
- A typical call such as `git_commit_all_with_message("msg", cwd="/repo")` walks this path:
142
-
143
- 1. `file_resolve_path(cwd)` turns the argument into a `Path`.
144
- 2. `git_run(["add", "-A"], cwd=resolved)` prepends `"git"` and calls `shell_run`.
145
- 3. `shell_run` executes the subprocess and returns a `ShellResult` with `.stdout`, `.stderr`, and `.returncode`.
146
- 4. A second `git_run(["commit", "-m", message], ...)` follows the same path.
147
-
148
- For push and pull, step 2 also carries `retries=3`; `shell_run` re-runs the command on failure up to that limit.
149
-
150
- ### External dependencies
151
-
152
- `wexample-helpers` supplies `shell_run`, `ShellResult`, `file_resolve_path`, `RetryableCallbackManager`, and the `@base_class` decorator used by `GitRetryableCallbackManager`. `gitpython` is used only for the two functions that need a `Repo` object directly. `attrs` and `cattrs` are pulled in transitively through `@base_class`.
153
-
154
- ## Integration in the Suite
155
-
156
- This package is part of the Wexample Suite — a collection of high-quality, modular tools designed to work seamlessly together across multiple languages and environments.
157
-
158
- ### Related Packages
159
-
160
- The suite includes packages for configuration management, file handling, prompts, and more. Each package can be used independently or as part of the integrated suite.
161
-
162
- ## Dependencies
163
-
164
- - attrs: >=23.1.0
165
- - cattrs: >=23.1.0
166
- - gitpython:
167
- - wexample-helpers: >=20.5.0
168
-
169
- ## Versioning & Compatibility Policy
170
-
171
- Wexample packages follow **Semantic Versioning** (SemVer):
172
-
173
- - **MAJOR**: Breaking changes
174
- - **MINOR**: New features, backward compatible
175
- - **PATCH**: Bug fixes, backward compatible
176
-
177
- We maintain backward compatibility within major versions and provide clear migration guides for breaking changes.
178
-
179
- ## License
180
-
181
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
182
-
183
- Free to use in both personal and commercial projects.
184
-
185
- ## About us
186
-
187
- [Wexample](https://wexample.com) stands as a cornerstone of the digital ecosystem — a collective of seasoned engineers, researchers, and creators driven by a relentless pursuit of technological excellence. More than a media platform, it has grown into a vibrant community where innovation meets craftsmanship, and where every line of code reflects a commitment to clarity, durability, and shared intelligence.
188
-
189
- This packages suite embodies this spirit. Trusted by professionals and enthusiasts alike, it delivers a consistent, high-quality foundation for modern development — open, elegant, and battle-tested. Its reputation is built on years of collaboration, refinement, and rigorous attention to detail, making it a natural choice for those who demand both robustness and beauty in their tools.
190
-
191
- Wexample cultivates a culture of mastery. Each package, each contribution carries the mark of a community that values precision, ethics, and innovation — a community proud to shape the future of digital craftsmanship.
192
-
193
- Built and maintained by [Romain Weeger](https://weeger.io).
194
-
195
- ## Known Limitations & Roadmap
196
-
197
- Current limitations and planned features are tracked in the GitHub issues.
198
-
199
- See the [project roadmap](https://github.com/wexample/python-helpers_git/issues) for upcoming features and improvements.
200
-
201
- ## Status & Compatibility
202
-
203
- **Maturity**: Production-ready
204
-
205
- **Python Support**: >=3.10
206
-
207
- **OS Support**: Linux, macOS, Windows
208
-
209
- **Status**: Actively maintained
210
-
211
- ## Useful Links
212
-
213
- - **Homepage**: https://github.com/wexample/python-helpers-git
214
- - **Issue Tracker**: https://github.com/wexample/python-helpers-git/issues
215
- - **Discussions**: https://github.com/wexample/python-helpers-git/discussions
216
- - **PyPI**: [pypi.org/project/wexample-helpers-git](https://pypi.org/project/wexample-helpers-git/)
217
-
218
- ## Migration Notes
219
-
220
- When upgrading between major versions, refer to the migration guides in the documentation.
221
-
222
- Breaking changes are clearly documented with upgrade paths and examples.
File without changes
File without changes