gitbolt 0.0.0.dev1__py3-none-any.whl
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.
- gitbolt/__init__.py +18 -0
- gitbolt/_internal_init.py +18 -0
- gitbolt/add.py +652 -0
- gitbolt/base.py +333 -0
- gitbolt/exceptions.py +46 -0
- gitbolt/git_subprocess/__init__.py +14 -0
- gitbolt/git_subprocess/_internal_init.py +9 -0
- gitbolt/git_subprocess/add.py +484 -0
- gitbolt/git_subprocess/base.py +436 -0
- gitbolt/git_subprocess/constants.py +13 -0
- gitbolt/git_subprocess/exceptions.py +110 -0
- gitbolt/git_subprocess/impl/__init__.py +6 -0
- gitbolt/git_subprocess/impl/simple.py +185 -0
- gitbolt/git_subprocess/ls_tree.py +384 -0
- gitbolt/git_subprocess/runner/__init__.py +8 -0
- gitbolt/git_subprocess/runner/base.py +64 -0
- gitbolt/git_subprocess/runner/simple_impl.py +89 -0
- gitbolt/git_subprocess/utils.py +179 -0
- gitbolt/ls_tree.py +155 -0
- gitbolt/models.py +686 -0
- gitbolt/py.typed +0 -0
- gitbolt/utils.py +179 -0
- gitbolt-0.0.0.dev1.dist-info/METADATA +308 -0
- gitbolt-0.0.0.dev1.dist-info/RECORD +27 -0
- gitbolt-0.0.0.dev1.dist-info/WHEEL +5 -0
- gitbolt-0.0.0.dev1.dist-info/licenses/LICENSE +201 -0
- gitbolt-0.0.0.dev1.dist-info/top_level.txt +1 -0
gitbolt/utils.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding=utf-8
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Utility functions related to processors specific to git commands.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
from gitbolt.models import GitOpts, GitEnvVars
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def merge_git_opts(primary: GitOpts, fallback: GitOpts) -> GitOpts:
|
|
15
|
+
"""
|
|
16
|
+
Merge the ``primary`` and ``fallback`` ``GitOpts`` object and return a new ``GitOpts`` object.
|
|
17
|
+
|
|
18
|
+
Construction of the new ``GitOpts`` object is done such that:
|
|
19
|
+
|
|
20
|
+
* first prioritise picking up a property from the ``primary``.
|
|
21
|
+
* if a property is ``None`` in the ``primary`` then that corresponding property is picked from the ``fallback``.
|
|
22
|
+
|
|
23
|
+
Example usage:
|
|
24
|
+
|
|
25
|
+
>>> from pathlib import Path
|
|
26
|
+
>>> from typing import cast
|
|
27
|
+
>>> _primary = cast(GitOpts, {
|
|
28
|
+
... "C": [Path("/repo")],
|
|
29
|
+
... "c": {"user.name": "Alice", "color.ui": None},
|
|
30
|
+
... "paginate": True,
|
|
31
|
+
... "no_pager": None,
|
|
32
|
+
... "exec_path": None,
|
|
33
|
+
... "git_dir": Path("/repo/.git"),
|
|
34
|
+
... "work_tree": None,
|
|
35
|
+
... "bare": None,
|
|
36
|
+
... "namespace": None
|
|
37
|
+
... })
|
|
38
|
+
>>> _fallback = cast(GitOpts, {
|
|
39
|
+
... "C": [Path("/fallback")],
|
|
40
|
+
... "c": {"user.name": "Bob", "core.editor": "vim"},
|
|
41
|
+
... "paginate": False,
|
|
42
|
+
... "no_pager": True,
|
|
43
|
+
... "exec_path": Path("/usr/lib/git-core"),
|
|
44
|
+
... "git_dir": None,
|
|
45
|
+
... "work_tree": Path("/fallback"),
|
|
46
|
+
... "bare": True,
|
|
47
|
+
... "namespace": "fallback-ns"
|
|
48
|
+
... })
|
|
49
|
+
>>> _merged = merge_git_opts(_primary, _fallback)
|
|
50
|
+
>>> _merged["C"] == [Path("/repo")]
|
|
51
|
+
True
|
|
52
|
+
>>> _merged["c"]
|
|
53
|
+
{'user.name': 'Alice', 'color.ui': None}
|
|
54
|
+
>>> _merged["paginate"]
|
|
55
|
+
True
|
|
56
|
+
>>> _merged["no_pager"]
|
|
57
|
+
True
|
|
58
|
+
>>> _merged["exec_path"] == Path("/usr/lib/git-core")
|
|
59
|
+
True
|
|
60
|
+
>>> _merged["git_dir"] == Path("/repo/.git")
|
|
61
|
+
True
|
|
62
|
+
>>> _merged["work_tree"] == Path("/fallback")
|
|
63
|
+
True
|
|
64
|
+
>>> _merged["bare"]
|
|
65
|
+
True
|
|
66
|
+
>>> _merged["namespace"]
|
|
67
|
+
'fallback-ns'
|
|
68
|
+
|
|
69
|
+
Empty example:
|
|
70
|
+
|
|
71
|
+
>>> merge_git_opts({}, {})
|
|
72
|
+
{}
|
|
73
|
+
|
|
74
|
+
Partial fallback behavior:
|
|
75
|
+
|
|
76
|
+
>>> merge_git_opts({"paginate": None}, {"paginate": True})["paginate"]
|
|
77
|
+
True
|
|
78
|
+
>>> 'paginate' in merge_git_opts({"paginate": None}, {"paginate": None})
|
|
79
|
+
False
|
|
80
|
+
>>> merge_git_opts({"paginate": False}, {"paginate": True})["paginate"]
|
|
81
|
+
False
|
|
82
|
+
|
|
83
|
+
:param primary: The first priority ``GitOpts`` object.
|
|
84
|
+
:param fallback: the second priority or fallback ``GitOpts`` object.
|
|
85
|
+
:return: A new ``GitOpts`` object that contains all the properties from the ``primary`` ``GitOpts`` object and
|
|
86
|
+
fallbacks on the corresponding property from the ``fallback`` ``GitOpts`` object if that corresponding property
|
|
87
|
+
is ``None`` in the ``primary`` ``GitOpts`` object.
|
|
88
|
+
"""
|
|
89
|
+
return merge_typed_dicts(primary, fallback, GitOpts)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def merge_git_envs(primary: GitEnvVars, fallback: GitEnvVars) -> GitEnvVars:
|
|
93
|
+
"""
|
|
94
|
+
Merge the ``primary`` and ``fallback`` ``GitEnvVars`` objects and return a new ``GitEnvVars`` object.
|
|
95
|
+
|
|
96
|
+
Construction of the new ``GitEnvVars`` object is done such that:
|
|
97
|
+
|
|
98
|
+
* values from ``primary`` are prioritized.
|
|
99
|
+
* if a key exists in both, and the value in ``primary`` is explicitly ``None``, then the value from ``fallback`` is used.
|
|
100
|
+
* if a value in ``primary`` is ``Unset``, it is retained and does not fall back.
|
|
101
|
+
* any keys missing from ``primary`` but present in ``fallback`` are included.
|
|
102
|
+
|
|
103
|
+
Example usage:
|
|
104
|
+
|
|
105
|
+
>>> from pathlib import Path
|
|
106
|
+
>>> from datetime import datetime
|
|
107
|
+
>>> from typing import cast
|
|
108
|
+
>>> _primary = cast(GitEnvVars, {
|
|
109
|
+
... "GIT_AUTHOR_NAME": "Alice",
|
|
110
|
+
... "GIT_AUTHOR_EMAIL": "alice@example.com",
|
|
111
|
+
... "GIT_COMMITTER_DATE": None,
|
|
112
|
+
... "GIT_EDITOR": None,
|
|
113
|
+
... "GIT_TRACE": 2,
|
|
114
|
+
... "GIT_SSH": Path("/usr/bin/ssh"),
|
|
115
|
+
... })
|
|
116
|
+
>>> _fallback = cast(GitEnvVars, {
|
|
117
|
+
... "GIT_AUTHOR_NAME": "Bob",
|
|
118
|
+
... "GIT_AUTHOR_EMAIL": "bob@example.com",
|
|
119
|
+
... "GIT_COMMITTER_DATE": datetime(2020, 1, 1),
|
|
120
|
+
... "GIT_EDITOR": "vim",
|
|
121
|
+
... "GIT_TRACE": Path("/tmp/trace.log"),
|
|
122
|
+
... "GIT_SSH": None,
|
|
123
|
+
... "GIT_CONFIG_GLOBAL": Path("/home/bob/.gitconfig"),
|
|
124
|
+
... "GIT_REDACT_COOKIES": "sessionid"
|
|
125
|
+
... })
|
|
126
|
+
>>> _merged = merge_git_envs(_primary, _fallback)
|
|
127
|
+
>>> _merged["GIT_AUTHOR_NAME"]
|
|
128
|
+
'Alice'
|
|
129
|
+
>>> _merged["GIT_AUTHOR_EMAIL"]
|
|
130
|
+
'alice@example.com'
|
|
131
|
+
>>> _merged["GIT_COMMITTER_DATE"]
|
|
132
|
+
datetime.datetime(2020, 1, 1, 0, 0)
|
|
133
|
+
>>> _merged["GIT_EDITOR"]
|
|
134
|
+
'vim'
|
|
135
|
+
>>> _merged["GIT_TRACE"]
|
|
136
|
+
2
|
|
137
|
+
>>> _merged["GIT_SSH"]==Path('/usr/bin/ssh')
|
|
138
|
+
True
|
|
139
|
+
>>> _merged["GIT_CONFIG_GLOBAL"]==Path('/home/bob/.gitconfig')
|
|
140
|
+
True
|
|
141
|
+
|
|
142
|
+
Empty example:
|
|
143
|
+
|
|
144
|
+
>>> empty = merge_git_envs({}, {})
|
|
145
|
+
>>> isinstance(empty, dict)
|
|
146
|
+
True
|
|
147
|
+
|
|
148
|
+
Partial fallback behavior:
|
|
149
|
+
|
|
150
|
+
>>> merge_git_envs({"GIT_EDITOR": None}, {"GIT_EDITOR": "nano"})["GIT_EDITOR"]
|
|
151
|
+
'nano'
|
|
152
|
+
>>> 'GIT_EDITOR' in merge_git_envs({"GIT_EDITOR": None}, {"GIT_EDITOR": None})
|
|
153
|
+
False
|
|
154
|
+
>>> merge_git_envs({"GIT_EDITOR": "code"}, {"GIT_EDITOR": "nano"})["GIT_EDITOR"]
|
|
155
|
+
'code'
|
|
156
|
+
|
|
157
|
+
>>> from vt.utils.commons.commons.core_py import Unset, UNSET
|
|
158
|
+
>>> merge_git_envs({"GIT_EDITOR": UNSET}, {"GIT_EDITOR": "nano"})["GIT_EDITOR"] is UNSET
|
|
159
|
+
True
|
|
160
|
+
|
|
161
|
+
:param primary: The first priority ``GitEnvVars`` object.
|
|
162
|
+
:param fallback: The second priority or fallback ``GitEnvVars`` object.
|
|
163
|
+
:return: A new ``GitEnvVars`` object that contains all the properties from the ``primary`` ``GitEnvVars`` object and
|
|
164
|
+
fallbacks on the corresponding property from the ``fallback`` ``GitEnvVars`` object if that corresponding property
|
|
165
|
+
is explicitly ``None`` in the ``primary`` ``GitEnvVars`` object.
|
|
166
|
+
"""
|
|
167
|
+
return merge_typed_dicts(primary, fallback, GitEnvVars)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
# TODO: check for typing this function
|
|
171
|
+
def merge_typed_dicts(primary, fallback, the_typed_dict):
|
|
172
|
+
merged = {}
|
|
173
|
+
for k in the_typed_dict.__annotations__.keys(): # type: ignore
|
|
174
|
+
val = primary.get(k) # type: ignore # required as mypy thinks k is not str
|
|
175
|
+
if val is None:
|
|
176
|
+
val = fallback.get(k) # type: ignore # required as mypy thinks k is not str
|
|
177
|
+
if val is not None:
|
|
178
|
+
merged[k] = val # type: ignore # required as mypy thinks k is not str
|
|
179
|
+
return merged
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gitbolt
|
|
3
|
+
Version: 0.0.0.dev1
|
|
4
|
+
Summary: Fast, flexible and type-safe Git commands in Python.
|
|
5
|
+
Author-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>
|
|
6
|
+
Maintainer-email: Suhas Krishna Srivastava <suhas.srivastava@vaastav.tech>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: homepage, https://github.com/Vaastav-Technologies/py-gitbolt
|
|
9
|
+
Project-URL: source, https://github.com/Vaastav-Technologies/py-gitbolt
|
|
10
|
+
Project-URL: issues, https://github.com/Vaastav-Technologies/py-gitbolt/issues
|
|
11
|
+
Keywords: git,vcs,library,version control
|
|
12
|
+
Classifier: Development Status :: 1 - Planning
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: Topic :: Education
|
|
16
|
+
Classifier: Topic :: Software Development
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Software Development :: Version Control
|
|
20
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.12
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: vt-err-hndlr==0.0.0dev1
|
|
30
|
+
Provides-Extra: pygit2
|
|
31
|
+
Requires-Dist: pygit2; extra == "pygit2"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# ๐ Gitbolt
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+

