11#! /usr/bin/env bash
2- # shellcheck disable=SC2312,SC2248,SC2250,SC2064,SC2086
2+ # shellcheck disable=SC2312
33#
44# Change files modification time to their last commit date
55#
3434if bash --help 2>&1 | grep -q -- ' --norc' ; then
3535 bash_opts=" ${bash_opts} --norc"
3636fi
37- # sanity check, not required:
38- if bash --help 2>&1 | grep -q -- ' --posix' ; then
39- bash_opts=" ${bash_opts} --posix"
40- fi
41-
42- prefix=" $( git rev-parse --show-prefix) "
43- strip=" ${# prefix} "
4437
4538status_opts=
4639whatchanged_opts=
@@ -55,16 +48,22 @@ if git status --help 2>&1 | grep -q -- "--ignored"; then
5548 status_opts=" ${status_opts} --ignored=no"
5649fi
5750
51+ prefix=" $( git rev-parse --show-prefix) "
52+ strip=" ${# prefix} "
53+
5854tmpfile=$( mktemp)
55+ # shellcheck disable=SC2064
5956trap " rm -f '${tmpfile} '" 0
6057
6158# prefix is stripped:
59+ # shellcheck disable=SC2086
6260git --no-pager status --porcelain --short ${status_opts} . |
6361 cut -c 4- > " ${tmpfile} "
6462
6563# prefix is not stripped:
64+ # shellcheck disable=SC1003,SC2086,SC2248
6665git --no-pager whatchanged ${whatchanged_opts} --format=' %ct' . |
67- awk $awk_flags \
66+ awk ${ awk_flags} \
6867 -F' \t' \
6968 -v date_flags=" ${date_flags} " \
7069 -v op=" ${op} " \
@@ -107,8 +106,13 @@ FILENAME==tmpfile {
107106 next
108107 }
109108 seen[$2]=1
110- # escape quotes:
111- gsub(/"/, "\\\"", $2)
112- printf("t %s \"%s\"\n", ct, $2)
109+ # remove double quotes and backslashes that git adds:
110+ if (substr($2, 1, 1) == "\"" && substr($2, length($2), 1) == "\"") {
111+ $2 = substr($2, 2, length($2) - 2)
112+ gsub(/\\/, "", $2)
113+ }
114+ # escape single quotes:
115+ gsub(/' \' ' /, "' \' ' \\' \' ' ' \' ' ", $2)
116+ printf("t %s ' \' ' %s' \' ' \n", ct, $2)
113117}
114118' " ${tmpfile} " - | BASH_ENV=' ' bash ${bash_opts} /dev/stdin
0 commit comments