~ruther/emacs.d

ref: 2248eedcb0dbfebadd62d052d27fa74cfe2c98ba emacs.d/scripts/android-repair-git -rw-r--r-- 1.1 KiB
2248eedc — Rutherther chore: automatically start server on Android 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash

# On Android, I have this issue... When too many repos are being
# cloned, it fails. Then I have to go over them one by one and either
# remove them or checkout the main branch after fetching. So this is a
# possible workaround. In the future, elpaca-queue-limit should take
# care of this on new devices I will use.

checkout()
{
  # The lock is left there even when nothing uses it...
  # Of course in general this is dangerous, nothing else
  # should be accessing the repo.
  rm -rf .git/index.lock

  if [[ ! -f $repo/.git/HEAD ]]; then
    cd -
    rm -rf $repo
    return 0
  fi

  if git show-ref --verify --quiet refs/remotes/origin/main; then
    git checkout main
  elif git show-ref --verify --quiet refs/remotes/origin/master; then
    git checkout master
  else
    echo "ERROR: No main or master branch found in $repo" >&2
  fi

  git reset --hard HEAD
}

for repo in ~/.emacs.d/stateful/elpaca/repos/*; do
    count=$(ls "$repo" | wc -l)

    if [[ $count -eq 0 ]]; then
      echo "Found, $repo"

      (cd "$repo" && git fetch --all && checkout)
    fi
done