3 #=======================================================================
5 # File ID: e89047ce-29d1-11e2-bb6f-00c0a8deee11
7 # Customised frontend to git-annex
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
16 if test "$1" = "--version"; then
17 echo $progname $VERSION
21 if test "$1" = "-h" -o "$1" = "--help"; then
24 Customised frontend to git-annex.
26 Usage: $progname [options] git-annex_commands_and_options
28 The following commands (first non-option on the command line) are
32 Verify the file contents with ga-key(1) against the key stored in
33 the symlink. Only supports SHA256 for now.
35 Like "git annex numcopies", but always return a number. If numcopies
36 is not defined, return 1.
38 Filter the output through ga-fsck-size, calculates how much space is
39 needed to get enough file copies.
41 If annex.uuid isn't already defined, initialise annex.uuid with an
42 UUID v1 (time-based UUID) instead of v4 (random-based). This is done
43 before executing an ordinary "git annex init". If a description is
44 provided on the command line after the "init" command, use that, or
45 set the description to the value of the ga.description Git config
46 variable if it exists. Otherwise use the output from the "ga-pwd"
47 command. The script will abort if annex.uuid is already defined.
48 Also, if any other command than init is executed and annex.uuid
49 doesn't exist, the script aborts. This is to make sure no git-annex
50 setup is done in non-annex repositories.
51 max-bytes SIZE COMMAND
52 Execute git-annex with a modified annex.diskreserve locally so the
53 local free annex space seems to be SIZE. This can be used to for
54 example move maximum SIZE bytes from another repo to the local one:
55 ga max-bytes 1000000 move --from exthd --not --in here
56 will move at most 1 megabyte from the exthd remote. Note that
57 because it uses the annex.diskreserve Git config variable as a
58 workaround, it will be affected if the actual disk space changes. It
59 works best when there's no other activity on the local disk going
62 Shortcut for "metadata".
64 Shortcut for "ga sync --no-push".
66 If the Git config variable annex.autocommit is not "false", execute
67 "git wait-until-clean -u" before syncing, i.e., wait until the
68 repository is clean before continuing. This is to avoid any
70 Run "git-annex merge" before sync to get local modifications in
71 place in case "git-annex sync" doesn't do it properly.
72 Also, update all local synced/* branches by running "git pa -s". If
73 you have a Git-aware command line prompt that shows if the current
74 branch is behind or ahead upstream, it will show when a sync or
77 Shortcut for "update-desc".
79 Filter the output through ga-sumsize, display total number of bytes
82 Update the git-annex description, use the generic output from
83 ga-pwd. For example, the output for the current directory is
85 If the git config key ga.description is defined, that value is used
86 instead. This can be used if some repos have to be called something
87 else than what the ga-pwd value says.
89 After all this, it disables "git annex pre-commit ." in
90 .git/hooks/pre-commit if it's not already disabled. This is to avoid an
91 automatic "git annex fix" that automatically fixes broken symlinks
92 before commit. It makes it hard to track file renames, as it breaks "git
93 log --follow" and friends.
100 Print version information.
107 df
-B 1 -P . |
tail -1 |
tr -s ' ' | cut
-f 4 -d ' ' |
tr -d '\n'
110 if test "$1" = "init"; then
111 if test -z "$(git config --get annex.uuid)"; then
112 git config annex.uuid $
(suuid
-wa -t ga_init
)
114 if test -n "$1"; then
116 elif test -n "$(git config --get ga.description)"; then
117 git-annex init
"$(git config --get ga.description)"
119 git-annex init
"$(ga-pwd)"
123 echo $progname: Repository is already initialised
for git-annex
>&2
127 if test -z "$(git config --get annex.uuid)"; then
128 echo $progname: annex.uuid is not defined
, aborting
>&2
133 # Check that "git annex pre-commit ." is commented out in
134 # .git/hooks/pre-commit, I don't want to let "git commit" run "git annex
135 # fix" automatically when I've moved files around. I want to be able to
136 # track moves, and it breaks "git log --follow". If it's not disabled,
137 # do it automatically.
138 precommit
="$(git rev-parse --show-toplevel)/.git/hooks/pre-commit"
139 if test -f "$precommit"; then
140 grep -q '^git.*annex.*pre-commit' "$precommit" && {
141 perl
-p -i -e 's/^(git.annex.+pre-commit)/# $1/' "$precommit"
142 echo $progname: $precommit: Have disabled git annex pre-commit
: >&2
148 sha256key_regexp
='/SHA256-s[0-9]+--[0-9a-f]{64}$'
150 if test "$1" = "chk"; then
153 if test -L "$f" -a -d "$f"; then
154 echo $progname: $f: Is a symlink to a directory
>&2
157 if test -d "$f"; then
158 echo $progname: $f: Is a directory
>&2
161 if test -L "$f" -a ! -e "$f"; then
162 if readlink
"$f" |
grep -Eq $sha256key_regexp; then
163 echo $progname: $f: File not present here
>&2
165 echo $progname: $f: Broken symlink
>&2
169 if test ! -e "$f"; then
170 echo $progname: $f: File not found
>&2
174 if test ! -L "$f"; then
175 echo $progname: $f: Not a symbolic link
>&2
178 if ! readlink
"$f" |
grep -Eq $sha256key_regexp; then
179 echo $progname: $f: SHA256 key not found
in symlink
>&2
182 if test ! -r "$f"; then
183 echo $progname: $f: File is not readable by you
>&2
189 readlink
"$f" |
grep -q $key && echo ok ||
{ echo fail
; exitval
=1; }
192 elif test "$1" = "copnum"; then
193 if test -n "$(ga numcopies | grep "is not
set")"; then
198 elif test "$1" = "fsck"; then
200 git-annex fsck
"$@" 2>&1 | ga-fsck-size
201 elif test "$1" = "max-bytes"; then
203 if test -z "$maxbytes"; then
204 echo $progname: max-bytes needs an integer argument
>&2
208 git-annex
"$@" -c annex.diskreserve
=$
(echo $
(disk_free
)-$maxbytes |
bc)
209 elif test "$1" = "md"; then
211 git-annex metadata
"$@"
212 elif test "$1" = "snp"; then
214 ga sync
--no-push "$@"
215 elif test "$1" = "sync"; then
216 if test "$(git config --get annex.autocommit)" != "false"; then
217 git wait-until-clean
-u
222 elif test "$1" = "unused"; then
224 git-annex unused
"$@" | ga-sumsize
225 elif test "$1" = "update-desc" -o "$1" = "ud"; then
226 toplevel
="$(git rev-parse --show-toplevel)"
228 echo $progname update-desc
: $toplevel: Cannot change to directory
>&2
231 description
="$(git config --get ga.description)"
232 if test -n "$description"; then
237 repouuid
="$(git config --get annex.uuid)"
238 if test -z "$repouuid"; then
239 echo $progname: annex.uuid is empty
, seems as it is not an annex
>&2
242 info_line
="$(ga info --fast | grep $repouuid)"
244 # FIXME: The regexp is relaxed here because some suspicious
245 # behaviour from git-annex, it places remotes there. They're also in
246 # the JSON output, so it looks like a bug. — Sønnyen, 2016-04-29
247 echo "$info_line" |
grep -q " -- $here .*\\[here\\]" && found_it
=1
248 if test "$found_it" = "1"; then
249 echo $progname: Description looks ok
, not changing it
>&2
253 sess
-- ga describe here
"$here"
256 echo $progname update-desc
: Before
: $info_line >&2
257 echo $progname update-desc
: After
: $
(
258 ga info
--fast |
grep $repouuid