Skip to content

Commit 2f8c5f6

Browse files
committed
feat: add resolve cmd
1 parent 967e339 commit 2f8c5f6

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Commands.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
- [`git rename-remote`](#git-rename-remote)
5959
- [`git repl`](#git-repl)
6060
- [`git reset-file`](#git-reset-file)
61+
- [`git resolve`](#git-resolve)
6162
- [`git root`](#git-root)
6263
- [`git rscp`](#git-scp)
6364
- [`git scp`](#git-scp)
@@ -1402,6 +1403,16 @@ or reset one file to certain commit
14021403
$ git reset-file .htaccess dc82b19
14031404
```
14041405
1406+
## git resolve
1407+
1408+
On default text-editor, open unmerged ("both modified" `status`) files in working-directory that have errors (e.g. conflict-markers),
1409+
then auto-stage all (in full work-tree) unmerged files without errors,
1410+
and finally [`continue`](#git-continue) (if possible).
1411+
1412+
```bash
1413+
$ git resolve
1414+
```
1415+
14051416
## git mr
14061417
14071418
Checks out a merge request from GitLab. Usage: `git mr <ID|URL> [REMOTE]`.

bin/git-resolve

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -eufo pipefail
3+
IFS=$' \t'
4+
5+
#shellcheck disable=SC2046
6+
# ignore files outside WD, to avoid overload
7+
git diff --name-only --diff-filter=U --relative -z |
8+
while IFS= read -r -d '' f; do
9+
# `--quiet` implies `--exit-code` which is incompatible with `--check`;
10+
# however, it could be special-cased internally, so it could work
11+
# (untested)
12+
if ! git diff --check -- "$f" &>/dev/null; then
13+
printf '%s\0' "$f"
14+
fi
15+
done |
16+
# WARN: `-r` is too new
17+
# https://github.com/tj/git-extras/pull/1233#issuecomment-3957233996
18+
xargs -0r $(git var GIT_EDITOR)
19+
20+
# user might have removed other conflict-markers,
21+
# so check full WT
22+
git diff --name-only --diff-filter=U -z |
23+
while IFS= read -r -d '' f; do
24+
# WARN: `f` is relative to repo root!
25+
# this might be broken
26+
if git diff --check -- "$f"; then
27+
git add -- "$f"
28+
fi
29+
done
30+
31+
git continue

0 commit comments

Comments
 (0)