3 #==============================================================================
5 # File ID: b3bc789e-fb2a-11e7-a332-f74d993421b0
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname
=ga-find-exist
19 while test -n "$1"; do
21 -h|
--help) opt_help
=1; shift ;;
22 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
23 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
24 --version) echo $progname $VERSION; exit 0 ;;
27 if printf '%s\n' "$1" |
grep -q ^
-; then
28 echo "$progname: $1: Unknown option" >&2
36 opt_verbose
=$
(($opt_verbose - $opt_quiet))
38 if test "$opt_help" = "1"; then
41 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
44 Usage: $progname [options] FILENAME
46 Go back in time in Git for a specific filename until FILENAME exists and
47 is not a broken symlink. Checks all earlier revisions where FILENAME was
48 modified. Abort if the git command fails.
50 Very suitable for git-annex, but can also be used with regular git. In
51 git-annex, it keeps scanning the history backwards until the symlink
52 isn't broken anymore. Can be used to find a reference file for rsync
53 transfers. If the files share common data, the transfer speed can be
54 increased dramatically. For example, transfer time for upgraded isofs
55 images can be reduced because not all files have changed, especially if
56 the files are stored in the same order as the previous version.
58 \$ $progname $exname # HEAD becomes detached if the file didn't exist
59 \$ git annex edit $exname
60 \$ rsync -avzL --progress user@remotehost:/path/to/$exname $exname
61 \$ git annex reinject --known $exname
62 \$ git checkout -f $exname # Was deleted by git annex reinject
63 \$ git checkout master
65 Returns 0 if FILENAME exists or it was found in the Git history.
66 Returns 1 if the git command failed or the file wasn't found.
73 Be more quiet. Can be repeated to increase silence.
75 Increase level of verbosity. Can be repeated.
77 Print version information.
85 if test -z "$file"; then
86 echo $progname: No
file specified
>&2
90 test -e "$file" && exit 0
92 shas
="$(git log --format=%h -- "$file")"
94 if test -z "$shas"; then
95 echo $progname: $file: File not found
in the Git
history >&2
99 test $opt_verbose -ge 1 && echo $progname: Checking revisions
$shas >&2
102 git checkout
$s ||
exit 1
103 test -e "$file" && exit 0
106 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :