| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -eu |
| 4 |
|
| 5 |
export PS4='> ' |
| 6 |
# set -x |
| 7 |
|
| 8 |
function info () { |
| 9 |
echo "INFO: $*" |
| 10 |
} |
| 11 |
|
| 12 |
function error() { |
| 13 |
echo "ERROR: $1" >&2 |
| 14 |
exit "${2:-1}" |
| 15 |
} |
| 16 |
|
| 17 |
function fsck() { |
| 18 |
info "FSCKing" |
| 19 |
git annex fsck --fast -q |
| 20 |
} |
| 21 |
|
| 22 |
function check_clean() { |
| 23 |
info "Checking if all clean" |
| 24 |
git diff --quiet --exit-code --ignore-submodules && git diff --exit-code --ignore-submodules --cached --quiet |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
if $(git config --global annex.autoupgraderepository) != false; then |
| 29 |
error "Please disable auto upgrades first" |
| 30 |
fi |
| 31 |
|
| 32 |
cd "${1:-.}" |
| 33 |
|
| 34 |
annex_version=$(git annex version | awk -e '/^git-annex version:/{print $3}') |
| 35 |
case "$annex_version" in |
| 36 |
5.*|6.*|7.*) info "git-annex $annex_version . Good, proceeding";; |
| 37 |
*) error "git-annex $annex_version . Please downgrade to proceed";; |
| 38 |
esac |
| 39 |
|
| 40 |
repo_annex_version=$(git config annex.version) |
| 41 |
case "$repo_annex_version" in |
| 42 |
5) echo "you are good - already version $repo_annex_version"; exit 0;; |
| 43 |
8) ;; |
| 44 |
*) error "do not know how to downgrade $repo_annex_version, fix me" |
| 45 |
esac |
| 46 |
|
| 47 |
# needs recent annex |
| 48 |
# unlocked=( $(git annex find --unlocked) ) |
| 49 |
unlocked=( $(git grep -l -a --no-textconv --cached '^/annex/objects/' || :) ) |
| 50 |
if [ "${#unlocked[*]}" -ge 1 ]; then |
| 51 |
error "Found ${#unlocked[*]} unlocked files. Cannot do: ${unlocked[*]}" 2 |
| 52 |
fi |
| 53 |
|
| 54 |
# Cannot do - needs more recent annex |
| 55 |
# fsck |
| 56 |
check_clean |
| 57 |
|
| 58 |
git config --remove-section filter.annex || echo "Failed to remove filter.annex, may be gone already" |
| 59 |
sed -i -n -e '/filter=annex/d' .git/info/attributes |
| 60 |
rm -f .git/hooks/post-checkout .git/hooks/post-merge |
| 61 |
rm -rf .git/annex/keysdb .git/annex/fsck .git/annex/export |
| 62 |
|
| 63 |
git config annex.version 5 |
| 64 |
|
| 65 |
fsck |
| 66 |
check_clean |
| 67 |
|
| 68 |
## Let's do a dummy basic operation test |
| 69 |
#echo data > data |
| 70 |
#git annex add data |
| 71 |
#git commit -m 'sample data' data |
| 72 |
# |
| 73 |
#fsck |
| 74 |
#check_clean |
| 75 |
|
| 76 |
info "DONE, all good" |