Root/scripts/gitenealogy

Source at commit d7d95ff2da07c37cd95d5466d7cd2b775c771ec8 created 13 years 7 months ago.
By Werner Almesberger, Allow schhist2web and friends to run from a directory outside the working tree.
1#!/bin/sh
2#
3# gitenealogy - Trace the ancestry 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
21EOF
22    exit 1
23}
24
25
26if [ -z "$2" -o ! -z "$3" ]; then
27    usage
28fi
29
30if [ ! -d "$1" -o ! -d "$1/.git" ]; then
31    echo "no git repository at $1" 1>&2
32    exit 1
33fi
34if [ ! -f "$1/$2" ]; then
35    echo "cannot find $2" 2>&1
36    exit 1
37fi
38
39cd "$1" || exit
40git log --follow --name-status "$2" |
41    awk '
42/^commit /{ if (c) print c, n; c = $2 }
43{ if (NF) n = $(NF) }
44END { if (c) print c, n; }'
45

Archive Download this file



interactive