Do show the top-level working dir.
[git-shortcuts.git] / git-merge-without-working
blob584b5fb000cf9396cbc089d664f4379d5b286b06
1 #!/bin/bash
3 set -e
5 usage() {
6 printf $"Usage: %s\n" "git merge-without-working REMOTE"
7 echo $"It merges the commit REMOTE with your current branch, advancing it, without touching your working dir."
8 echo $"It's useful for constructing the history (say, after an import from RCS) without loosing the current states of your files."
11 if [[ $# != 1 ]]; then
12 usage
13 exit 1
16 case "$1" in
17 -h|--help|--usage)
18 usage
19 exit 0
21 esac
23 # What to merge:
24 readonly REMOTE="$1"
26 readonly BASE="$(git merge-base HEAD "$REMOTE")" \
27 HEAD=
28 if [[ "$BASE" == "$(git rev-parse "$REMOTE")" ]]; then
29 echo $"Nothing to do."
30 elif [[ "$BASE" == "$(git rev-parse HEAD)" ]]; then
31 echo $"Fast-forward."
32 git update-ref HEAD "$(git rev-parse "$REMOTE")"
33 else
34 printf $"Merging %s ethereally.\n" "$REMOTE"
35 git read-tree -v -m -i "$BASE" HEAD "$REMOTE"
36 # The commit message is read from stdin.
37 git commit-tree "$(git write-tree)" -p HEAD -p "$REMOTE" \
38 | xargs git update-ref HEAD