|
|
38
|
+
[](https://github.com/Vaastav-Technologies/py-gitbolt/actions/workflows/test.yml)
|
|
39
|
+
[](https://github.com/Vaastav-Technologies/py-gitbolt/actions/workflows/typecheck.yml)
|
|
40
|
+
[](https://github.com/Vaastav-Technologies/py-gitbolt/actions/workflows/lint.yml)
|
|
41
|
+
[](https://codecov.io/gh/Vaastav-Technologies/py-gitbolt)
|
|
42
|
+
[](https://github.com/Vaastav-Technologies/py-gitbolt/actions/workflows/python-publish.yml)
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
**Fast, flexible and type-safe Git command execution in Python using subprocess.**
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## โจ Features
|
|
50
|
+
|
|
51
|
+
* ๐ง **Typed:** All commands and options are statically type-checked.
|
|
52
|
+
* โก **Fast:** Minimal abstractions over subprocess, runs directly on your system Git.
|
|
53
|
+
* ๐งฉ **Composable:** Git commands and options can be passed around as objects.
|
|
54
|
+
* ๐ **Overridable:** Easily override environment variables and options in a chainable, readable manner.
|
|
55
|
+
* ๐ฆ **Lightweight:** No dependencies on heavy Git libraries or C extensions.
|
|
56
|
+
* ๐งฐ **Extensible:** Future support for output transformers and other plugins.
|
|
57
|
+
* ๐จ **Exception Handling:** Raises any error as a Python-recognisable exception.
|
|
58
|
+
* ๐ค **Debuggable:** Exceptions capture `stdout`, `stderr`, and the return code of the run command.
|
|
59
|
+
* ๐ค **Lazy Execution:** Inherently lazily processed.
|
|
60
|
+
* ๐ **Transparent Output:** Returns a Git command's `stdout` as-is.
|
|
61
|
+
* ๐งช **Terminal Functions:** Git subcommands are terminal functions.
|
|
62
|
+
* ๐งผ **Idiomatic Python:** Write commands in idiomatic Python at compile-time and be confident theyโll execute smoothly at runtime.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## ๐ฆ Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install gitbolt
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## ๐ก Motivation
|
|
75
|
+
|
|
76
|
+
Running system commands in Python can be tricky for the following reasons:
|
|
77
|
+
|
|
78
|
+
1. Arguments sent to `subprocess` may not be typed correctly and result in runtime errors.
|
|
79
|
+
2. Argument groups may be mutually exclusive or required conditionally โ again causing runtime issues.
|
|
80
|
+
3. Errors from subprocess are often unhelpful and difficult to debug.
|
|
81
|
+
|
|
82
|
+
Also, using subprocess effectively means you must:
|
|
83
|
+
|
|
84
|
+
* Understand and manage process setup, piping, and teardown.
|
|
85
|
+
* Know your CLI command intricacies in depth.
|
|
86
|
+
|
|
87
|
+
> This project exists to fix all that โ with ergonomics, speed, and type-safety.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## ๐ฏ Project Goals
|
|
92
|
+
|
|
93
|
+
### โ
Predictable Compile-Time Behavior
|
|
94
|
+
|
|
95
|
+
Type-checking ensures runtime safety.
|
|
96
|
+
|
|
97
|
+
### โ
Ergonomic APIs
|
|
98
|
+
|
|
99
|
+
<details>
|
|
100
|
+
<summary>Make git command interfaces as ergonomic to the user as possible.</summary>
|
|
101
|
+
|
|
102
|
+
#### Provide versions of most used command combinations
|
|
103
|
+
|
|
104
|
+
`git hash-object` supports taking multiple files and outputs a hash per file. But in practice, it's most often used to write a single file to the Git object database and return its hash. To match this real-world usage, Gitbolt offers a more ergonomic method that accepts one file and returns one hash โ while still giving you the flexibility to access the full range of `git hash-object` capabilities when needed.
|
|
105
|
+
|
|
106
|
+
#### Let subcommands be passed around as objects
|
|
107
|
+
|
|
108
|
+
Gitbolt lets you pass subcommands around as typed objects. This enables highly focused, minimal APIs โ you can write functions that accept only the subcommands they truly need. This leads to cleaner logic, better separation of concerns, and compile-time guarantees that help prevent misuse.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import gitbolt
|
|
112
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
113
|
+
|
|
114
|
+
git = SimpleGitCommand()
|
|
115
|
+
version_subcmd = git.version_subcmd
|
|
116
|
+
add_subcmd = git.add_subcmd
|
|
117
|
+
|
|
118
|
+
def method_which_only_adds_a_file(add_subcmd: gitbolt.base.Add):
|
|
119
|
+
"""
|
|
120
|
+
This method only requires the `add` subcommand.
|
|
121
|
+
"""
|
|
122
|
+
...
|
|
123
|
+
|
|
124
|
+
method_which_only_adds_a_file(add_subcmd)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
</details>
|
|
128
|
+
|
|
129
|
+
### โ
Subcommands as Objects
|
|
130
|
+
|
|
131
|
+
git subcommands are modeled as terminal functions that return stdout.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
135
|
+
|
|
136
|
+
git = SimpleGitCommand()
|
|
137
|
+
status_out = git.status_subcmd.status()
|
|
138
|
+
print(status_out)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## ๐ง Strong Typing Everywhere
|
|
144
|
+
|
|
145
|
+
Extensive use of type-hints ensures that invalid usages fail early โ at *compile-time*. Write at compile-time and be sure that commands run error-free at runtime.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
<details>
|
|
150
|
+
<summary>Allow users to set/unset/reset Git environment variables and main command options using typed, chainable, Pythonic methods โ just before a subcommand is executed.</summary>
|
|
151
|
+
|
|
152
|
+
### ๐งฌ Git Environment Variables
|
|
153
|
+
|
|
154
|
+
#### ๐ Override a single Git env (e.g., `GIT_TRACE`)
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
158
|
+
|
|
159
|
+
git = SimpleGitCommand()
|
|
160
|
+
git = git.git_envs_override(GIT_TRACE=True)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### ๐ Override multiple Git envs (e.g., `GIT_TRACE`, `GIT_DIR`, `GIT_EDITOR`)
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from pathlib import Path
|
|
167
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
168
|
+
|
|
169
|
+
git = SimpleGitCommand()
|
|
170
|
+
git = git.git_envs_override(GIT_TRACE=1, GIT_DIR=Path('/tmp/git-dir/'), GIT_EDITOR='vim')
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### ๐ชข Chain multiple overrides fluently
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from pathlib import Path
|
|
177
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
178
|
+
|
|
179
|
+
git = SimpleGitCommand()
|
|
180
|
+
overridden_git = git.git_envs_override(GIT_SSH=Path('/tmp/SSH')).git_envs_override(
|
|
181
|
+
GIT_TERMINAL_PROMPT=1,
|
|
182
|
+
GIT_NO_REPLACE_OBJECTS=True
|
|
183
|
+
)
|
|
184
|
+
re_overridden_git = overridden_git.git_envs_override(GIT_TRACE=True)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### โ Unset Git envs using a special `UNSET` marker
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
191
|
+
from vt.utils.commons.commons.core_py import UNSET
|
|
192
|
+
|
|
193
|
+
git = SimpleGitCommand()
|
|
194
|
+
overridden_git = git.git_envs_override(GIT_ADVICE=True, GIT_TRACE=True)
|
|
195
|
+
no_advice_unset_git = overridden_git.git_envs_override(GIT_TRACE=UNSET)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### ๐ Reset Git envs by setting new values
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
202
|
+
|
|
203
|
+
git = SimpleGitCommand()
|
|
204
|
+
overridden_git = git.git_envs_override(GIT_TRACE=True)
|
|
205
|
+
git_trace_reset_git = overridden_git.git_envs_override(GIT_TRACE=False)
|
|
206
|
+
```
|
|
207
|
+
</details>
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
<details>
|
|
212
|
+
<summary>Allow users to set/unset/reset git main command options in typed and pythonic manner just before subcommand run to provide maximal flexibility.</summary>
|
|
213
|
+
|
|
214
|
+
### โ๏ธ Git Main Command Options
|
|
215
|
+
|
|
216
|
+
#### ๐ Override a single Git opt (e.g., `--no-replace-objects`)
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
220
|
+
|
|
221
|
+
git = SimpleGitCommand()
|
|
222
|
+
git = git.git_opts_override(no_replace_objects=True)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### ๐ Override multiple options (e.g., `--git-dir`, `--paginate`)
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
from pathlib import Path
|
|
229
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
230
|
+
|
|
231
|
+
git = SimpleGitCommand()
|
|
232
|
+
git = git.git_opts_override(no_replace_objects=True, git_dir=Path(), paginate=True)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### ๐ชข Chain multiple option overrides fluently
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from pathlib import Path
|
|
239
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
240
|
+
|
|
241
|
+
git = SimpleGitCommand()
|
|
242
|
+
overridden_git = git.git_opts_override(exec_path=Path('tmp')).git_opts_override(
|
|
243
|
+
noglob_pathspecs=True,
|
|
244
|
+
no_advice=True
|
|
245
|
+
).git_opts_override(
|
|
246
|
+
config_env={'auth': 'suhas', 'comm': 'suyog'}
|
|
247
|
+
)
|
|
248
|
+
re_overridden_git = overridden_git.git_opts_override(glob_pathspecs=True)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
#### โ Unset Git opts using a special `UNSET` marker
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from pathlib import Path
|
|
255
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
256
|
+
from vt.utils.commons.commons.core_py import UNSET
|
|
257
|
+
|
|
258
|
+
git = SimpleGitCommand()
|
|
259
|
+
overridden_git = git.git_opts_override(exec_path=Path('tmp'), no_advice=True)
|
|
260
|
+
no_advice_unset_git = overridden_git.git_opts_override(no_advice=UNSET)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### ๐ Reset Git opts by setting new values
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from gitbolt.git_subprocess.impl.simple import SimpleGitCommand
|
|
267
|
+
|
|
268
|
+
git = SimpleGitCommand()
|
|
269
|
+
overridden_git = git.git_opts_override(no_advice=True)
|
|
270
|
+
no_advice_reset_git = overridden_git.git_opts_override(no_advice=False)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
</details>
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## ๐ Transparent by Default
|
|
279
|
+
|
|
280
|
+
Output of git commands is returned as-is. No transformations unless explicitly requested.
|
|
281
|
+
Transformers for formatting/parsing can be added later.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## โ
Benefits Out-of-the-Box
|
|
286
|
+
|
|
287
|
+
* ๐ Composable Git commands.
|
|
288
|
+
* ๐ค Returns raw stdout.
|
|
289
|
+
* ๐จ Exceptions with full context.
|
|
290
|
+
* ๐ค Lazy execution.
|
|
291
|
+
* ๐ง Strong typing and compile-time guarantees.
|
|
292
|
+
* ๐งผ Idiomatic Python.
|
|
293
|
+
* ๐งช Terminal subcommands.
|
|
294
|
+
* ๐ฃ Fail-fast on invalid usage.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## ๐ More Information
|
|
299
|
+
|
|
300
|
+
- ๐ [License (Apache-2.0)](./LICENSE)
|
|
301
|
+
- ๐ค [Contributing Guide](./CONTRIBUTING.md)
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## ๐ง Future Goals
|
|
306
|
+
|
|
307
|
+
* Support `pygit2` for direct, fast Git access.
|
|
308
|
+
* Enable `porcelain` support using `pygit2` where required.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
gitbolt/__init__.py,sha256=oGR5nG5-sMwKrU0xa5wNuBYX4bfUa4KjSKS0WpwfVM0,536
|
|
2
|
+
gitbolt/_internal_init.py,sha256=alSsIMgBWHmOdUo7P1ewftR12xPv8vb3ZgECuVsRMwk,485
|
|
3
|
+
gitbolt/add.py,sha256=F16d0SQfLrjbpUzJIjKFwGU4KLSjqtYLOA9oZ5gdNS0,31731
|
|
4
|
+
gitbolt/base.py,sha256=eUjzfu0OilCrOpxpwRyCSs7HD83OaXk6BCzxT8LKKhU,9322
|
|
5
|
+
gitbolt/exceptions.py,sha256=7YvR7whZYM1hlWZk4GxHbeNgJ0KJXElg5VFA1Vi-fiA,989
|
|
6
|
+
gitbolt/ls_tree.py,sha256=PrDSoh4Pnqh6g4AfX8kwgez_zHYaH4yqknULbFbisUY,6269
|
|
7
|
+
gitbolt/models.py,sha256=iwIO-ugHYiKS57I_LPo3uDFEQlAtu2mnn5AjZHHQg04,18828
|
|
8
|
+
gitbolt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
gitbolt/utils.py,sha256=XftX3LIKtfzjQaUZUF3QYaFJFM-QdFjc05ZrZSMSdeM,6315
|
|
10
|
+
gitbolt/git_subprocess/__init__.py,sha256=ynnsY2IDCsjzd2LU2GbXtIamNyBcME58q1yDsCBXCX8,515
|
|
11
|
+
gitbolt/git_subprocess/_internal_init.py,sha256=C6jfsbjXhIFHaDH9GE-wLPAN9WMlUU57rRLWvfpZuAs,255
|
|
12
|
+
gitbolt/git_subprocess/add.py,sha256=1PA9XonqFi2O941eBwIPMobSNgEJ0tgFYxlkVXSe1K4,17277
|
|
13
|
+
gitbolt/git_subprocess/base.py,sha256=3DIydF-yQ7cVmT0di5cJtBVz-w68tawxk2xpq0yfcz8,14399
|
|
14
|
+
gitbolt/git_subprocess/constants.py,sha256=3qHXbNjPf_DOhTPNHi3_bcvIpvtqvgFtpGoTJLYmTWk,250
|
|
15
|
+
gitbolt/git_subprocess/exceptions.py,sha256=cx4YKzxeBRSRKoF-oakZLpFUGrAHiGj1FtMIsiK5oHc,4063
|
|
16
|
+
gitbolt/git_subprocess/ls_tree.py,sha256=MmM3qh-kvkD_tGQG9yliLx-reY_5TIVEArvAXJN6rP4,13200
|
|
17
|
+
gitbolt/git_subprocess/utils.py,sha256=n9_kXPvDf0ACrzAm6SVVLBOFM1JyjHmXJl_99vBoPS8,4941
|
|
18
|
+
gitbolt/git_subprocess/impl/__init__.py,sha256=bxYluO0B3My-10H5Z0JuEGvZe_g8i71QTpt6iM0WXoU,97
|
|
19
|
+
gitbolt/git_subprocess/impl/simple.py,sha256=nMxZYp1ayX6kyigLzIfrT5kNLvTd3KjYPDUNV4iB04U,5653
|
|
20
|
+
gitbolt/git_subprocess/runner/__init__.py,sha256=LPxbj3AwKLXyDxxCLwAVtl5b5SKjaNDj99lkKz6VSOU,177
|
|
21
|
+
gitbolt/git_subprocess/runner/base.py,sha256=Sof2WaNyYULiObRF7WjaGs7-yGrdyeHUXchE2tg1820,1562
|
|
22
|
+
gitbolt/git_subprocess/runner/simple_impl.py,sha256=ov8lXamu489twQanej0lCkkjBmEXvXxqGrWI_aK3JzQ,2484
|
|
23
|
+
gitbolt-0.0.0.dev1.dist-info/licenses/LICENSE,sha256=pOzr5bMWS6mHi3vro8d5vw0qW1i14rVq2XFrDuystVY,11372
|
|
24
|
+
gitbolt-0.0.0.dev1.dist-info/METADATA,sha256=405JbuYEnngAtA4a-mVwfhSNMZTmOwDzzzZjMAnk2-Y,10724
|
|
25
|
+
gitbolt-0.0.0.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
26
|
+
gitbolt-0.0.0.dev1.dist-info/top_level.txt,sha256=QCXclkzSPZjgamcwB6XuKJexaJ1as_TLUUSGdIDA7VY,8
|
|
27
|
+
gitbolt-0.0.0.dev1.dist-info/RECORD,,
|