blob: 23f057b45fa6e5287823a280db2601075f276f55 [file] [log] [blame]
James Tuckerec997f12019-02-01 15:34:13 -08001#!/usr/bin/env bash
2# Copyright 2019 The Fuchsia Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6usage() {
7 cat <<EOF
8git follow-log -h
9 print help
10git follow-log <path> [<git-log options>]
11 produce git-log output for all objects under <path>
12 additional options for git-log can be provided later. only a subset
13 of git-log options will work.
14EOF
15 exit 1
16}
17
18git_follow_log() {
19 test $# -eq 0 && usage
20 while [ $# -gt 0 ]; do
21 arg="$1"
22 case "$arg" in
23 -h|--help|help)
24 usage
25 ;;
26 *)
27 if [ "$have_path" == true ]; then
28 args+=("$arg")
29 else
30 have_path=true
31 path="$arg"
32 fi
33 ;;
34 esac
35 shift
36 done
37 for p in $(git log --name-only --pretty=format: "$path" | sort -u); do
38 git --no-pager log --follow --no-abbrev-commit --format=%H -- ":(top)$p"
39 done | git log --stdin --no-walk=sorted "$@"
40}
41
42git_follow_log "$@"