Skip to content

Commit 49dd786

Browse files
committed
docs: add comprehensive troubleshooting guide for git-mit
1 parent ab4c1cd commit 49dd786

File tree

1 file changed

+356
-0
lines changed

1 file changed

+356
-0
lines changed

docs/troubleshooting.md

Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
# Troubleshooting git-mit
2+
3+
This guide will help you diagnose and fix common issues with git-mit.
4+
5+
## Authors and the `git mit` command
6+
7+
Something is up with authors, author discovery or similar
8+
9+
### Steps
10+
11+
1. **View all configured authors**:
12+
```bash,skip()
13+
git mit-config mit available
14+
```
15+
This shows all authors available to git-mit. See the [authors documentation](mit.md#configuring) for more details.
16+
17+
2. **Check where your authors file is located**:
18+
```bash,skip()
19+
echo $GIT_MIT_AUTHORS_CONFIG
20+
```
21+
If not set, git-mit uses the default location: `$HOME/.config/git-mit/mit.toml` (or `%APPDATA%\git-mit\mit.toml` on Windows)
22+
23+
3. **Verify your authors file exists**:
24+
```bash,skip()
25+
cat $HOME/.config/git-mit/mit.toml
26+
# Or if you have a custom location:
27+
cat $GIT_MIT_AUTHORS_CONFIG
28+
```
29+
30+
4. **Check Git's stored author configuration**:
31+
```bash,skip()
32+
git config --list | grep "^mit.author"
33+
```
34+
This shows authors stored in Git's config. Example output:
35+
```
36+
37+
mit.author.config.bt.name=Billie Thompson
38+
mit.author.config.bt.signingkey=0A46826A
39+
mit.author.expires=1747556921
40+
```
41+
42+
### Technical Details
43+
44+
git-mit loads authors from multiple sources and merges them together:
45+
46+
1. **From exec command** (highest priority):
47+
- Set via `--exec` flag or `GIT_MIT_AUTHORS_EXEC` environment variable
48+
- The command output must be valid TOML or YAML format
49+
- The command is executed using `shell_words::split()` for proper argument parsing
50+
51+
2. **From authors file**:
52+
- Default location: `$HOME/.config/git-mit/mit.toml`
53+
- Custom location via `--config` flag or `GIT_MIT_AUTHORS_CONFIG` environment variable
54+
- Special handling for `$HOME/.config/git-mit/mit.toml` path - it's expanded to the actual home directory
55+
- If the file doesn't exist, an empty string is used (no error)
56+
57+
3. **From Git config**:
58+
- Authors stored in `mit.author.config.<initial>.*` entries
59+
- These are set when you run `git mit-config mit set <initial> <name> <email>`
60+
- Stored at repository level (local) or user level (global) based on `--scope`
61+
62+
The authors from these sources are **merged together**, with later sources overriding earlier ones if there are conflicts.
63+
64+
For more information on configuring authors, see the [authors documentation](mit.md).
65+
66+
### Extending Author Configuration Timeout
67+
68+
By default, author configuration expires after 60 minutes, requiring you to run `git mit <initials>` again. If you find this timeout too short, you can extend it.
69+
70+
#### How the Timeout Works
71+
72+
- The timeout is stored as a Unix timestamp in `mit.author.expires`
73+
- When you run `git mit <initials>`, it sets the expiration to current time + timeout duration (in minutes)
74+
- The `pre-commit` hook checks if the current time is past this expiration
75+
- If expired, you'll see an error with the expiration time and need to run `git mit` again
76+
77+
Note: Setting very long timeouts reduces the benefit of the expiration feature, which ensures commit attribution stays current when developers change throughout the day.
78+
79+
#### Setting a Longer Timeout
80+
81+
1. **Using command-line flag**:
82+
```bash,skip()
83+
git mit --timeout 480 bt se
84+
```
85+
This sets the timeout to 480 minutes (8 hours).
86+
87+
2. **Using environment variable**:
88+
```bash,skip()
89+
export GIT_MIT_AUTHORS_TIMEOUT=480
90+
git mit bt se
91+
```
92+
Add this to your shell profile (`.bashrc`, `.zshrc`, etc.) to make it permanent.
93+
94+
3. **Check current expiration time**:
95+
```bash,skip()
96+
git config mit.author.expires
97+
```
98+
This shows the Unix timestamp when the current configuration expires.
99+
100+
## Hooks and `git mit-install` command
101+
102+
If co-authors aren't being added to commits or commit message validation isn't working:
103+
104+
### Verify Hook Installation
105+
106+
1. **Check if hooks are installed in your repository**:
107+
```bash,skip()
108+
ls -la .git/hooks/ | grep mit
109+
```
110+
You should see symbolic links for:
111+
- `commit-msg` → mit-commit-msg (or mit-commit-msg.exe on Windows)
112+
- `pre-commit` → mit-pre-commit (or mit-pre-commit.exe on Windows)
113+
- `prepare-commit-msg` → mit-prepare-commit-msg (or mit-prepare-commit-msg.exe on Windows)
114+
115+
2. **For global installations, check the template directory**:
116+
```bash,skip()
117+
git config --global init.templatedir
118+
```
119+
If this returns a path, check that directory contains the hooks:
120+
```bash,skip()
121+
ls -la $(git config --global init.templatedir)/hooks/
122+
```
123+
124+
3. **Verify hooks are executable**:
125+
```bash,skip()
126+
ls -la .git/hooks/ | grep mit
127+
```
128+
Look for `x` in the permissions (e.g., `-rwxr-xr-x`)
129+
130+
### Hook Installation Details
131+
132+
The installation process creates symbolic links to the git-mit binaries:
133+
134+
- **Windows**: Creates file symbolic links with `.exe` extension
135+
- **Unix/Linux/macOS**: Creates standard symbolic links
136+
- **Existing hooks**: Installation will fail if hooks already exist (unless they're already symlinks to git-mit)
137+
- **Symlink validation**: If a symlink exists but points to the correct binary, installation succeeds silently
138+
139+
### Reinstall Hooks
140+
141+
If hooks are missing or not working:
142+
143+
1. **For local installation** (installs in current repository only):
144+
```bash,skip()
145+
git mit-install
146+
```
147+
148+
2. **For global installation** (affects all new repositories):
149+
```bash,skip()
150+
git mit-install --scope=global
151+
```
152+
Then reinitialize existing repositories:
153+
```bash,skip()
154+
git init
155+
```
156+
157+
See the [installation documentation](binaries/git-mit-install.md) for more details.
158+
159+
### Test Hook Execution
160+
161+
1. **Test the pre-commit hook**:
162+
```bash,skip()
163+
# This should fail if no authors are set
164+
.git/hooks/pre-commit
165+
```
166+
See [`mit-pre-commit`](binaries/mit-pre-commit.md) for expected behavior.
167+
168+
2. **Test commit message validation**:
169+
```bash,skip()
170+
echo "test" > test-file.txt
171+
git add test-file.txt
172+
git commit -m "this is a commit message that is way too long and should definitely fail the 72 character limit check"
173+
```
174+
This should fail with an error about the subject being too long. See [`mit-commit-msg`](binaries/mit-commit-msg.md) for details.
175+
176+
## Lint Configuration Not Working
177+
178+
If lints aren't being applied as expected:
179+
180+
### Understanding Lint Configuration Precedence
181+
182+
Lints are loaded from multiple sources with TOML files taking precedence:
183+
184+
1. **TOML configuration files** (highest priority):
185+
- `.git-mit.toml` (takes precedence if exists)
186+
- `.git-mit.toml.dist` (used if `.git-mit.toml` doesn't exist)
187+
- Located by discovering the Git repository and checking the parent of `.git` directory
188+
- For bare repositories, checks the repository directory itself
189+
190+
2. **VCS configuration** (Git config - used if no TOML config exists):
191+
- Read from `mit.lint.<lint-name>` entries
192+
- Can be set with `git mit-config lint enable/disable <lint-name>`
193+
- Uses the lint's default enabled state if not explicitly configured
194+
195+
The TOML configuration uses this format:
196+
```toml,skip()
197+
[mit.lint]
198+
"lint-name" = true # or false
199+
```
200+
201+
### Debugging Lint Configuration
202+
203+
1. **Check current lint status**:
204+
```bash,skip()
205+
git mit-config lint status <lint-name>
206+
```
207+
208+
2. **Check for TOML config files**:
209+
```bash,skip()
210+
ls -la .git-mit.toml*
211+
```
212+
213+
3. **View Git config lint settings**:
214+
```bash,skip()
215+
git config --list | grep "^mit.lint"
216+
```
217+
218+
4. **Generate current configuration**:
219+
```bash,skip()
220+
git mit-config lint generate
221+
```
222+
This shows the effective configuration from all sources.
223+
224+
5. **Warning about TOML override**:
225+
When using `git mit-config lint enable/disable`, if a TOML file exists, you'll see:
226+
```
227+
Warning: your config is overridden by a repository config file
228+
```
229+
This reminds you that the TOML file takes precedence over Git config.
230+
231+
## Where Does git-mit Save Things?
232+
233+
Understanding where git-mit stores its data can help with troubleshooting:
234+
235+
### Author Configurations
236+
237+
1. **Authors file** (permanent storage):
238+
- Default location: `$HOME/.config/git-mit/mit.toml` (Linux/macOS) or `%APPDATA%\git-mit\mit.toml` (Windows)
239+
- Custom location: Set via `GIT_MIT_AUTHORS_CONFIG` environment variable
240+
- Format: TOML or YAML file containing author details
241+
- See [authors documentation](mit.md) for file format
242+
243+
2. **Git config** (permanent storage):
244+
- Stored in: `.git/config` (repository level) or `~/.gitconfig` (global)
245+
- Keys: `mit.author.config.<initial>.<field>` for author details
246+
- Set by: `git mit-config mit set [--scope=local|global] <initial> <name> <email>`
247+
248+
3. **Active author state** (temporary):
249+
- Stored in: `.git/config`
250+
- Keys: `user.name`, `user.email`, `user.signingkey`, `mit.author.coauthors.*`
251+
- Expires: Controlled by `mit.author.expires` timestamp
252+
- Set by: Running `git mit <initials>`
253+
254+
### Lint Configuration
255+
256+
1. **Repository level**:
257+
- File: `.git/config`
258+
- Keys: `mit.lint.<lint-name>`
259+
- Set by: `git mit-config lint enable/disable <lint-name>`
260+
261+
2. **Project level** (shared with team):
262+
- Files: `.git-mit.toml` or `.git-mit.toml.dist`
263+
- Example: Setting `not-conventional-commit = true` in `[mit.lint]` section
264+
- See [lint configuration documentation](lints/configuring.md)
265+
266+
### Relates-to Configuration
267+
268+
- Stored in: `.git/config`
269+
- Keys: `mit.relate.to` and `mit.relate.expires`
270+
- Template: `mit.relate.template` (for formatting the trailer)
271+
- Set by: `git mit-relates-to`
272+
- See [relates-to documentation](mit-relates-to.md)
273+
274+
### Hook Installation Locations
275+
276+
1. **Local installation** (`git mit-install` or `git mit-install --scope=local`):
277+
- Location: `.git/hooks/` in current repository
278+
- Creates symbolic links to the actual git-mit binaries
279+
280+
2. **Global installation** (`git mit-install --scope=global`):
281+
- Sets: `init.templatedir` in global Git config
282+
- Location: Template directory (e.g., `~/.config/git/init-template/hooks/`)
283+
- Applied to: New repositories when running `git init` or `git clone`
284+
285+
### git's Precedence of config files
286+
287+
git-mit uses libgit2 for Git interactions, which follows standard Git configuration precedence:
288+
289+
1. Repository config (`.git/config`) - highest priority
290+
2. User config (`~/.gitconfig`)
291+
3. System config (`/etc/gitconfig`) - lowest priority
292+
293+
### How git-mit Discovers git Configuration
294+
295+
The configuration discovery process:
296+
297+
1. **Repository discovery**: Uses `Repository::discover()` to find the Git repository
298+
2. **Config loading**: Opens the repository's config or falls back to [default config](https://libgit2.org/docs/reference/v0.22.1/config/git_config_open_default.html)
299+
3. **Author loading**: Reads from `mit.author.config.*` entries in Git config
300+
4. **Lint settings**: Reads from `mit.lint.*` entries and `.git-mit.toml` files
301+
5. **TOML file discovery**: Looks for `.git-mit.toml` first, then `.git-mit.toml.dist` in repository root
302+
303+
## Common Error Messages
304+
305+
### "failed to interact with git repository"
306+
307+
This usually means git-mit can't find or read the Git repository. Check:
308+
- You're in a Git repository (`git status` should work)
309+
- The `.git` directory has proper permissions
310+
- Your Git installation is working correctly
311+
312+
### "could not parse author configuration"
313+
314+
Your authors file has invalid TOML or YAML syntax. The error will show which format failed:
315+
- Check for missing quotes around strings
316+
- Ensure proper indentation (YAML is indent-sensitive)
317+
- Validate your file with a TOML/YAML validator
318+
- The error message will indicate whether it failed parsing as TOML or YAML
319+
320+
### "failed to install hook"
321+
322+
The hook installation failed because:
323+
- **ExistingHook**: A non-symlink hook already exists at that location
324+
- **ExistingSymlink**: A symlink exists but points to a different location
325+
- You don't have write permissions to the hooks directory
326+
327+
Remove the existing hook or check where the existing symlink points.
328+
329+
### "No authors set" (from pre-commit hook)
330+
331+
This error appears when:
332+
- You haven't run `git mit <initials>` to set the current authors
333+
- The author configuration has expired (check `git config mit.author.expires`)
334+
- The author configuration was never set in this repository
335+
336+
### "The details of the author of this commit are stale"
337+
338+
This error shows:
339+
- The exact time when the author configuration expired
340+
- You need to run `git mit <initials>` again to refresh the configuration
341+
342+
## Still Having Issues?
343+
344+
If you're still experiencing problems:
345+
346+
1. **Check for error messages**: Run git commands with verbose output
347+
2. **Verify Git version compatibility**: Ensure you're using a recent version of Git
348+
3. **Check for conflicting hook managers**: Other tools like Husky or pre-commit might interfere
349+
4. **File an issue**: Visit the [git-mit repository](https://github.com/PurpleBooth/git-mit) with details about your setup
350+
351+
For more help, consult:
352+
- [Installation guide](binaries/git-mit-install.md)
353+
- [Authors configuration](mit.md)
354+
- [Lint configuration](lints/configuring.md)
355+
- [Relates-to configuration](mit-relates-to.md)
356+
- [Hook documentation](binaries/mit-pre-commit.md)

0 commit comments

Comments
 (0)