DovieW / obsidian-android-sync

Automated Obsidian sync setup for Android using Git (SSH), Termux, and Tasker.
GNU General Public License v3.0
48 stars 6 forks source link

Object Corruption #7

Open DovieW opened 10 months ago

DovieW commented 10 months ago

Screenshot_20231218-234554.png

DovieW commented 10 months ago

Screenshot_20231223-192131.png

DovieW commented 10 months ago

When i get such issues, just going into the directory in Termux and running git sync -ns works

DovieW commented 9 months ago

Doesn't seem to actually be a network issue. if i run the Sync (all) Vaults script, it just keeps happening.

DovieW commented 6 months ago

the network error is from the git-sync script so that can be ignored.

I was able to fix the object file is empty with git fsck --full

If you need the changes from the remote, a safe bet is git fetch && git reset @{u}

DovieW commented 6 months ago

maybe the fix would be to auto git fsck --full if a sync fails. and that can be toggled with an env var and it defaults to true

DovieW commented 2 weeks ago

https://github.com/termux/termux-app/issues/3777 consider solution in last comment

DovieW commented 5 days ago

https://www.reddit.com/r/termux/comments/1geddlp/git_repo_in_shared_storage_object_corruption/

DovieW commented 4 days ago

made this script to move all my vaults to termux storage and do the worktrees thing. so far seems to be working (I think its signifcantly faster too). will check back in a couple weeks to see if it solved the issue.

the script (thanks chatgpt):

#!/bin/bash
set -euo pipefail

# Colors for echo commands
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

# Source and destination paths
SOURCE_PATH="/storage/emulated/0/repos/Obsidian"
DEST_PATH="$HOME/repos/Obsidian"

# Create the destination directory if it doesn't exist
echo -e "${YELLOW}Creating destination directory at $DEST_PATH if it doesn't exist...${NC}"
mkdir -p "$DEST_PATH"

# Move all repositories from source to destination
for repo in "$SOURCE_PATH"/*; do
  if [ -d "$repo/.git" ]; then

    if [ -f "$repo/.git" ]; then
      echo "$repo is a worktree. Skipping loop."
      continue
    fi

    # Get the name of the repository
    repo_name=$(basename "$repo")

    # Move the repository
    echo -e "${YELLOW}Moving repository $repo_name to $DEST_PATH...${NC}"
    mv "$repo" "$DEST_PATH/"

    # Change to the repository directory
    echo -e "${YELLOW}Changing to the repository directory $DEST_PATH/$repo_name...${NC}"
    cd "$DEST_PATH/$repo_name" || exit

    # Determine if the branch is 'master' or 'main'
    # This is dumb it should just take the current branch name
    if git show-ref --verify --quiet refs/heads/master; then
      default_branch="master"
    elif git show-ref --verify --quiet refs/heads/main; then
      default_branch="main"
    else
      echo -e "${YELLOW}Neither 'master' nor 'main' branch found. Exiting...${NC}"
      exit 1
    fi

    git switch -c empty

    # Remove all files and directories except the .git directory
    echo -e "${YELLOW}Removing all files from the working directory of $repo_name except the .git directory...${NC}"
    find . -mindepth 1 \( -not -path "./.git" -a -not -path "./.git/*" \) -exec rm -rf {} +

    # Create a worktree for the repo back to the original location, checked out to the default branch
    echo -e "${YELLOW}Creating a worktree for $repo_name back to the original location at $SOURCE_PATH/$repo_name, checked out to $default_branch...${NC}"
    mkdir -p "$SOURCE_PATH/$repo_name"
    git worktree add "$SOURCE_PATH/$repo_name" "$default_branch"
  fi
done

echo -e "${GREEN}All repositories have been moved and worktrees created.${NC}"