git-pincer 0.1.3
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.
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/bin/git-pincer.js +58 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zero <1143967454@qq.com>
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./assets/logo.gif" width="320" alt="git-pincer logo">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# git-pincer
|
|
6
|
+
|
|
7
|
+
[](https://github.com/zlx2019/git-pincer/actions/workflows/ci.yml)
|
|
8
|
+
[](https://crates.io/crates/git-pincer)
|
|
9
|
+
[](./LICENSE)
|
|
10
|
+
[](https://www.rust-lang.org)
|
|
11
|
+
|
|
12
|
+
**English** | [简体中文](./README.zh-CN.md)
|
|
13
|
+
|
|
14
|
+
> **"Pincer"** — a Git terminal tool written in Rust, focused on helping developers resolve code conflicts in Git merge, rebase, cherry-pick and similar scenarios with ease.
|
|
15
|
+
|
|
16
|
+
The name comes from Rust's mascot — the crab. A Git conflict is like two branches "pinching" the same piece of code at the same time, while a crab's pincer stands for stability, precision and control. May it work like a trusty pincer: gripping both sides of every conflict firmly, helping you understand the differences and complete the merge more efficiently.
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Three-pane merge UI** — local | result | remote, with chunk bands colored by change type using IDEA semantics: blue = modified, green = added, gray = deleted, red = conflict. Bands fade as chunks get resolved.
|
|
23
|
+
- **Precise diff rendering** — delta-style word-level emphasis inside changed chunks, plus syntax highlighting (Maple theme via syntect, selected by file extension, gracefully disabled for huge files).
|
|
24
|
+
- **Full flow takeover** — after all files are resolved it runs `git add` and the matching `--continue`, re-probes, and loops until the repository is clean. Multi-commit cherry-picks and multi-round rebases just work.
|
|
25
|
+
- **RPG-style action menu** — running bare `git-pincer` in a clean repository opens a pixel-art menu with a status window that maps your repository to character vitals (Lv. = commit count, HP = uncommitted changes, MP = stashes, EXP = commits ahead). Pick an action, then a branch (merge / rebase) or a commit (cherry-pick / revert); success and failure both pop an in-TUI dialog and return to the menu — no flicker, no exit.
|
|
26
|
+
- **Broad conflict-source support** — merge, rebase, pull, cherry-pick, revert, `git am`, and even flows without a `--continue` such as `stash pop`, `checkout -m` or `apply --3way`.
|
|
27
|
+
- **Native git, zero magic** — everything shells out to your git binary (the same route lazygit and IDEA take), so credentials, hooks, merge strategies and rerere all follow your existing configuration. Arguments are passed as arrays (no shell, no injection), and host `GIT_DIR`-style variables are scrubbed so nested invocations from hooks cannot hijack the wrong repository.
|
|
28
|
+
- **Terminal-aware theming** — dark (Tokyo Night) and light (Maple Light) themes via `--theme <auto|dark|light>`, `COLORFGBG` auto-detection, and automatic xterm-256 quantization on terminals without truecolor support.
|
|
29
|
+
- **Bilingual UI** — every menu, hint and message ships in both English and Chinese; `--lang <auto|zh|en>` with `auto` following the system locale. Messages live in `locales/*.conf` and are embedded at compile time — still a single binary.
|
|
30
|
+
- **Sensible fallbacks** — binary conflicts degrade to whole-file pick-one; a git-free `file` mode parses conflict markers directly; non-TTY invocations fail with a readable message instead of a panic.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Requires `git` on your `PATH`.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
cargo install git-pincer
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Prebuilt binaries for major platforms are also attached to [GitHub Releases](https://github.com/zlx2019/git-pincer/releases). To build from source (Rust 1.96+):
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cargo install --git https://github.com/zlx2019/git-pincer
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git-pincer # conflicts present: take over and resolve them
|
|
50
|
+
# clean repo: open the interactive action menu
|
|
51
|
+
git-pincer merge <branch> # run git merge, resolve conflicts if any
|
|
52
|
+
git-pincer rebase <branch> # run git rebase, looping through every conflicted commit
|
|
53
|
+
git-pincer pull origin main # arguments are passed straight to git pull
|
|
54
|
+
git-pincer cherry-pick <commit> # multiple commits / options are passed through
|
|
55
|
+
git-pincer revert <commit> # run git revert and take over the conflicts
|
|
56
|
+
git-pincer file conflict.txt # git-free: parse a conflict-marked file, write it back
|
|
57
|
+
git-pincer abort # abort the operation in progress (with confirmation)
|
|
58
|
+
git-pincer completions zsh # shell completion script (bash/zsh/fish/powershell/elvish)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Tab completion needs a one-time hook into your shell:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# zsh
|
|
65
|
+
echo 'eval "$(git-pincer completions zsh)"' >> ~/.zshrc
|
|
66
|
+
# bash
|
|
67
|
+
echo 'eval "$(git-pincer completions bash)"' >> ~/.bashrc
|
|
68
|
+
# fish
|
|
69
|
+
git-pincer completions fish > ~/.config/fish/completions/git-pincer.fish
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Global options:
|
|
73
|
+
|
|
74
|
+
| Option | Description |
|
|
75
|
+
| ------ | ----------- |
|
|
76
|
+
| `-C, --repo <PATH>` | Operate on the repository at `PATH` (defaults to the current directory) |
|
|
77
|
+
| `--theme <auto\|dark\|light>` | UI theme; `auto` inspects `COLORFGBG` and falls back to dark |
|
|
78
|
+
| `--lang <auto\|zh\|en>` | UI language; `auto` follows the system locale (Chinese locales get Chinese, everything else English) |
|
|
79
|
+
| `-v, --verbose` | Echo every git command being executed |
|
|
80
|
+
|
|
81
|
+
### Configuration
|
|
82
|
+
|
|
83
|
+
An optional config file is read from `~/.config/git-pincer/config.toml` (`$XDG_CONFIG_HOME` is respected; `%APPDATA%\git-pincer\config.toml` on Windows; the `GIT_PINCER_CONFIG` env var overrides the path entirely). CLI flags always take precedence. A missing file just means defaults; a malformed one fails fast with a readable error.
|
|
84
|
+
|
|
85
|
+
```toml
|
|
86
|
+
[ui] # defaults for the global options above
|
|
87
|
+
theme = "auto" # auto | dark | light
|
|
88
|
+
lang = "auto" # auto | zh | en
|
|
89
|
+
verbose = false
|
|
90
|
+
editor = "nvim" # editor for the e key; falls back to $VISUAL > $EDITOR > vim > vi (notepad on Windows)
|
|
91
|
+
|
|
92
|
+
[keys] # rebind actions — replaces all default keys of that action
|
|
93
|
+
take-local = "o"
|
|
94
|
+
write = "ctrl+s" # modifiers: ctrl+ / alt+ / shift+; named keys: left, up, tab, enter, space, f1-f12…
|
|
95
|
+
|
|
96
|
+
[theme.dark] # override any color by name (same table exists as [theme.light])
|
|
97
|
+
rpg_accent = "#ff7a2f"
|
|
98
|
+
band_conflict = ["#3a1e22", "#5e2d35"] # band_* / emph_* colors take a [normal, selected] pair
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Rebindable actions: `take-local`, `take-remote`, `ignore`, `undo`, `undo-file`, `edit`, `apply-all`, `next-change`, `prev-change`, `next-conflict`, `prev-conflict`, `copy-chunk`, `copy-file`, `copy-local`, `copy-remote`, `write`, `next-file`, `fold`, `quit`, `help`. Overridden keys show up in the hint bar and help overlay automatically. Unknown action names, key conflicts and invalid colors are rejected at startup with the full list of valid values.
|
|
102
|
+
|
|
103
|
+
Try the TUI without a git repository:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
cp fixtures/conflict.txt /tmp/ && git-pincer file /tmp/conflict.txt
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Keybindings
|
|
110
|
+
|
|
111
|
+
| Key | Action |
|
|
112
|
+
| --- | ------ |
|
|
113
|
+
| `h` / `←` | Take the local side (taking both sides of a conflict in order keeps both) |
|
|
114
|
+
| `l` / `→` | Take the remote side |
|
|
115
|
+
| `x` | Ignore the remaining pending sides of the current chunk (keep base) |
|
|
116
|
+
| `u` | Undo all decisions on the current chunk |
|
|
117
|
+
| `U` | Undo all decisions in the current file |
|
|
118
|
+
| `e` | Edit the current chunk in `$EDITOR` |
|
|
119
|
+
| `a` | Apply every non-conflicting change at once |
|
|
120
|
+
| `j` / `k` | Move to the next / previous change chunk |
|
|
121
|
+
| `n` / `p` | Jump to the next / previous unresolved conflict |
|
|
122
|
+
| `Ctrl+d` / `Ctrl+u` | Scroll the viewport half a page down / up (navigation keys re-attach it to the cursor) |
|
|
123
|
+
| `y` / `Y` | Copy the current chunk result / the whole file result |
|
|
124
|
+
| `H` / `L` | Copy the local / remote side of the current chunk |
|
|
125
|
+
| `w` | Write the file (auto-applies remaining non-conflict changes, then `git add`) |
|
|
126
|
+
| `Tab` | Switch to the next file |
|
|
127
|
+
| `z` | Fold / unfold unchanged regions |
|
|
128
|
+
| `q` | Quit (press twice if files are unfinished; the scene is kept) |
|
|
129
|
+
| `?` | Show the full key reference |
|
|
130
|
+
|
|
131
|
+
### Supported conflict sources
|
|
132
|
+
|
|
133
|
+
| Source | Detected via | Finished with |
|
|
134
|
+
| ------ | ------------ | ------------- |
|
|
135
|
+
| `git merge` / `git pull` | `MERGE_HEAD` | `git merge --continue` |
|
|
136
|
+
| `git rebase` | `rebase-merge` / `rebase-apply` | `git rebase --continue` (multi-round) |
|
|
137
|
+
| `git cherry-pick` | `CHERRY_PICK_HEAD` | `git cherry-pick --continue` (multi-round) |
|
|
138
|
+
| `git revert` | `REVERT_HEAD` | `git revert --continue` |
|
|
139
|
+
| `git am -3` | `rebase-apply/applying` | `git am --continue` |
|
|
140
|
+
| `stash pop` / `checkout -m` / `apply --3way` | unmerged index entries only | nothing to continue — resolving is enough |
|
|
141
|
+
|
|
142
|
+
## How it works
|
|
143
|
+
|
|
144
|
+
- **diff3 core** — two 2-way diffs (base→ours, base→theirs, Myers algorithm with a 500 ms timeout guard) are grouped by base-range collisions into chunks: stable, one-sided, agreed, or conflicting. The grouping is deliberately conservative: reporting one conflict too many beats merging something silently wrong.
|
|
145
|
+
- **Pure-logic session** — every chunk side is pending / applied / ignored; take order defines how content is stitched together, and `$EDITOR` edits override a chunk wholesale. Files containing NUL bytes degrade to a whole-file binary choice.
|
|
146
|
+
- **Thin git wrapper** — conflict contents are read from index stages 1/2/3; writes go through `git add`; repository state (merge / rebase / cherry-pick / revert / am) is probed from the git directory so the right `--continue` is always used.
|
|
147
|
+
|
|
148
|
+
## Development
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
cargo nextest run --all-features --no-tests pass # tests
|
|
152
|
+
cargo clippy --all-targets --all-features -- -D warnings
|
|
153
|
+
cargo fmt --all -- --check
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for the toolchain setup, pre-commit hooks and commit conventions.
|
|
157
|
+
|
|
158
|
+
## Acknowledgements
|
|
159
|
+
|
|
160
|
+
Built with [ratatui](https://github.com/ratatui/ratatui), [similar](https://github.com/mitsuhiko/similar), [syntect](https://github.com/trishume/syntect) and [clap](https://github.com/clap-rs/clap). Visual design inspired by the IntelliJ IDEA merge tool, [delta](https://github.com/dandavison/delta) and [lazygit](https://github.com/jesseduffield/lazygit).
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
Distributed under the [MIT](./LICENSE) license.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// git-pincer 的 npm 启动垫片:
|
|
5
|
+
// 按当前平台定位 optionalDependencies 里对应的二进制子包, 并把参数原样转发给它。
|
|
6
|
+
|
|
7
|
+
const { spawnSync } = require("node:child_process");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
|
|
10
|
+
// 判断 Linux 是否为 musl 环境(运行时报告中没有 glibc 版本信息即视为 musl)
|
|
11
|
+
function isMusl() {
|
|
12
|
+
try {
|
|
13
|
+
return !process.report.getReport().header.glibcVersionRuntime;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 根据平台与架构推导对应的二进制子包名, 不支持的平台返回 null
|
|
20
|
+
function platformPackage() {
|
|
21
|
+
const { platform, arch } = process;
|
|
22
|
+
if (platform === "darwin" && arch === "arm64") return "@zero9501/git-pincer-darwin-arm64";
|
|
23
|
+
if (platform === "darwin" && arch === "x64") return "@zero9501/git-pincer-darwin-x64";
|
|
24
|
+
if (platform === "linux" && arch === "arm64") return "@zero9501/git-pincer-linux-arm64-gnu";
|
|
25
|
+
if (platform === "linux" && arch === "x64") {
|
|
26
|
+
return isMusl() ? "@zero9501/git-pincer-linux-x64-musl" : "@zero9501/git-pincer-linux-x64-gnu";
|
|
27
|
+
}
|
|
28
|
+
if (platform === "win32" && arch === "x64") return "@zero9501/git-pincer-win32-x64";
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 定位子包内的可执行文件绝对路径, 失败时输出指引并退出
|
|
33
|
+
function binaryPath() {
|
|
34
|
+
const pkg = platformPackage();
|
|
35
|
+
if (!pkg) {
|
|
36
|
+
console.error(`[git-pincer] unsupported platform: ${process.platform}-${process.arch}`);
|
|
37
|
+
console.error("[git-pincer] see https://github.com/zlx2019/git-pincer#installation for other install options");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const exe = process.platform === "win32" ? "git-pincer.exe" : "git-pincer";
|
|
41
|
+
try {
|
|
42
|
+
return path.join(path.dirname(require.resolve(`${pkg}/package.json`)), "bin", exe);
|
|
43
|
+
} catch {
|
|
44
|
+
console.error(`[git-pincer] platform package ${pkg} is missing; try reinstalling git-pincer`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const result = spawnSync(binaryPath(), process.argv.slice(2), { stdio: "inherit" });
|
|
50
|
+
if (result.error) {
|
|
51
|
+
console.error(`[git-pincer] failed to launch binary: ${result.error.message}`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
if (result.signal) {
|
|
55
|
+
// 被信号终止时对自身重放同一信号, 让退出码符合 shell 约定(128+N)
|
|
56
|
+
process.kill(process.pid, result.signal);
|
|
57
|
+
}
|
|
58
|
+
process.exit(result.status ?? 1);
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "git-pincer",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "A simple and efficient terminal Git conflict resolution CLI tool.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"git",
|
|
7
|
+
"merge",
|
|
8
|
+
"conflict",
|
|
9
|
+
"diff3",
|
|
10
|
+
"tui",
|
|
11
|
+
"cli"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/zlx2019/git-pincer",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/zlx2019/git-pincer.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Zero <1143967454@qq.com>",
|
|
20
|
+
"bin": {
|
|
21
|
+
"git-pincer": "bin/git-pincer.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=16"
|
|
28
|
+
},
|
|
29
|
+
"optionalDependencies": {
|
|
30
|
+
"@zero9501/git-pincer-darwin-arm64": "0.1.3",
|
|
31
|
+
"@zero9501/git-pincer-darwin-x64": "0.1.3",
|
|
32
|
+
"@zero9501/git-pincer-linux-arm64-gnu": "0.1.3",
|
|
33
|
+
"@zero9501/git-pincer-linux-x64-gnu": "0.1.3",
|
|
34
|
+
"@zero9501/git-pincer-linux-x64-musl": "0.1.3",
|
|
35
|
+
"@zero9501/git-pincer-win32-x64": "0.1.3"
|
|
36
|
+
}
|
|
37
|
+
}
|