gitnextver 1.0.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.
- gitnextver-1.0.0/.gitignore +128 -0
- gitnextver-1.0.0/.omc/project-memory.json +37 -0
- gitnextver-1.0.0/.omc/state/subagent-tracking.json +53 -0
- gitnextver-1.0.0/CLAUDE.md +70 -0
- gitnextver-1.0.0/LICENSE +201 -0
- gitnextver-1.0.0/PKG-INFO +72 -0
- gitnextver-1.0.0/README.md +43 -0
- gitnextver-1.0.0/pyproject.toml +66 -0
- gitnextver-1.0.0/src/gitnextver/__init__.py +12 -0
- gitnextver-1.0.0/src/gitnextver/__main__.py +7 -0
- gitnextver-1.0.0/src/gitnextver/__version__.py +24 -0
- gitnextver-1.0.0/src/gitnextver/cli.py +448 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
__marimo__/
|
|
40
|
+
__pycache__/
|
|
41
|
+
__pypackages__/
|
|
42
|
+
__version__.py
|
|
43
|
+
_version.py
|
|
44
|
+
.abstra/
|
|
45
|
+
.cache
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cursorignore
|
|
49
|
+
.cursorindexingignore
|
|
50
|
+
.dmypy.json
|
|
51
|
+
.DS_Store
|
|
52
|
+
.eggs/
|
|
53
|
+
.env
|
|
54
|
+
.envrc
|
|
55
|
+
.hypothesis/
|
|
56
|
+
.installed.cfg
|
|
57
|
+
.ipynb_checkpoints
|
|
58
|
+
.mypy_cache/
|
|
59
|
+
.nox/
|
|
60
|
+
.pdm-build/
|
|
61
|
+
.pdm-python
|
|
62
|
+
.pixi
|
|
63
|
+
.pybuilder/
|
|
64
|
+
.pypirc
|
|
65
|
+
.pyre/
|
|
66
|
+
.pytest_cache/
|
|
67
|
+
.Python
|
|
68
|
+
.pytype/
|
|
69
|
+
.ropeproject
|
|
70
|
+
.ruff_cache/
|
|
71
|
+
.scrapy
|
|
72
|
+
.spyderproject
|
|
73
|
+
.spyproject
|
|
74
|
+
.tox/
|
|
75
|
+
.venv
|
|
76
|
+
.webassets-cache
|
|
77
|
+
*.cover
|
|
78
|
+
*.egg
|
|
79
|
+
*.egg-info/
|
|
80
|
+
*.log
|
|
81
|
+
*.manifest
|
|
82
|
+
*.mo
|
|
83
|
+
*.pot
|
|
84
|
+
*.py.cover
|
|
85
|
+
*.py[codz]
|
|
86
|
+
*.sage.py
|
|
87
|
+
*.so
|
|
88
|
+
*.spec
|
|
89
|
+
*$py.class
|
|
90
|
+
/site
|
|
91
|
+
build/
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
celerybeat.pid
|
|
94
|
+
cover/
|
|
95
|
+
coverage.xml
|
|
96
|
+
cython_debug/
|
|
97
|
+
db.sqlite3
|
|
98
|
+
db.sqlite3-journal
|
|
99
|
+
develop-eggs/
|
|
100
|
+
dist/
|
|
101
|
+
dmypy.json
|
|
102
|
+
docs/_build/
|
|
103
|
+
downloads/
|
|
104
|
+
eggs/
|
|
105
|
+
env.bak/
|
|
106
|
+
env/
|
|
107
|
+
ENV/
|
|
108
|
+
htmlcov/
|
|
109
|
+
instance/
|
|
110
|
+
ipython_config.py
|
|
111
|
+
lib/
|
|
112
|
+
lib64/
|
|
113
|
+
local_settings.py
|
|
114
|
+
MANIFEST
|
|
115
|
+
marimo/_lsp/
|
|
116
|
+
marimo/_static/
|
|
117
|
+
nosetests.xml
|
|
118
|
+
parts/
|
|
119
|
+
pip-delete-this-directory.txt
|
|
120
|
+
pip-log.txt
|
|
121
|
+
profile_default/
|
|
122
|
+
sdist/
|
|
123
|
+
share/python-wheels/
|
|
124
|
+
target/
|
|
125
|
+
var/
|
|
126
|
+
venv.bak/
|
|
127
|
+
venv/
|
|
128
|
+
wheels/
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"lastScanned": 1775659826985,
|
|
4
|
+
"projectRoot": "/Users/adam/Developer/vcs3/github.twardoch/pub/gitnextver",
|
|
5
|
+
"techStack": {
|
|
6
|
+
"languages": [],
|
|
7
|
+
"frameworks": [],
|
|
8
|
+
"packageManager": null,
|
|
9
|
+
"runtime": null
|
|
10
|
+
},
|
|
11
|
+
"build": {
|
|
12
|
+
"buildCommand": null,
|
|
13
|
+
"testCommand": null,
|
|
14
|
+
"lintCommand": null,
|
|
15
|
+
"devCommand": null,
|
|
16
|
+
"scripts": {}
|
|
17
|
+
},
|
|
18
|
+
"conventions": {
|
|
19
|
+
"namingStyle": null,
|
|
20
|
+
"importStyle": null,
|
|
21
|
+
"testPattern": null,
|
|
22
|
+
"fileOrganization": null
|
|
23
|
+
},
|
|
24
|
+
"structure": {
|
|
25
|
+
"isMonorepo": false,
|
|
26
|
+
"workspaces": [],
|
|
27
|
+
"mainDirectories": [],
|
|
28
|
+
"gitBranches": {
|
|
29
|
+
"defaultBranch": "main",
|
|
30
|
+
"branchingStrategy": null
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"customNotes": [],
|
|
34
|
+
"directoryMap": {},
|
|
35
|
+
"hotPaths": [],
|
|
36
|
+
"userDirectives": []
|
|
37
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"agents": [
|
|
3
|
+
{
|
|
4
|
+
"agent_id": "a7dd8008147802d16",
|
|
5
|
+
"agent_type": "Explore",
|
|
6
|
+
"started_at": "2026-04-08T14:50:39.028Z",
|
|
7
|
+
"parent_mode": "none",
|
|
8
|
+
"status": "completed",
|
|
9
|
+
"completed_at": "2026-04-08T14:51:40.022Z",
|
|
10
|
+
"duration_ms": 60994
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"agent_id": "a6fd8fecc70890750",
|
|
14
|
+
"agent_type": "oh-my-claudecode:executor",
|
|
15
|
+
"started_at": "2026-04-08T14:58:01.667Z",
|
|
16
|
+
"parent_mode": "ultrawork",
|
|
17
|
+
"status": "completed",
|
|
18
|
+
"completed_at": "2026-04-08T14:58:20.791Z",
|
|
19
|
+
"duration_ms": 19124
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"agent_id": "a25f98b47d41e49c5",
|
|
23
|
+
"agent_type": "oh-my-claudecode:executor",
|
|
24
|
+
"started_at": "2026-04-08T14:58:11.582Z",
|
|
25
|
+
"parent_mode": "ultrawork",
|
|
26
|
+
"status": "completed",
|
|
27
|
+
"completed_at": "2026-04-08T14:59:20.059Z",
|
|
28
|
+
"duration_ms": 68477
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"agent_id": "a6b5450488b8eae7f",
|
|
32
|
+
"agent_type": "oh-my-claudecode:executor-low",
|
|
33
|
+
"started_at": "2026-04-08T14:58:13.504Z",
|
|
34
|
+
"parent_mode": "ultrawork",
|
|
35
|
+
"status": "completed",
|
|
36
|
+
"completed_at": "2026-04-08T14:58:22.403Z",
|
|
37
|
+
"duration_ms": 8899
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"agent_id": "aadd6b355aaf008e3",
|
|
41
|
+
"agent_type": "oh-my-claudecode:executor-low",
|
|
42
|
+
"started_at": "2026-04-08T14:59:50.697Z",
|
|
43
|
+
"parent_mode": "ultrawork",
|
|
44
|
+
"status": "completed",
|
|
45
|
+
"completed_at": "2026-04-08T14:59:57.930Z",
|
|
46
|
+
"duration_ms": 7233
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"total_spawned": 5,
|
|
50
|
+
"total_completed": 5,
|
|
51
|
+
"total_failed": 0,
|
|
52
|
+
"last_updated": "2026-04-08T14:59:58.034Z"
|
|
53
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
**gitnextver** is a Git versioning automation CLI tool published to PyPI. It automatically bumps semantic version tags (`vX.Y.Z`) in Git repositories, commits all changes with the version as the commit message, creates the tag, and pushes to the remote.
|
|
8
|
+
|
|
9
|
+
### Workflow
|
|
10
|
+
|
|
11
|
+
1. Validate git repo
|
|
12
|
+
2. Ensure GitPython index compatibility (downgrade v3→v2 if needed)
|
|
13
|
+
3. Stash uncommitted changes (including untracked)
|
|
14
|
+
4. Pull from remote with conflict detection
|
|
15
|
+
5. Re-apply stash
|
|
16
|
+
6. Find latest `vX.Y.Z` tag, increment patch → next version
|
|
17
|
+
7. Stage all, commit, tag, push
|
|
18
|
+
|
|
19
|
+
## Tech Stack
|
|
20
|
+
|
|
21
|
+
- **Language:** Python 3.10+
|
|
22
|
+
- **Build system:** hatchling + hatch-vcs (git-tag-based semver)
|
|
23
|
+
- **Package manager:** uv
|
|
24
|
+
- **Dependencies:** GitPython, fire (CLI), rich (terminal UI), loguru (logging)
|
|
25
|
+
|
|
26
|
+
## Package Layout
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
src/gitnextver/
|
|
30
|
+
├── __init__.py # version import with fallback chain
|
|
31
|
+
├── __main__.py # `python -m gitnextver` entry point
|
|
32
|
+
├── __version__.py # generated by hatch-vcs (in .gitignore)
|
|
33
|
+
└── cli.py # all CLI logic, app() is the console_scripts entry point
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- `pyproject.toml` — `[project.scripts] gitnextver = "gitnextver.cli:app"`
|
|
37
|
+
- `gitnextver-old.md` — previous single-file implementation (reference only)
|
|
38
|
+
|
|
39
|
+
## Build & Run Commands
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Run directly via uvx (PyPI)
|
|
43
|
+
uvx gitnextver [--directory PATH] [--verbose]
|
|
44
|
+
|
|
45
|
+
# Development
|
|
46
|
+
uv sync # install deps + editable
|
|
47
|
+
uvx hatch build # build sdist + wheel
|
|
48
|
+
uvx hatch test # run tests
|
|
49
|
+
uvx ruff check --fix . # lint
|
|
50
|
+
uvx ruff format . # format
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Versioning
|
|
54
|
+
|
|
55
|
+
Versions are derived from git tags via hatch-vcs. `__version__.py` is auto-generated at build time and must not be committed (it's in `.gitignore`). To release a new version, create a git tag like `v1.2.3` and build.
|
|
56
|
+
|
|
57
|
+
## Architecture Notes
|
|
58
|
+
|
|
59
|
+
- CLI via `fire.Fire(main)` — the `app()` function in `cli.py` is the entry point
|
|
60
|
+
- Version tags parsed with regex `^v(\d+)\.(\d+)\.(\d+)$`, only patch is auto-incremented
|
|
61
|
+
- Remote selection: prefers `origin`, falls back to any available remote, skips gracefully if none
|
|
62
|
+
- GitPython compatibility: handles index version mismatch (v3→v2 downgrade) and index.lock cleanup
|
|
63
|
+
- Stash/restore pattern wraps pull to avoid losing local work on conflict
|
|
64
|
+
|
|
65
|
+
## Key Design Decisions
|
|
66
|
+
|
|
67
|
+
- Defaults to `v1.0.0` when no version tags exist
|
|
68
|
+
- Commits use the version string as the entire commit message (e.g., `v1.0.1`)
|
|
69
|
+
- All files are staged (`git add -A`) — intentional for the "snapshot and tag" workflow
|
|
70
|
+
- Conflicts abort with user-friendly Rich panels rather than attempting auto-resolution
|
gitnextver-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitnextver
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Automatically bump semantic version tags in Git repositories
|
|
5
|
+
Project-URL: Homepage, https://github.com/twardoch/gitnextver
|
|
6
|
+
Project-URL: Repository, https://github.com/twardoch/gitnextver
|
|
7
|
+
Project-URL: Issues, https://github.com/twardoch/gitnextver/issues
|
|
8
|
+
Author-email: Adam Twardoch <adam+github@twardoch.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: bump,git,semver,tag,version
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: fire
|
|
25
|
+
Requires-Dist: gitpython
|
|
26
|
+
Requires-Dist: loguru
|
|
27
|
+
Requires-Dist: rich
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# gitnextver
|
|
31
|
+
|
|
32
|
+
Automatically bump semantic version tags in Git repositories.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
pip install gitnextver
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or run directly:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
uvx gitnextver
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Bump patch version in current directory
|
|
50
|
+
gitnextver
|
|
51
|
+
|
|
52
|
+
# Specify directory
|
|
53
|
+
gitnextver --directory /path/to/repo
|
|
54
|
+
|
|
55
|
+
# Verbose output
|
|
56
|
+
gitnextver --verbose
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## What it does
|
|
60
|
+
|
|
61
|
+
1. Validates you're in a git repository
|
|
62
|
+
2. Stashes uncommitted changes
|
|
63
|
+
3. Pulls from remote with conflict detection
|
|
64
|
+
4. Re-applies stashed changes
|
|
65
|
+
5. Finds the latest `vX.Y.Z` tag and increments the patch version
|
|
66
|
+
6. Commits all changes, creates the tag, and pushes
|
|
67
|
+
|
|
68
|
+
Defaults to `v1.0.0` if no version tags exist.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
Apache-2.0
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# gitnextver
|
|
2
|
+
|
|
3
|
+
Automatically bump semantic version tags in Git repositories.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install gitnextver
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or run directly:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
uvx gitnextver
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Bump patch version in current directory
|
|
21
|
+
gitnextver
|
|
22
|
+
|
|
23
|
+
# Specify directory
|
|
24
|
+
gitnextver --directory /path/to/repo
|
|
25
|
+
|
|
26
|
+
# Verbose output
|
|
27
|
+
gitnextver --verbose
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## What it does
|
|
31
|
+
|
|
32
|
+
1. Validates you're in a git repository
|
|
33
|
+
2. Stashes uncommitted changes
|
|
34
|
+
3. Pulls from remote with conflict detection
|
|
35
|
+
4. Re-applies stashed changes
|
|
36
|
+
5. Finds the latest `vX.Y.Z` tag and increments the patch version
|
|
37
|
+
6. Commits all changes, creates the tag, and pushes
|
|
38
|
+
|
|
39
|
+
Defaults to `v1.0.0` if no version tags exist.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
Apache-2.0
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gitnextver"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Automatically bump semantic version tags in Git repositories"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Adam Twardoch", email = "adam+github@twardoch.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["git", "version", "semver", "tag", "bump"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Environment :: Console",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"License :: OSI Approved :: Apache Software License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Software Development :: Version Control :: Git",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"fire",
|
|
31
|
+
"GitPython",
|
|
32
|
+
"loguru",
|
|
33
|
+
"rich",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
gitnextver = "gitnextver.cli:app"
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/twardoch/gitnextver"
|
|
41
|
+
Repository = "https://github.com/twardoch/gitnextver"
|
|
42
|
+
Issues = "https://github.com/twardoch/gitnextver/issues"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.version]
|
|
45
|
+
source = "vcs"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.hooks.vcs]
|
|
48
|
+
version-file = "src/gitnextver/__version__.py"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/gitnextver"]
|
|
52
|
+
|
|
53
|
+
[tool.pytest.ini_options]
|
|
54
|
+
testpaths = ["tests"]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
target-version = "py310"
|
|
58
|
+
src = ["src"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint]
|
|
61
|
+
select = ["E", "F", "W", "I"]
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
python_version = "3.10"
|
|
65
|
+
warn_return_any = true
|
|
66
|
+
warn_unused_configs = true
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# this_file: src/gitnextver/__init__.py
|
|
2
|
+
"""gitnextver - Automatically bump semantic version tags in Git repositories."""
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
from gitnextver.__version__ import __version__
|
|
6
|
+
except ImportError:
|
|
7
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
__version__ = version("gitnextver")
|
|
11
|
+
except PackageNotFoundError:
|
|
12
|
+
__version__ = "0.0.0"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '1.0.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 0, 0)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
# this_file: src/gitnextver/cli.py
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Git Next Version Tool - Automatically bump version tags and commit changes.
|
|
5
|
+
|
|
6
|
+
This tool:
|
|
7
|
+
1. Checks if we're in a git repo
|
|
8
|
+
2. Pulls from remote repo
|
|
9
|
+
3. Handles conflicts gracefully
|
|
10
|
+
4. Determines next version tag based on existing tags
|
|
11
|
+
5. Commits all changes with version tag
|
|
12
|
+
6. Creates and pushes the new tag
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
import sys
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Optional
|
|
19
|
+
|
|
20
|
+
import fire # type: ignore
|
|
21
|
+
import git
|
|
22
|
+
from git.exc import GitCommandError, InvalidGitRepositoryError
|
|
23
|
+
from loguru import logger
|
|
24
|
+
from rich.console import Console
|
|
25
|
+
from rich.panel import Panel
|
|
26
|
+
from rich.text import Text
|
|
27
|
+
|
|
28
|
+
console = Console()
|
|
29
|
+
|
|
30
|
+
# Pre-compiled regex to match semantic version tags like v1.2.3
|
|
31
|
+
VERSION_PATTERN = re.compile(r"^v(\d+)\.(\d+)\.(\d+)$")
|
|
32
|
+
|
|
33
|
+
# Friendly default remote name
|
|
34
|
+
DEFAULT_REMOTE_NAME = "origin"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def setup_logging(verbose: bool = False) -> None:
|
|
38
|
+
"""Setup logging configuration."""
|
|
39
|
+
logger.remove()
|
|
40
|
+
level = "DEBUG" if verbose else "INFO"
|
|
41
|
+
logger.add(
|
|
42
|
+
sys.stderr,
|
|
43
|
+
format=(
|
|
44
|
+
"<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
|
|
45
|
+
"<level>{level: <8}</level> | <level>{message}</level>"
|
|
46
|
+
),
|
|
47
|
+
level=level,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def is_git_repo(path: Path) -> bool:
|
|
52
|
+
"""Check if the given path is a git repository."""
|
|
53
|
+
try:
|
|
54
|
+
git.Repo(path)
|
|
55
|
+
return True
|
|
56
|
+
except InvalidGitRepositoryError:
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_last_version_tag(repo: git.Repo) -> Optional[str]:
|
|
61
|
+
"""Get the last version tag in vA.B.C format."""
|
|
62
|
+
tags = repo.tags
|
|
63
|
+
version_tags = []
|
|
64
|
+
|
|
65
|
+
for tag in tags:
|
|
66
|
+
match = VERSION_PATTERN.match(tag.name)
|
|
67
|
+
if match:
|
|
68
|
+
major, minor, patch = map(int, match.groups())
|
|
69
|
+
version_tags.append((major, minor, patch, tag.name))
|
|
70
|
+
|
|
71
|
+
if not version_tags:
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
# Pick the tag with the highest numerical value
|
|
75
|
+
latest = max(version_tags, key=lambda x: (x[0], x[1], x[2]))
|
|
76
|
+
return latest[3]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def calculate_next_version(last_tag: Optional[str]) -> str:
|
|
80
|
+
"""Calculate the next version tag."""
|
|
81
|
+
if not last_tag:
|
|
82
|
+
return "v1.0.0"
|
|
83
|
+
|
|
84
|
+
match = VERSION_PATTERN.match(last_tag)
|
|
85
|
+
|
|
86
|
+
if not match:
|
|
87
|
+
return "v1.0.0"
|
|
88
|
+
|
|
89
|
+
major, minor, patch = map(int, match.groups())
|
|
90
|
+
return f"v{major}.{minor}.{patch + 1}"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _select_remote(repo: git.Repo):
|
|
94
|
+
"""Return a remote to interact with, or *None* if no remotes exist."""
|
|
95
|
+
remotes = {r.name: r for r in repo.remotes}
|
|
96
|
+
if DEFAULT_REMOTE_NAME in remotes:
|
|
97
|
+
return remotes[DEFAULT_REMOTE_NAME]
|
|
98
|
+
# Fallback to any remote if 'origin' is missing
|
|
99
|
+
return next(iter(remotes.values())) if remotes else None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def stash_uncommitted_changes(repo: git.Repo) -> bool:
|
|
103
|
+
"""Stash any uncommitted (including untracked) changes before a pull.
|
|
104
|
+
|
|
105
|
+
Returns True if a stash was created, False otherwise.
|
|
106
|
+
"""
|
|
107
|
+
if repo.is_dirty(untracked_files=True) or repo.untracked_files:
|
|
108
|
+
logger.info("Stashing uncommitted changes before pull …")
|
|
109
|
+
try:
|
|
110
|
+
# Include untracked files to ensure a clean working tree
|
|
111
|
+
repo.git.stash(
|
|
112
|
+
"push",
|
|
113
|
+
"--include-untracked",
|
|
114
|
+
"-m",
|
|
115
|
+
"gitnextver-auto-stash",
|
|
116
|
+
)
|
|
117
|
+
return True
|
|
118
|
+
except GitCommandError as e:
|
|
119
|
+
if "could not write index" in str(e):
|
|
120
|
+
# Try to fix index corruption
|
|
121
|
+
logger.warning("Git index appears corrupted, attempting to fix...")
|
|
122
|
+
try:
|
|
123
|
+
# Remove index lock if it exists
|
|
124
|
+
index_lock = Path(repo.git_dir) / "index.lock"
|
|
125
|
+
if index_lock.exists():
|
|
126
|
+
index_lock.unlink()
|
|
127
|
+
logger.info("Removed stale index.lock file")
|
|
128
|
+
|
|
129
|
+
# Reset the index
|
|
130
|
+
repo.git.reset("--mixed")
|
|
131
|
+
logger.info("Reset git index")
|
|
132
|
+
|
|
133
|
+
# Try stash again
|
|
134
|
+
repo.git.stash(
|
|
135
|
+
"push",
|
|
136
|
+
"--include-untracked",
|
|
137
|
+
"-m",
|
|
138
|
+
"gitnextver-auto-stash",
|
|
139
|
+
)
|
|
140
|
+
return True
|
|
141
|
+
except Exception as fix_error:
|
|
142
|
+
logger.error(f"Failed to fix git index: {fix_error}")
|
|
143
|
+
console.print(
|
|
144
|
+
Panel(
|
|
145
|
+
Text(
|
|
146
|
+
"Git index is corrupted. Try running:\n"
|
|
147
|
+
"rm -f .git/index.lock\n"
|
|
148
|
+
"git reset --mixed",
|
|
149
|
+
style="bold red",
|
|
150
|
+
),
|
|
151
|
+
title="❌ Git Index Error",
|
|
152
|
+
border_style="red",
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
raise
|
|
156
|
+
else:
|
|
157
|
+
raise
|
|
158
|
+
return False
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def apply_latest_stash(repo: git.Repo) -> bool:
|
|
162
|
+
"""Apply (pop) the most recent stash if one exists.
|
|
163
|
+
|
|
164
|
+
Returns True when the stash is successfully applied (or none existed).
|
|
165
|
+
Returns False when applying the stash leads to merge conflicts or other
|
|
166
|
+
errors that require manual user intervention.
|
|
167
|
+
"""
|
|
168
|
+
stash_list = repo.git.stash("list").strip()
|
|
169
|
+
if not stash_list:
|
|
170
|
+
# Nothing to apply
|
|
171
|
+
return True
|
|
172
|
+
|
|
173
|
+
try:
|
|
174
|
+
logger.info("Re-applying stashed changes …")
|
|
175
|
+
repo.git.stash("pop")
|
|
176
|
+
logger.info("Successfully re-applied stashed changes")
|
|
177
|
+
return True
|
|
178
|
+
except GitCommandError as exc:
|
|
179
|
+
message = str(exc)
|
|
180
|
+
if "CONFLICT" in message.upper():
|
|
181
|
+
logger.error("Applying stash resulted in conflicts")
|
|
182
|
+
console.print(
|
|
183
|
+
Panel(
|
|
184
|
+
Text(
|
|
185
|
+
"Applying stashed changes resulted in "
|
|
186
|
+
"merge conflicts!\n\n"
|
|
187
|
+
"Please resolve conflicts manually and run the "
|
|
188
|
+
"command again.",
|
|
189
|
+
style="bold red",
|
|
190
|
+
),
|
|
191
|
+
title="❌ Merge Conflict",
|
|
192
|
+
border_style="red",
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
return False
|
|
196
|
+
|
|
197
|
+
logger.error(f"Failed to apply stash: {exc}")
|
|
198
|
+
console.print(
|
|
199
|
+
Panel(
|
|
200
|
+
Text(f"Failed to apply stash: {exc}", style="bold red"),
|
|
201
|
+
title="❌ Stash Error",
|
|
202
|
+
border_style="red",
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
return False
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def pull_with_conflict_check(repo: git.Repo) -> bool:
|
|
209
|
+
"""Pull from the selected remote and check for merge conflicts.
|
|
210
|
+
|
|
211
|
+
Returns True on success, False if a conflict or pull failure occurred.
|
|
212
|
+
If no remote is configured, the function logs a warning and returns
|
|
213
|
+
True (nothing to pull).
|
|
214
|
+
"""
|
|
215
|
+
remote = _select_remote(repo)
|
|
216
|
+
|
|
217
|
+
if remote is None:
|
|
218
|
+
logger.warning("No git remotes configured – skipping pull step.")
|
|
219
|
+
return True
|
|
220
|
+
|
|
221
|
+
try:
|
|
222
|
+
logger.info(f"Pulling from remote '{remote.name}' …")
|
|
223
|
+
remote.pull()
|
|
224
|
+
logger.info("Successfully pulled from remote")
|
|
225
|
+
return True
|
|
226
|
+
except GitCommandError as exc:
|
|
227
|
+
if "CONFLICT" in str(exc).upper():
|
|
228
|
+
logger.error("Git pull resulted in conflicts")
|
|
229
|
+
console.print(
|
|
230
|
+
Panel(
|
|
231
|
+
Text(
|
|
232
|
+
"Git pull resulted in merge conflicts!\n\n"
|
|
233
|
+
"Please resolve conflicts manually and run the "
|
|
234
|
+
"command again.",
|
|
235
|
+
style="bold red",
|
|
236
|
+
),
|
|
237
|
+
title="❌ Merge Conflict",
|
|
238
|
+
border_style="red",
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
return False
|
|
242
|
+
|
|
243
|
+
logger.error(f"Git pull failed: {exc}")
|
|
244
|
+
console.print(
|
|
245
|
+
Panel(
|
|
246
|
+
Text(f"Git pull failed: {exc}", style="bold red"),
|
|
247
|
+
title="❌ Pull Error",
|
|
248
|
+
border_style="red",
|
|
249
|
+
)
|
|
250
|
+
)
|
|
251
|
+
return False
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def ensure_gitpython_compatibility(repo: git.Repo) -> None:
|
|
255
|
+
"""Ensure git index is compatible with GitPython by downgrading if needed."""
|
|
256
|
+
try:
|
|
257
|
+
# Test if GitPython can read the index
|
|
258
|
+
_ = repo.index.entries
|
|
259
|
+
except AssertionError as e:
|
|
260
|
+
# The AssertionError from GitPython index version incompatibility
|
|
261
|
+
logger.warning(f"Git index version incompatible with GitPython: {e}")
|
|
262
|
+
logger.warning("Attempting to downgrade git index to version 2...")
|
|
263
|
+
try:
|
|
264
|
+
# Downgrade index to version 2 (compatible with GitPython)
|
|
265
|
+
repo.git.update_index("--index-version", "2")
|
|
266
|
+
logger.info("Successfully downgraded git index to version 2")
|
|
267
|
+
|
|
268
|
+
# Verify the fix worked by testing index access again
|
|
269
|
+
_ = repo.index.entries
|
|
270
|
+
logger.info("GitPython can now access the git index")
|
|
271
|
+
except GitCommandError as downgrade_error:
|
|
272
|
+
logger.error(f"Failed to downgrade git index: {downgrade_error}")
|
|
273
|
+
raise
|
|
274
|
+
except Exception as verify_error:
|
|
275
|
+
logger.error(f"Git index still incompatible after downgrade: {verify_error}")
|
|
276
|
+
raise
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def commit_and_tag(
|
|
280
|
+
repo: git.Repo,
|
|
281
|
+
version: str,
|
|
282
|
+
verbose: bool = False,
|
|
283
|
+
) -> None:
|
|
284
|
+
"""Add all files, commit, create tag, and push."""
|
|
285
|
+
try:
|
|
286
|
+
# Add all untracked and modified files
|
|
287
|
+
logger.info("Adding all untracked and modified files...")
|
|
288
|
+
repo.git.add(A=True)
|
|
289
|
+
|
|
290
|
+
# Check if there are any changes to commit
|
|
291
|
+
if not repo.is_dirty() and not repo.untracked_files:
|
|
292
|
+
logger.warning("No changes to commit")
|
|
293
|
+
console.print(
|
|
294
|
+
Panel(
|
|
295
|
+
Text("No changes found to commit", style="yellow"),
|
|
296
|
+
title="⚠️ Warning",
|
|
297
|
+
border_style="yellow",
|
|
298
|
+
)
|
|
299
|
+
)
|
|
300
|
+
return
|
|
301
|
+
|
|
302
|
+
# Ensure GitPython compatibility before committing
|
|
303
|
+
ensure_gitpython_compatibility(repo)
|
|
304
|
+
|
|
305
|
+
# Commit with version as message
|
|
306
|
+
logger.info(f"Committing changes with message: {version}")
|
|
307
|
+
repo.index.commit(version)
|
|
308
|
+
|
|
309
|
+
# Create tag
|
|
310
|
+
logger.info(f"Creating tag: {version}")
|
|
311
|
+
repo.create_tag(version)
|
|
312
|
+
|
|
313
|
+
# Push commits and tags
|
|
314
|
+
logger.info("Pushing commits and tags to remote...")
|
|
315
|
+
remote = _select_remote(repo)
|
|
316
|
+
if remote is None:
|
|
317
|
+
logger.warning("No remotes configured – skipping push step.")
|
|
318
|
+
else:
|
|
319
|
+
remote.push()
|
|
320
|
+
remote.push(tags=True)
|
|
321
|
+
|
|
322
|
+
console.print(
|
|
323
|
+
Panel(
|
|
324
|
+
Text(
|
|
325
|
+
f"✅ Successfully created and pushed version {version}",
|
|
326
|
+
style="bold green",
|
|
327
|
+
),
|
|
328
|
+
title="🎉 Success",
|
|
329
|
+
border_style="green",
|
|
330
|
+
)
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
except GitCommandError as e:
|
|
334
|
+
logger.error(f"Git operation failed: {e}")
|
|
335
|
+
console.print(
|
|
336
|
+
Panel(
|
|
337
|
+
Text(f"Git operation failed: {str(e)}", style="bold red"),
|
|
338
|
+
title="❌ Git Error",
|
|
339
|
+
border_style="red",
|
|
340
|
+
)
|
|
341
|
+
)
|
|
342
|
+
sys.exit(1)
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def main(directory: Optional[str] = None, verbose: bool = False) -> None:
|
|
346
|
+
"""
|
|
347
|
+
Main function to handle git version tagging.
|
|
348
|
+
|
|
349
|
+
Args:
|
|
350
|
+
directory: Directory to work in (defaults to current directory)
|
|
351
|
+
verbose: Enable verbose logging
|
|
352
|
+
"""
|
|
353
|
+
setup_logging(verbose)
|
|
354
|
+
|
|
355
|
+
# Determine working directory
|
|
356
|
+
work_dir = Path(directory) if directory else Path.cwd()
|
|
357
|
+
work_dir = work_dir.resolve()
|
|
358
|
+
|
|
359
|
+
logger.info(f"Working in directory: {work_dir}")
|
|
360
|
+
|
|
361
|
+
# Check if it's a git repository
|
|
362
|
+
if not is_git_repo(work_dir):
|
|
363
|
+
console.print(
|
|
364
|
+
Panel(
|
|
365
|
+
Text(
|
|
366
|
+
f"Directory {work_dir} is not a git repository!",
|
|
367
|
+
style="bold red",
|
|
368
|
+
),
|
|
369
|
+
title="❌ Not a Git Repository",
|
|
370
|
+
border_style="red",
|
|
371
|
+
)
|
|
372
|
+
)
|
|
373
|
+
sys.exit(1)
|
|
374
|
+
|
|
375
|
+
# Initialize git repo object
|
|
376
|
+
repo = git.Repo(work_dir)
|
|
377
|
+
|
|
378
|
+
# Ensure git index is compatible with GitPython early on
|
|
379
|
+
try:
|
|
380
|
+
ensure_gitpython_compatibility(repo)
|
|
381
|
+
except Exception as e:
|
|
382
|
+
logger.error(f"Failed to ensure GitPython compatibility: {e}")
|
|
383
|
+
console.print(
|
|
384
|
+
Panel(
|
|
385
|
+
Text(
|
|
386
|
+
f"Git index compatibility issue: {e}\n\n"
|
|
387
|
+
"This may be due to a newer git index version. "
|
|
388
|
+
"Try running: git update-index --index-version=2",
|
|
389
|
+
style="bold red",
|
|
390
|
+
),
|
|
391
|
+
title="❌ Git Index Error",
|
|
392
|
+
border_style="red",
|
|
393
|
+
)
|
|
394
|
+
)
|
|
395
|
+
sys.exit(1)
|
|
396
|
+
|
|
397
|
+
# If there are local changes, stash them so that pull can proceed safely
|
|
398
|
+
had_stash = stash_uncommitted_changes(repo)
|
|
399
|
+
|
|
400
|
+
# Pull from remote
|
|
401
|
+
if not pull_with_conflict_check(repo):
|
|
402
|
+
# If pull failed and we created a stash, attempt to restore it so the
|
|
403
|
+
# user does not lose their work (even though they may need to resolve
|
|
404
|
+
# issues manually afterwards).
|
|
405
|
+
if had_stash:
|
|
406
|
+
try:
|
|
407
|
+
repo.git.stash("pop")
|
|
408
|
+
except GitCommandError:
|
|
409
|
+
# If even restoring fails we still proceed to exit – the user
|
|
410
|
+
# has to handle the situation manually.
|
|
411
|
+
pass
|
|
412
|
+
sys.exit(1)
|
|
413
|
+
|
|
414
|
+
# Re-apply stashed changes (if any)
|
|
415
|
+
if had_stash and not apply_latest_stash(repo):
|
|
416
|
+
sys.exit(1)
|
|
417
|
+
|
|
418
|
+
# Get last version tag
|
|
419
|
+
last_tag = get_last_version_tag(repo)
|
|
420
|
+
logger.info(f"Last version tag: {last_tag if last_tag else 'None found'}")
|
|
421
|
+
|
|
422
|
+
# Calculate next version
|
|
423
|
+
next_version = calculate_next_version(last_tag)
|
|
424
|
+
logger.info(f"Next version will be: {next_version}")
|
|
425
|
+
|
|
426
|
+
console.print(
|
|
427
|
+
Panel(
|
|
428
|
+
Text(
|
|
429
|
+
f"Current version: {last_tag if last_tag else 'None'}\n"
|
|
430
|
+
f"Next version: {next_version}",
|
|
431
|
+
style="bold blue",
|
|
432
|
+
),
|
|
433
|
+
title="📋 Version Info",
|
|
434
|
+
border_style="blue",
|
|
435
|
+
)
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
# Commit and tag
|
|
439
|
+
commit_and_tag(repo, next_version, verbose)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def app() -> None:
|
|
443
|
+
"""CLI entry point for gitnextver."""
|
|
444
|
+
fire.Fire(main)
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
if __name__ == "__main__":
|
|
448
|
+
app()
|