Root/schhist/gitwhoareyounow

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
15usage()
16{
17    cat <<EOF 2>&1
18usage: $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.
22EOF
23    exit 1
24}
25
26
27if [ -z "$2" -o ! -z "$3" ]; then
28    usage
29fi
30
31if [ ! -d "$1" -o ! -d "$1/.git" ]; then
32    echo "no git repository at $1" 1>&2
33    exit 1
34fi
35if [ ! -f "$1/$2" ]; then
36    echo "cannot find $2" 2>&1
37    exit 1
38fi
39
40cd "$1" || exit
41prev=`git rev-parse @{0}`
42name=$2
43for 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
48done
49echo "$name"
50

Archive Download this file

Branches:
master



interactive