Skip to content

Instantly share code, notes, and snippets.

@eugeneyan
Last active January 16, 2023 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugeneyan/c4da21af315b62fc3b88163541c816e3 to your computer and use it in GitHub Desktop.
Save eugeneyan/c4da21af315b62fc3b88163541c816e3 to your computer and use it in GitHub Desktop.
"""
Iteratively loop through all files in DIR and add-commit-push them to REPO.
This script should sit in your obsidian vault.
"""
from pathlib import Path
from git import Repo
import os
DIR = '/Users/eugene/obsidian-vault/assets'
REPO = Repo('.')
for i, path in enumerate(Path(DIR).iterdir()):
file_size = int(os.stat(path).st_size / 1024)
print(f'file {i}: {str(path).split("/")[-1]} ({file_size} kb)')
if file_size < 1024:
commit_msg = f'Add {str(path).split("/")[-1]}'
REPO.index.add(str(path)) # Add
REPO.index.commit(commit_msg) # Commit
origin = REPO.remote('origin')
origin.push() # Push
else:
print(f'Skipping file {i}: {str(path).split("/")[-1]} ({file_size} kb)')
f = open("skipped-files.txt", "a")
f.write(f'{str(path).split("/")[-1]}\n')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment