aboutsummaryrefslogtreecommitdiff
path: root/doc/tips/automatically_adding_metadata/pre-commit-annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-04-17 16:10:20 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-04-17 16:10:20 -0400
commiteac99631a4ea103966b06af2cff1ea83b4f3192b (patch)
tree5a47f188fc8ec99a9f05030d4735c12b529ad807 /doc/tips/automatically_adding_metadata/pre-commit-annex
parent733b750f5d078deadb1a539ecfce8279d0dd905d (diff)
modify so the script can be run with existing annexed files to extract their metadata
Diffstat (limited to 'doc/tips/automatically_adding_metadata/pre-commit-annex')
-rwxr-xr-xdoc/tips/automatically_adding_metadata/pre-commit-annex24
1 files changed, 19 insertions, 5 deletions
diff --git a/doc/tips/automatically_adding_metadata/pre-commit-annex b/doc/tips/automatically_adding_metadata/pre-commit-annex
index f300bd731..fe818d032 100755
--- a/doc/tips/automatically_adding_metadata/pre-commit-annex
+++ b/doc/tips/automatically_adding_metadata/pre-commit-annex
@@ -1,6 +1,11 @@
#!/bin/sh
+#
# This script can be used to add git-annex metadata to files when they're
-# committed.
+# committed. It is typically installed as .git/hooks/pre-commit-annex
+#
+# You can also run this script by hand, passing it the names of files
+# already checked into git-annex, and it will extract/refresh the git-annex
+# metadata from the files.
#
# Copyright 2014 Joey Hess <id@joeyh.name>
# License: GPL-3+
@@ -12,8 +17,6 @@ if [ -z "$want" ]; then
exit 0
fi
-echo "$want"
-
case "$(git config --bool metadata.overwrite || true)" in
true)
overwrite=1
@@ -46,7 +49,8 @@ fi
IFS="
"
-for f in $(git diff-index --name-only --cached $against); do
+
+process () {
if [ -e "$f" ]; then
for l in $(extract "$f" | egrep "$want"); do
field="${l%% - *}"
@@ -54,4 +58,14 @@ for f in $(git diff-index --name-only --cached $against); do
addmeta "$f" "$field" "$value"
done
fi
-done
+}
+
+if [ -n "$*" ]; then
+ for f in $@; do
+ process "$f"
+ done
+else
+ for f in $(git diff-index --name-only --cached $against); do
+ process "$f"
+ done
+fi