Root/
| 1 | #!/bin/sh |
| 2 | # |
| 3 | # gitwhoareyounow - Trace the future of a file in git across renames |
| 4 | # |
| 5 | # Written 2010 by Werner Almesberger |
| 6 | # Copyright 2010 Werner Almesberger |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | |
| 14 | |
| 15 | usage() |
| 16 | { |
| 17 | cat <<EOF 2>&1 |
| 18 | usage: $0 repo-dir path |
| 19 | |
| 20 | The file to trace must be at repo-dir/path |
| 21 | The repo must be on a branch in the past of the current master. |
| 22 | EOF |
| 23 | exit 1 |
| 24 | } |
| 25 | |
| 26 | |
| 27 | if [ -z "$2" -o ! -z "$3" ]; then |
| 28 | usage |
| 29 | fi |
| 30 | |
| 31 | if [ ! -d "$1" -o ! -d "$1/.git" ]; then |
| 32 | echo "no git repository at $1" 1>&2 |
| 33 | exit 1 |
| 34 | fi |
| 35 | if [ ! -f "$1/$2" ]; then |
| 36 | echo "cannot find $2" 2>&1 |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | cd "$1" || exit |
| 41 | prev=`git rev-parse @{0}` |
| 42 | name=$2 |
| 43 | for n in `git rev-list --reverse ..master`; do |
| 44 | new=`git diff-tree --name-status -r -M $prev $n | |
| 45 | awk -F '\t' '$1~/^R/ && $2=="'"$name"'" { print $3 }'` |
| 46 | [ -z "$new" ] || name=$new |
| 47 | prev=$n |
| 48 | done |
| 49 | echo "$name" |
| 50 |
Branches:
master
