wexample-helpers-git 7.0.0__tar.gz → 7.1.0__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.0/PKG-INFO +243 -0
  2. wexample_helpers_git-7.1.0/README.md +223 -0
  3. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/pyproject.toml +3 -3
  4. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/const/common.py +1 -0
  5. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/helper/git.py +29 -3
  6. wexample_helpers_git-7.0.0/tests/helper/__init__.py → wexample_helpers_git-7.1.0/tests/.gitkeep +0 -0
  7. {wexample_helpers_git-7.0.0/tests/unit → wexample_helpers_git-7.1.0/tests/helper}/__init__.py +0 -0
  8. wexample_helpers_git-7.1.0/tests/unit/helper/__init__.py +0 -0
  9. wexample_helpers_git-7.0.0/PKG-INFO +0 -474
  10. wexample_helpers_git-7.0.0/README.md +0 -454
  11. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/__init__.py +0 -0
  12. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/__pycache__/__init__.py +0 -0
  13. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/const/__init__.py +0 -0
  14. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/helper/__init__.py +0 -0
  15. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/helper/__pycache__/__init__.py +0 -0
  16. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/helper/git_retryable_callback_manager.py +0 -0
  17. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/helper/gitignore.py +0 -0
  18. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/helper/repo.py +0 -0
  19. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/src/wexample_helpers_git/py.typed +0 -0
  20. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/tests/helper/test_helper_git.py +0 -0
  21. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/tests/helper/test_repo.py +0 -0
  22. {wexample_helpers_git-7.0.0/tests/unit/helper → wexample_helpers_git-7.1.0/tests/unit}/__init__.py +0 -0
  23. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/tests/unit/helper/test_git.py +0 -0
  24. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/tests/unit/helper/test_git_retryable_callback_manager.py +0 -0
  25. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/tests/unit/helper/test_gitignore.py +0 -0
  26. {wexample_helpers_git-7.0.0 → wexample_helpers_git-7.1.0}/tests/unit/helper/test_repo.py +0 -0
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.1
2
+ Name: wexample-helpers-git
3
+ Version: 7.1.0
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>=19.1.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.0
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
+ Visit the [Wexample Suite documentation](https://docs.wexample.com) for the complete package ecosystem.
183
+
184
+ ## Dependencies
185
+
186
+ - attrs: >=23.1.0
187
+ - cattrs: >=23.1.0
188
+ - gitpython:
189
+ - wexample-helpers: >=19.1.0
190
+
191
+ ## Versioning & Compatibility Policy
192
+
193
+ Wexample packages follow **Semantic Versioning** (SemVer):
194
+
195
+ - **MAJOR**: Breaking changes
196
+ - **MINOR**: New features, backward compatible
197
+ - **PATCH**: Bug fixes, backward compatible
198
+
199
+ We maintain backward compatibility within major versions and provide clear migration guides for breaking changes.
200
+
201
+ ## License
202
+
203
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
204
+
205
+ Free to use in both personal and commercial projects.
206
+
207
+ ## About us
208
+
209
+ [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.
210
+
211
+ 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.
212
+
213
+ 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.
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
+ - **Documentation**: [docs.wexample.com](https://docs.wexample.com)
235
+ - **Issue Tracker**: https://github.com/wexample/python-helpers-git/issues
236
+ - **Discussions**: https://github.com/wexample/python-helpers-git/discussions
237
+ - **PyPI**: [pypi.org/project/wexample-helpers-git](https://pypi.org/project/wexample-helpers-git/)
238
+
239
+ ## Migration Notes
240
+
241
+ When upgrading between major versions, refer to the migration guides in the documentation.
242
+
243
+ Breaking changes are clearly documented with upgrade paths and examples.
@@ -0,0 +1,223 @@
1
+ # helpers_git
2
+
3
+ Version: 7.1.0
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
+ Visit the [Wexample Suite documentation](https://docs.wexample.com) for the complete package ecosystem.
163
+
164
+ ## Dependencies
165
+
166
+ - attrs: >=23.1.0
167
+ - cattrs: >=23.1.0
168
+ - gitpython:
169
+ - wexample-helpers: >=19.1.0
170
+
171
+ ## Versioning & Compatibility Policy
172
+
173
+ Wexample packages follow **Semantic Versioning** (SemVer):
174
+
175
+ - **MAJOR**: Breaking changes
176
+ - **MINOR**: New features, backward compatible
177
+ - **PATCH**: Bug fixes, backward compatible
178
+
179
+ We maintain backward compatibility within major versions and provide clear migration guides for breaking changes.
180
+
181
+ ## License
182
+
183
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
184
+
185
+ Free to use in both personal and commercial projects.
186
+
187
+ ## About us
188
+
189
+ [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.
190
+
191
+ 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.
192
+
193
+ 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.
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
+ - **Documentation**: [docs.wexample.com](https://docs.wexample.com)
215
+ - **Issue Tracker**: https://github.com/wexample/python-helpers-git/issues
216
+ - **Discussions**: https://github.com/wexample/python-helpers-git/discussions
217
+ - **PyPI**: [pypi.org/project/wexample-helpers-git](https://pypi.org/project/wexample-helpers-git/)
218
+
219
+ ## Migration Notes
220
+
221
+ When upgrading between major versions, refer to the migration guides in the documentation.
222
+
223
+ Breaking changes are clearly documented with upgrade paths and examples.
@@ -6,8 +6,8 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "wexample-helpers-git"
9
- version = "7.0.0"
10
- description = "Some python basic helpers for git."
9
+ version = "7.1.0"
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" },
13
13
  ]
@@ -21,7 +21,7 @@ dependencies = [
21
21
  "attrs>=23.1.0",
22
22
  "cattrs>=23.1.0",
23
23
  "gitpython",
24
- "wexample-helpers>=19.0.0",
24
+ "wexample-helpers>=19.1.0",
25
25
  ]
26
26
 
27
27
  [project.readme]
@@ -4,4 +4,5 @@ from __future__ import annotations
4
4
  GIT_BRANCH_MAIN: str = "main"
5
5
  GIT_PROVIDER_GITHUB: str = "github"
6
6
  GIT_PROVIDER_GITLAB: str = "gitlab"
7
+ GIT_REMOTE_GITHUB: str = "github"
7
8
  GIT_REMOTE_ORIGIN: str = "origin"
@@ -24,14 +24,25 @@ def git_checkout_new_branch(
24
24
 
25
25
 
26
26
  def git_commit_all_with_message(
27
- message: str, *, cwd: FileStringOrPath, inherit_stdio: bool = True
27
+ message: str,
28
+ *,
29
+ cwd: FileStringOrPath,
30
+ inherit_stdio: bool = True,
31
+ sudo_user: str | None = None,
28
32
  ) -> None:
29
33
  """Stage all changes (including new files) and commit with the provided message."""
30
34
  from wexample_helpers.helper.file import file_resolve_path
31
35
 
32
36
  resolved = file_resolve_path(cwd)
33
- git_run(["add", "-A"], inherit_stdio=inherit_stdio, cwd=resolved)
34
- git_run(["commit", "-m", message], inherit_stdio=inherit_stdio, cwd=resolved)
37
+ git_run(
38
+ ["add", "-A"], inherit_stdio=inherit_stdio, cwd=resolved, sudo_user=sudo_user
39
+ )
40
+ git_run(
41
+ ["commit", "-m", message],
42
+ inherit_stdio=inherit_stdio,
43
+ cwd=resolved,
44
+ sudo_user=sudo_user,
45
+ )
35
46
 
36
47
 
37
48
  def git_create_or_switch_branch(
@@ -212,6 +223,21 @@ def git_has_changes_since_tag(
212
223
  return out == "CHANGED"
213
224
 
214
225
 
226
+ def git_has_commits(*, cwd: FileStringOrPath) -> bool:
227
+ """Return True if the repository has at least one commit."""
228
+ from wexample_helpers.helper.file import file_resolve_path
229
+
230
+ return (
231
+ git_run(
232
+ ["rev-parse", "--verify", "HEAD"],
233
+ inherit_stdio=False,
234
+ check=False,
235
+ cwd=file_resolve_path(cwd),
236
+ ).returncode
237
+ == 0
238
+ )
239
+
240
+
215
241
  def git_has_index_changes(*, cwd: FileStringOrPath) -> bool:
216
242
  """Return True if there are staged (indexed) changes."""
217
243
  from wexample_helpers.helper.file import file_resolve_path