whygit 0.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.
- whygit-0.1.0/LICENSE +21 -0
- whygit-0.1.0/PKG-INFO +226 -0
- whygit-0.1.0/README.md +196 -0
- whygit-0.1.0/pyproject.toml +61 -0
- whygit-0.1.0/pyproject.toml.orig +49 -0
- whygit-0.1.0/src/whygit/__init__.py +1 -0
- whygit-0.1.0/src/whygit/__main__.py +5 -0
- whygit-0.1.0/src/whygit/cli.py +109 -0
- whygit-0.1.0/src/whygit/engine.py +179 -0
- whygit-0.1.0/src/whygit/errors.py +1108 -0
- whygit-0.1.0/src/whygit/findings.py +88 -0
- whygit-0.1.0/src/whygit/gitcmd.py +183 -0
- whygit-0.1.0/src/whygit/render.py +185 -0
- whygit-0.1.0/src/whygit/rules.py +1252 -0
- whygit-0.1.0/src/whygit/server.py +77 -0
- whygit-0.1.0/src/whygit/state.py +486 -0
whygit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kameswara Sai Srikar Manda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
whygit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: whygit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Explains what state your Git repository is in and how to fix it, in plain English. CLI and MCP server; read-only.
|
|
5
|
+
Keywords: git,education,mcp,cli,merge-conflict,beginners
|
|
6
|
+
Author: Kameswara Sai Srikar Manda
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Education
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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 :: Education
|
|
23
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
24
|
+
Requires-Dist: mcp>=2.3,<3
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Project-URL: Homepage, https://github.com/Srikarmk/whygit
|
|
27
|
+
Project-URL: Source, https://github.com/Srikarmk/whygit
|
|
28
|
+
Project-URL: Issues, https://github.com/Srikarmk/whygit/issues
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# whygit
|
|
32
|
+
|
|
33
|
+
**What just happened to my Git repository, and how do I fix it?**
|
|
34
|
+
|
|
35
|
+
whygit looks at a Git repository and tells you, in plain English, what state it is in and
|
|
36
|
+
which commands will get you out of it: a merge conflict, a rebase stopped halfway, a detached
|
|
37
|
+
HEAD, a rejected push, a login GitHub won't accept, a 120 MB CSV that GitHub will refuse.
|
|
38
|
+
Paste it an error message and it explains that too.
|
|
39
|
+
|
|
40
|
+
It is written for people meeting Git for the first time. Git's own messages are accurate
|
|
41
|
+
but hard to read; whygit turns them into a short explanation and the exact fix.
|
|
42
|
+
|
|
43
|
+
It only ever **reads** your repository. It never runs the fixes it suggests, so you stay in
|
|
44
|
+
control and learn the commands as you go.
|
|
45
|
+
|
|
46
|
+
There are two ways to use it, built on the same engine:
|
|
47
|
+
|
|
48
|
+
- **On the command line**, with no AI tools involved: `whygit`.
|
|
49
|
+
- **As an MCP server**, so an assistant such as Claude Code, Claude Desktop or Cursor gets a
|
|
50
|
+
reliable diagnosis instead of guessing from `git status`.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
whygit needs Python 3.10 or newer and Git. Pick one:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
uv tool install whygit # with uv (https://docs.astral.sh/uv/)
|
|
58
|
+
pipx install whygit # with pipx
|
|
59
|
+
uvx whygit # run once without installing
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This works the same on macOS, Windows and Linux.
|
|
63
|
+
|
|
64
|
+
## Use it from the terminal
|
|
65
|
+
|
|
66
|
+
Run it inside your project folder:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
whygit # what's wrong here, most urgent first
|
|
70
|
+
whygit status # a plain summary: branch, upstream, what's changed
|
|
71
|
+
whygit explain "fatal: refusing to merge unrelated histories"
|
|
72
|
+
git push 2>&1 | whygit explain -
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Options: `--path <folder>` (or `-C`) to look at another folder, `--json` for machine-readable
|
|
76
|
+
output, `--no-color` to turn off colour. Colour is only used in a real terminal and never
|
|
77
|
+
when `NO_COLOR` is set.
|
|
78
|
+
|
|
79
|
+
Exit codes: `0` nothing blocking, `1` something blocking was found, `2` bad usage (for example
|
|
80
|
+
the folder does not exist), `3` `explain` did not recognise the message.
|
|
81
|
+
|
|
82
|
+
### Example
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
$ whygit
|
|
86
|
+
whygit: /Users/sam/ds3500/hw2 (branch main)
|
|
87
|
+
|
|
88
|
+
[BLOCKING] Merge in progress with conflicts in 1 file
|
|
89
|
+
Git tried to combine two lines of work, but both changed the same part of these
|
|
90
|
+
files, so it stopped and is waiting for you to choose what the result should be.
|
|
91
|
+
Nothing is lost while you decide.
|
|
92
|
+
Conflicted files:
|
|
93
|
+
- analysis.py (both changed)
|
|
94
|
+
How to fix:
|
|
95
|
+
Finish the merge:
|
|
96
|
+
1. Open each file and find the blocks between <<<<<<< and >>>>>>>. The part
|
|
97
|
+
above ======= is one version, the part below is the other. Keep what you
|
|
98
|
+
want, and delete the three marker lines.
|
|
99
|
+
2. git add analysis.py
|
|
100
|
+
Marks the files as resolved
|
|
101
|
+
3. git commit --no-edit
|
|
102
|
+
Records the merge and finishes it
|
|
103
|
+
Or cancel the merge:
|
|
104
|
+
1. git merge --abort
|
|
105
|
+
Puts everything back the way it was before the merge started
|
|
106
|
+
Learn more: https://git-scm.com/docs/git-merge#_how_to_resolve_conflicts
|
|
107
|
+
|
|
108
|
+
1 blocking. whygit never runs these commands for you; copy the ones you want.
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Commands that can lose work (`git restore`, `git rebase --skip`, `git push --force-with-lease`
|
|
112
|
+
and so on) are always marked with a warning, and a safer option is listed first when one
|
|
113
|
+
exists.
|
|
114
|
+
|
|
115
|
+
## Use it with an AI assistant (MCP)
|
|
116
|
+
|
|
117
|
+
`whygit mcp` runs a Model Context Protocol server over stdio with three read-only tools:
|
|
118
|
+
|
|
119
|
+
| Tool | Use it when | Returns |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `diagnose_repo(path=".")` | something seems stuck or broken | every problem found, most urgent first, with explanation and fix |
|
|
122
|
+
| `explain_git_error(error_text, path=None)` | a git command printed an error | what the error means and the fix, using the repository's state if `path` is given |
|
|
123
|
+
| `explain_state(path=".")` | you want a neutral summary | branch, upstream, ahead/behind, remotes, staged and changed files, operations in progress |
|
|
124
|
+
|
|
125
|
+
Results are small JSON objects. Pass an absolute path: relative paths resolve against the
|
|
126
|
+
server's working directory, which for desktop apps is usually not your project. `~` works.
|
|
127
|
+
|
|
128
|
+
### Claude Code
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
claude mcp add --scope user whygit -- uvx whygit mcp
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`--scope user` makes it available in every project; leave it out to add it to the current
|
|
135
|
+
project only. Check it with `claude mcp list`.
|
|
136
|
+
|
|
137
|
+
### Claude Desktop
|
|
138
|
+
|
|
139
|
+
Open Settings > Developer > Edit Config, and add whygit to
|
|
140
|
+
`claude_desktop_config.json` (on macOS `~/Library/Application Support/Claude/`, on Windows
|
|
141
|
+
`%APPDATA%\Claude\`):
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"mcpServers": {
|
|
146
|
+
"whygit": {
|
|
147
|
+
"command": "uvx",
|
|
148
|
+
"args": ["whygit", "mcp"]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Restart Claude Desktop. If it can't find `uvx`, use the full path that `which uvx` (macOS)
|
|
155
|
+
or `where uvx` (Windows) prints as the `command`.
|
|
156
|
+
|
|
157
|
+
### Cursor
|
|
158
|
+
|
|
159
|
+
Add the same block to `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` in a project:
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"mcpServers": {
|
|
164
|
+
"whygit": {
|
|
165
|
+
"command": "uvx",
|
|
166
|
+
"args": ["whygit", "mcp"]
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
If you installed whygit with `uv tool install` or `pipx`, you can use `"command": "whygit"`
|
|
173
|
+
with `"args": ["mcp"]` instead.
|
|
174
|
+
|
|
175
|
+
## What it recognises
|
|
176
|
+
|
|
177
|
+
Repository states: merge conflicts (and a merge that is resolved but not committed, including
|
|
178
|
+
leftover `<<<<<<<` markers), a rebase stopped on a conflict or an `edit`, cherry-pick, revert,
|
|
179
|
+
`git am` and bisect in progress, detached HEAD (and commits that no branch points to),
|
|
180
|
+
diverged / behind / ahead of the upstream, no upstream yet (the first `git push -u`), no
|
|
181
|
+
remote, upstream branch deleted, no commits yet, not a repository (including being one folder
|
|
182
|
+
too high, and your home folder), a home folder that was accidentally turned into a
|
|
183
|
+
repository, nested repositories (common with downloaded starter code), files over GitHub's
|
|
184
|
+
100 MB limit (and over 50 MB) staged or in unpushed commits, files that usually hold secrets
|
|
185
|
+
(`.env`, `id_rsa`, `*.pem`, `kaggle.json`, credentials JSON), notebooks with large saved
|
|
186
|
+
outputs, Jupyter notebook conflicts, missing `user.name` / `user.email`, a leftover
|
|
187
|
+
`index.lock`, and folders Git refuses because of "dubious ownership".
|
|
188
|
+
|
|
189
|
+
Error messages: rejected pushes, "You have divergent branches", "refusing to merge unrelated
|
|
190
|
+
histories", GitHub login failures (passwords no longer work; it explains tokens, SSH and
|
|
191
|
+
`gh auth login`, and never asks for your token), `Permission denied (publickey)`, repository
|
|
192
|
+
not found, 403, "Your local changes would be overwritten", untracked files in the way,
|
|
193
|
+
"not a git repository", "src refspec main does not match any", "pathspec did not match",
|
|
194
|
+
"remote origin already exists", missing upstream, "couldn't find remote ref", GitHub's
|
|
195
|
+
large-file rejection (GH001), "detected dubious ownership", "Please tell me who you are",
|
|
196
|
+
`index.lock` exists, line-ending warnings, network errors, and more. If it doesn't recognise
|
|
197
|
+
a message, it says so and shows what it can see in the repository instead.
|
|
198
|
+
|
|
199
|
+
## The read-only promise
|
|
200
|
+
|
|
201
|
+
whygit never changes your repository, and this is enforced in code rather than left to good
|
|
202
|
+
intentions:
|
|
203
|
+
|
|
204
|
+
- Every Git command goes through a single function that only accepts read-only subcommands
|
|
205
|
+
(`status`, `rev-parse`, `for-each-ref`, `rev-list`, `diff`, `log`, `ls-files`, `cat-file`,
|
|
206
|
+
`config --get`, `remote -v`, ...) and refuses anything else, including the writing forms of
|
|
207
|
+
`config`, `remote` and `symbolic-ref`.
|
|
208
|
+
- It sets `GIT_OPTIONAL_LOCKS=0`, so even `git status` doesn't refresh the index, and turns off
|
|
209
|
+
external diff programs and the fsmonitor hook.
|
|
210
|
+
- It never runs `git fetch`. Ahead/behind counts are "as of your last fetch", and whygit tells
|
|
211
|
+
you to run `git fetch` yourself when that matters.
|
|
212
|
+
- The test suite builds each state in a real repository, snapshots every file under `.git`
|
|
213
|
+
(names, timestamps and contents) before and after diagnosing, and checks nothing changed. It
|
|
214
|
+
also checks that no other module in the package can start a process or write a file.
|
|
215
|
+
|
|
216
|
+
Credentials are never printed: a remote address like `https://name:token@github.com/...`
|
|
217
|
+
is shown as `https://***@github.com/...`, in every output.
|
|
218
|
+
|
|
219
|
+
## Privacy
|
|
220
|
+
|
|
221
|
+
whygit collects nothing and makes no network calls. It reads your repository on your own
|
|
222
|
+
computer and prints the result. That's all.
|
|
223
|
+
|
|
224
|
+
## Licence
|
|
225
|
+
|
|
226
|
+
MIT. Copyright (c) 2026 Kameswara Sai Srikar Manda.
|
whygit-0.1.0/README.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# whygit
|
|
2
|
+
|
|
3
|
+
**What just happened to my Git repository, and how do I fix it?**
|
|
4
|
+
|
|
5
|
+
whygit looks at a Git repository and tells you, in plain English, what state it is in and
|
|
6
|
+
which commands will get you out of it: a merge conflict, a rebase stopped halfway, a detached
|
|
7
|
+
HEAD, a rejected push, a login GitHub won't accept, a 120 MB CSV that GitHub will refuse.
|
|
8
|
+
Paste it an error message and it explains that too.
|
|
9
|
+
|
|
10
|
+
It is written for people meeting Git for the first time. Git's own messages are accurate
|
|
11
|
+
but hard to read; whygit turns them into a short explanation and the exact fix.
|
|
12
|
+
|
|
13
|
+
It only ever **reads** your repository. It never runs the fixes it suggests, so you stay in
|
|
14
|
+
control and learn the commands as you go.
|
|
15
|
+
|
|
16
|
+
There are two ways to use it, built on the same engine:
|
|
17
|
+
|
|
18
|
+
- **On the command line**, with no AI tools involved: `whygit`.
|
|
19
|
+
- **As an MCP server**, so an assistant such as Claude Code, Claude Desktop or Cursor gets a
|
|
20
|
+
reliable diagnosis instead of guessing from `git status`.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
whygit needs Python 3.10 or newer and Git. Pick one:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
uv tool install whygit # with uv (https://docs.astral.sh/uv/)
|
|
28
|
+
pipx install whygit # with pipx
|
|
29
|
+
uvx whygit # run once without installing
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This works the same on macOS, Windows and Linux.
|
|
33
|
+
|
|
34
|
+
## Use it from the terminal
|
|
35
|
+
|
|
36
|
+
Run it inside your project folder:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
whygit # what's wrong here, most urgent first
|
|
40
|
+
whygit status # a plain summary: branch, upstream, what's changed
|
|
41
|
+
whygit explain "fatal: refusing to merge unrelated histories"
|
|
42
|
+
git push 2>&1 | whygit explain -
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Options: `--path <folder>` (or `-C`) to look at another folder, `--json` for machine-readable
|
|
46
|
+
output, `--no-color` to turn off colour. Colour is only used in a real terminal and never
|
|
47
|
+
when `NO_COLOR` is set.
|
|
48
|
+
|
|
49
|
+
Exit codes: `0` nothing blocking, `1` something blocking was found, `2` bad usage (for example
|
|
50
|
+
the folder does not exist), `3` `explain` did not recognise the message.
|
|
51
|
+
|
|
52
|
+
### Example
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
$ whygit
|
|
56
|
+
whygit: /Users/sam/ds3500/hw2 (branch main)
|
|
57
|
+
|
|
58
|
+
[BLOCKING] Merge in progress with conflicts in 1 file
|
|
59
|
+
Git tried to combine two lines of work, but both changed the same part of these
|
|
60
|
+
files, so it stopped and is waiting for you to choose what the result should be.
|
|
61
|
+
Nothing is lost while you decide.
|
|
62
|
+
Conflicted files:
|
|
63
|
+
- analysis.py (both changed)
|
|
64
|
+
How to fix:
|
|
65
|
+
Finish the merge:
|
|
66
|
+
1. Open each file and find the blocks between <<<<<<< and >>>>>>>. The part
|
|
67
|
+
above ======= is one version, the part below is the other. Keep what you
|
|
68
|
+
want, and delete the three marker lines.
|
|
69
|
+
2. git add analysis.py
|
|
70
|
+
Marks the files as resolved
|
|
71
|
+
3. git commit --no-edit
|
|
72
|
+
Records the merge and finishes it
|
|
73
|
+
Or cancel the merge:
|
|
74
|
+
1. git merge --abort
|
|
75
|
+
Puts everything back the way it was before the merge started
|
|
76
|
+
Learn more: https://git-scm.com/docs/git-merge#_how_to_resolve_conflicts
|
|
77
|
+
|
|
78
|
+
1 blocking. whygit never runs these commands for you; copy the ones you want.
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Commands that can lose work (`git restore`, `git rebase --skip`, `git push --force-with-lease`
|
|
82
|
+
and so on) are always marked with a warning, and a safer option is listed first when one
|
|
83
|
+
exists.
|
|
84
|
+
|
|
85
|
+
## Use it with an AI assistant (MCP)
|
|
86
|
+
|
|
87
|
+
`whygit mcp` runs a Model Context Protocol server over stdio with three read-only tools:
|
|
88
|
+
|
|
89
|
+
| Tool | Use it when | Returns |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `diagnose_repo(path=".")` | something seems stuck or broken | every problem found, most urgent first, with explanation and fix |
|
|
92
|
+
| `explain_git_error(error_text, path=None)` | a git command printed an error | what the error means and the fix, using the repository's state if `path` is given |
|
|
93
|
+
| `explain_state(path=".")` | you want a neutral summary | branch, upstream, ahead/behind, remotes, staged and changed files, operations in progress |
|
|
94
|
+
|
|
95
|
+
Results are small JSON objects. Pass an absolute path: relative paths resolve against the
|
|
96
|
+
server's working directory, which for desktop apps is usually not your project. `~` works.
|
|
97
|
+
|
|
98
|
+
### Claude Code
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
claude mcp add --scope user whygit -- uvx whygit mcp
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`--scope user` makes it available in every project; leave it out to add it to the current
|
|
105
|
+
project only. Check it with `claude mcp list`.
|
|
106
|
+
|
|
107
|
+
### Claude Desktop
|
|
108
|
+
|
|
109
|
+
Open Settings > Developer > Edit Config, and add whygit to
|
|
110
|
+
`claude_desktop_config.json` (on macOS `~/Library/Application Support/Claude/`, on Windows
|
|
111
|
+
`%APPDATA%\Claude\`):
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"mcpServers": {
|
|
116
|
+
"whygit": {
|
|
117
|
+
"command": "uvx",
|
|
118
|
+
"args": ["whygit", "mcp"]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Restart Claude Desktop. If it can't find `uvx`, use the full path that `which uvx` (macOS)
|
|
125
|
+
or `where uvx` (Windows) prints as the `command`.
|
|
126
|
+
|
|
127
|
+
### Cursor
|
|
128
|
+
|
|
129
|
+
Add the same block to `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` in a project:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"mcpServers": {
|
|
134
|
+
"whygit": {
|
|
135
|
+
"command": "uvx",
|
|
136
|
+
"args": ["whygit", "mcp"]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
If you installed whygit with `uv tool install` or `pipx`, you can use `"command": "whygit"`
|
|
143
|
+
with `"args": ["mcp"]` instead.
|
|
144
|
+
|
|
145
|
+
## What it recognises
|
|
146
|
+
|
|
147
|
+
Repository states: merge conflicts (and a merge that is resolved but not committed, including
|
|
148
|
+
leftover `<<<<<<<` markers), a rebase stopped on a conflict or an `edit`, cherry-pick, revert,
|
|
149
|
+
`git am` and bisect in progress, detached HEAD (and commits that no branch points to),
|
|
150
|
+
diverged / behind / ahead of the upstream, no upstream yet (the first `git push -u`), no
|
|
151
|
+
remote, upstream branch deleted, no commits yet, not a repository (including being one folder
|
|
152
|
+
too high, and your home folder), a home folder that was accidentally turned into a
|
|
153
|
+
repository, nested repositories (common with downloaded starter code), files over GitHub's
|
|
154
|
+
100 MB limit (and over 50 MB) staged or in unpushed commits, files that usually hold secrets
|
|
155
|
+
(`.env`, `id_rsa`, `*.pem`, `kaggle.json`, credentials JSON), notebooks with large saved
|
|
156
|
+
outputs, Jupyter notebook conflicts, missing `user.name` / `user.email`, a leftover
|
|
157
|
+
`index.lock`, and folders Git refuses because of "dubious ownership".
|
|
158
|
+
|
|
159
|
+
Error messages: rejected pushes, "You have divergent branches", "refusing to merge unrelated
|
|
160
|
+
histories", GitHub login failures (passwords no longer work; it explains tokens, SSH and
|
|
161
|
+
`gh auth login`, and never asks for your token), `Permission denied (publickey)`, repository
|
|
162
|
+
not found, 403, "Your local changes would be overwritten", untracked files in the way,
|
|
163
|
+
"not a git repository", "src refspec main does not match any", "pathspec did not match",
|
|
164
|
+
"remote origin already exists", missing upstream, "couldn't find remote ref", GitHub's
|
|
165
|
+
large-file rejection (GH001), "detected dubious ownership", "Please tell me who you are",
|
|
166
|
+
`index.lock` exists, line-ending warnings, network errors, and more. If it doesn't recognise
|
|
167
|
+
a message, it says so and shows what it can see in the repository instead.
|
|
168
|
+
|
|
169
|
+
## The read-only promise
|
|
170
|
+
|
|
171
|
+
whygit never changes your repository, and this is enforced in code rather than left to good
|
|
172
|
+
intentions:
|
|
173
|
+
|
|
174
|
+
- Every Git command goes through a single function that only accepts read-only subcommands
|
|
175
|
+
(`status`, `rev-parse`, `for-each-ref`, `rev-list`, `diff`, `log`, `ls-files`, `cat-file`,
|
|
176
|
+
`config --get`, `remote -v`, ...) and refuses anything else, including the writing forms of
|
|
177
|
+
`config`, `remote` and `symbolic-ref`.
|
|
178
|
+
- It sets `GIT_OPTIONAL_LOCKS=0`, so even `git status` doesn't refresh the index, and turns off
|
|
179
|
+
external diff programs and the fsmonitor hook.
|
|
180
|
+
- It never runs `git fetch`. Ahead/behind counts are "as of your last fetch", and whygit tells
|
|
181
|
+
you to run `git fetch` yourself when that matters.
|
|
182
|
+
- The test suite builds each state in a real repository, snapshots every file under `.git`
|
|
183
|
+
(names, timestamps and contents) before and after diagnosing, and checks nothing changed. It
|
|
184
|
+
also checks that no other module in the package can start a process or write a file.
|
|
185
|
+
|
|
186
|
+
Credentials are never printed: a remote address like `https://name:token@github.com/...`
|
|
187
|
+
is shown as `https://***@github.com/...`, in every output.
|
|
188
|
+
|
|
189
|
+
## Privacy
|
|
190
|
+
|
|
191
|
+
whygit collects nothing and makes no network calls. It reads your repository on your own
|
|
192
|
+
computer and prints the result. That's all.
|
|
193
|
+
|
|
194
|
+
## Licence
|
|
195
|
+
|
|
196
|
+
MIT. Copyright (c) 2026 Kameswara Sai Srikar Manda.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "whygit"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Explains what state your Git repository is in and how to fix it, in plain English. CLI and MCP server; read-only."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
keywords = [
|
|
10
|
+
"git",
|
|
11
|
+
"education",
|
|
12
|
+
"mcp",
|
|
13
|
+
"cli",
|
|
14
|
+
"merge-conflict",
|
|
15
|
+
"beginners",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Environment :: Console",
|
|
20
|
+
"Intended Audience :: Education",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Operating System :: MacOS",
|
|
23
|
+
"Operating System :: Microsoft :: Windows",
|
|
24
|
+
"Operating System :: POSIX :: Linux",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
27
|
+
"Programming Language :: Python :: 3.10",
|
|
28
|
+
"Programming Language :: Python :: 3.11",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Topic :: Education",
|
|
32
|
+
"Topic :: Software Development :: Version Control :: Git",
|
|
33
|
+
]
|
|
34
|
+
dependencies = ["mcp>=2.3,<3"]
|
|
35
|
+
|
|
36
|
+
[[project.authors]]
|
|
37
|
+
name = "Kameswara Sai Srikar Manda"
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/Srikarmk/whygit"
|
|
41
|
+
Source = "https://github.com/Srikarmk/whygit"
|
|
42
|
+
Issues = "https://github.com/Srikarmk/whygit/issues"
|
|
43
|
+
|
|
44
|
+
[project.scripts]
|
|
45
|
+
whygit = "whygit.cli:main"
|
|
46
|
+
|
|
47
|
+
[dependency-groups]
|
|
48
|
+
dev = [
|
|
49
|
+
"pytest>=8",
|
|
50
|
+
"anyio>=4",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[build-system]
|
|
54
|
+
requires = ["uv_build>=0.9,<0.14"]
|
|
55
|
+
build-backend = "uv_build"
|
|
56
|
+
|
|
57
|
+
[tool.pytest.ini_options]
|
|
58
|
+
testpaths = ["tests"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 120
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "whygit"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Explains what state your Git repository is in and how to fix it, in plain English. CLI and MCP server; read-only."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Kameswara Sai Srikar Manda" }]
|
|
10
|
+
keywords = ["git", "education", "mcp", "cli", "merge-conflict", "beginners"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Environment :: Console",
|
|
14
|
+
"Intended Audience :: Education",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Operating System :: MacOS",
|
|
17
|
+
"Operating System :: Microsoft :: Windows",
|
|
18
|
+
"Operating System :: POSIX :: Linux",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Education",
|
|
26
|
+
"Topic :: Software Development :: Version Control :: Git",
|
|
27
|
+
]
|
|
28
|
+
dependencies = ["mcp>=2.3,<3"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/Srikarmk/whygit"
|
|
32
|
+
Source = "https://github.com/Srikarmk/whygit"
|
|
33
|
+
Issues = "https://github.com/Srikarmk/whygit/issues"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
whygit = "whygit.cli:main"
|
|
37
|
+
|
|
38
|
+
[dependency-groups]
|
|
39
|
+
dev = ["pytest>=8", "anyio>=4"]
|
|
40
|
+
|
|
41
|
+
[build-system]
|
|
42
|
+
requires = ["uv_build>=0.9,<0.14"]
|
|
43
|
+
build-backend = "uv_build"
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
|
|
48
|
+
[tool.ruff]
|
|
49
|
+
line-length = 120
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Command line front end: whygit, whygit status, whygit explain, whygit mcp."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .engine import PathNotFound, diagnose, explain_error, explain_state
|
|
11
|
+
from .render import Style, render_diagnosis, render_explanation, render_state, want_color
|
|
12
|
+
|
|
13
|
+
EPILOG = """examples:
|
|
14
|
+
whygit explain what's going on in this repository
|
|
15
|
+
whygit status plain summary: branch, upstream, changes
|
|
16
|
+
whygit explain "fatal: refusing to merge unrelated histories"
|
|
17
|
+
git push 2>&1 | whygit explain -
|
|
18
|
+
whygit mcp run as an MCP server (for Claude Code, Cursor, Claude Desktop)
|
|
19
|
+
|
|
20
|
+
whygit only reads your repository. It never runs the fixes it suggests."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _common(p: argparse.ArgumentParser, suppress: bool) -> None:
|
|
24
|
+
d = argparse.SUPPRESS if suppress else None
|
|
25
|
+
p.add_argument(
|
|
26
|
+
"--path", "-C", default=d if suppress else ".", help="repository folder to look at (default: current folder)"
|
|
27
|
+
)
|
|
28
|
+
p.add_argument("--json", action="store_true", default=d if suppress else False, help="print JSON instead of text")
|
|
29
|
+
p.add_argument("--no-color", action="store_true", default=d if suppress else False, help="never use colour")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
33
|
+
parser = argparse.ArgumentParser(
|
|
34
|
+
prog="whygit",
|
|
35
|
+
description="Explains what state your Git repository is in and how to fix it, in plain English.",
|
|
36
|
+
epilog=EPILOG,
|
|
37
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument("--version", action="version", version=f"whygit {__version__}")
|
|
40
|
+
_common(parser, suppress=False)
|
|
41
|
+
sub = parser.add_subparsers(dest="command", metavar="command")
|
|
42
|
+
p = sub.add_parser("diagnose", help="list problems, most urgent first (the default)")
|
|
43
|
+
_common(p, suppress=True)
|
|
44
|
+
p = sub.add_parser("status", help="plain summary of the repository")
|
|
45
|
+
_common(p, suppress=True)
|
|
46
|
+
p = sub.add_parser("explain", help="explain a git error message ('-' reads it from stdin)")
|
|
47
|
+
p.add_argument("text", nargs="*", help="the error text, or - to read from stdin")
|
|
48
|
+
_common(p, suppress=True)
|
|
49
|
+
sub.add_parser("mcp", help="run the MCP server over stdio")
|
|
50
|
+
return parser
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _setup_stdout() -> None:
|
|
54
|
+
for stream in (sys.stdout, sys.stderr):
|
|
55
|
+
try:
|
|
56
|
+
stream.reconfigure(errors="replace")
|
|
57
|
+
except (AttributeError, ValueError):
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def main(argv: list[str] | None = None) -> int:
|
|
62
|
+
_setup_stdout()
|
|
63
|
+
args = build_parser().parse_args(argv)
|
|
64
|
+
if args.command == "mcp":
|
|
65
|
+
from .server import main as server_main
|
|
66
|
+
|
|
67
|
+
server_main()
|
|
68
|
+
return 0
|
|
69
|
+
style = Style(want_color(force_off=args.no_color or args.json))
|
|
70
|
+
try:
|
|
71
|
+
if args.command == "status":
|
|
72
|
+
res = explain_state(args.path)
|
|
73
|
+
_emit(res, args.json, lambda r: render_state(r, style))
|
|
74
|
+
return 0
|
|
75
|
+
if args.command == "explain":
|
|
76
|
+
text = " ".join(args.text)
|
|
77
|
+
if text.strip() in ("", "-"):
|
|
78
|
+
if sys.stdin is not None and sys.stdin.isatty():
|
|
79
|
+
print(
|
|
80
|
+
"Paste the error text, then press Ctrl-D (macOS/Linux) or Ctrl-Z then Enter (Windows):",
|
|
81
|
+
file=sys.stderr,
|
|
82
|
+
)
|
|
83
|
+
text = sys.stdin.read() if sys.stdin is not None else ""
|
|
84
|
+
if not text.strip():
|
|
85
|
+
print("whygit explain: no error text given.", file=sys.stderr)
|
|
86
|
+
return 2
|
|
87
|
+
res = explain_error(text, args.path)
|
|
88
|
+
_emit(res, args.json, lambda r: render_explanation(r, style))
|
|
89
|
+
return 0 if res.get("recognised") else 3
|
|
90
|
+
res = diagnose(args.path)
|
|
91
|
+
_emit(res, args.json, lambda r: render_diagnosis(r, style))
|
|
92
|
+
return 1 if any(f["severity"] == "blocking" for f in res["findings"]) else 0
|
|
93
|
+
except PathNotFound as exc:
|
|
94
|
+
print(
|
|
95
|
+
f"whygit: the folder {exc} does not exist. Use --path with your project folder, or cd into it first.",
|
|
96
|
+
file=sys.stderr,
|
|
97
|
+
)
|
|
98
|
+
return 2
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _emit(res: dict, as_json: bool, render) -> None:
|
|
102
|
+
if as_json:
|
|
103
|
+
print(json.dumps(res, indent=2, ensure_ascii=False))
|
|
104
|
+
else:
|
|
105
|
+
print(render(res))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
sys.exit(main())
|