-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateNotities.sh
More file actions
executable file
·49 lines (40 loc) · 1.15 KB
/
UpdateNotities.sh
File metadata and controls
executable file
·49 lines (40 loc) · 1.15 KB
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
42
43
44
45
46
47
48
49
#!/bin/bash
# git_sync.sh
# Script to sync git repository with automatic pull, add, commit, and push
# Repository path
REPO_PATH="/Users/mikebos/Library/Mobile Documents/27N4MQEA55~pro~writer/Documents"
# Function to handle errors
handle_error() {
echo "ERROR: $1"
exit 1
}
# Change to repository directory
cd "$REPO_PATH" || handle_error "Could not change to repository directory at $REPO_PATH"
# Pull latest changes
git pull
if [ $? -ne 0 ]; then
handle_error "Failed to pull latest changes. Please resolve conflicts manually."
fi
# Add all new files and directories
git add --all
if [ $? -ne 0 ]; then
handle_error "Failed to add new files and directories."
fi
# Check if there are changes to commit
if git diff-index --quiet HEAD --; then
echo "No changes to commit."
exit 0
fi
# Commit changes with timestamp
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
git commit -m "Automatic sync: $TIMESTAMP"
if [ $? -ne 0 ]; then
handle_error "Failed to commit changes."
fi
# Push changes to remote
git push
if [ $? -ne 0 ]; then
handle_error "Failed to push changes to remote repository."
fi
echo "SUCCESS: Repository successfully synchronized."
exit 0