#!/bin/bash # Here's an improved version of `pacify2.sh` in the style of `hello.sh`, including a `-c` option to remove extra files using the `move-rubbish` tool: # [-c] [file ...] # Pacify Git merge conflicts set -e -u -o pipefail pacify() { local c=0 # Flag to clean up extra files . opts if [ "$c" = 1 ]; then cleanup_files exit fi local -a files if [ $# -eq 0 ]; then readarray -t files < <(conflicts) else files=("$@") fi set -o noclobber for file in "${files[@]}"; do printf "%s\n" "$file" git show :1:"$file" > "$file.base" || true git show :2:"$file" > "$file.ours" || true git show :3:"$file" > "$file.theirs" || true yes n | cp -a -i "$file" "$file.conflict" || return 1 if [ -f "$file.ours" ]; then cp "$file.ours" "$file" elif [ -f "$file.base" ]; then cp "$file.base" "$file" fi done } cleanup_files() { local extra_files=(*.base *.ours *.theirs *.conflict) if [ ${#extra_files[@]} -gt 0 ]; then printf "Cleaning up extra files...\n" for file in "${extra_files[@]}"; do if [ -f "$file" ]; then move-rubbish "$file" fi done fi } if [ "$BASH_SOURCE" = "$0" ]; then pacify "$@" fi