contrib / rerere-train.shon commit Merge branch 'js/mv-dir-to-new-directory' (2c44b7a)
   1#!/bin/sh
   2# Copyright (c) 2008, Nanako Shiraishi
   3# Prime rerere database from existing merge commits
   4
   5me=rerere-train
   6USAGE="$me rev-list-args"
   7
   8SUBDIRECTORY_OK=Yes
   9OPTIONS_SPEC=
  10. "$(git --exec-path)/git-sh-setup"
  11require_work_tree
  12cd_to_toplevel
  13
  14# Remember original branch
  15branch=$(git symbolic-ref -q HEAD) ||
  16original_HEAD=$(git rev-parse --verify HEAD) || {
  17        echo >&2 "Not on any branch and no commit yet?"
  18        exit 1
  19}
  20
  21mkdir -p "$GIT_DIR/rr-cache" || exit
  22
  23git rev-list --parents "$@" |
  24while read commit parent1 other_parents
  25do
  26        if test -z "$other_parents"
  27        then
  28                # Skip non-merges
  29                continue
  30        fi
  31        git checkout -q "$parent1^0"
  32        if git merge $other_parents >/dev/null 2>&1
  33        then
  34                # Cleanly merges
  35                continue
  36        fi
  37        if test -s "$GIT_DIR/MERGE_RR"
  38        then
  39                git show -s --pretty=format:"Learning from %h %s" "$commit"
  40                git rerere
  41                git checkout -q $commit -- .
  42                git rerere
  43        fi
  44        git reset -q --hard
  45done
  46
  47if test -z "$branch"
  48then
  49        git checkout "$original_HEAD"
  50else
  51        git checkout "${branch#refs/heads/}"
  52fi