summary refs log tree commit diff
path: root/bin/git-blame-from-line-number
blob: dbe197074ea1480ff9b3715bbb84dea66836e7f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh

usage() {
  echo "usage: $0 <filename> <lineno>"
  exit 1
}

filename="$1"

[ -z "${filename}" ] && usage

lineno="$2"

[ -z "${lineno}" ] && usage

line=$(git blame -L "${lineno}","${lineno}" "${filename}")
sha=$(echo $line | awk '{print $1}')

if [[ "${sha}" == "00000000" ]]; then
  echo "${line}"
else
  git show "${sha}"
fi