summaryrefslogtreecommitdiff
path: root/git-keep
diff options
context:
space:
mode:
Diffstat (limited to 'git-keep')
-rwxr-xr-xgit-keep34
1 files changed, 34 insertions, 0 deletions
diff --git a/git-keep b/git-keep
new file mode 100755
index 0000000..4f5ab29
--- /dev/null
+++ b/git-keep
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# @describe Keep your changes or incoming changes during merge/rebase conflicts
+# @meta version 1.0.0
+# @meta require-tools git
+
+is_rebase() {
+ [ -d "$(git rev-parse --git-path rebase-merge 2>/dev/null)" ] || [ -d "$(git rev-parse --git-path rebase-apply 2>/dev/null)" ]
+}
+
+do_keep() {
+ local ours="$1" theirs="$2"
+ shift 2
+ if is_rebase; then
+ git checkout --"$theirs" "$@"
+ else
+ git checkout --"$ours" "$@"
+ fi
+ git add "$@"
+}
+
+# @cmd Keep your current branch changes for specified files
+mine() {
+ do_keep "ours" "theirs" "${@:-.}"
+}
+
+# @cmd Keep incoming branch changes for specified files
+incoming() {
+ do_keep "theirs" "ours" "${@:-.}"
+}
+
+eval "$(argc --argc-eval "$0" "$@")"