-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitup.sh
executable file
·104 lines (83 loc) · 3.09 KB
/
gitup.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
# Tolga Erok
# 10/6/2024
# git uploader version #2
set -e
# Personal nixos git folder uploader!!
# Tolga Erok. ¯\\_(ツ)_/¯..
# 20/8/23.
start_time=$(date +%s)
# Directory of your Git repository
REPO_DIR="/home/tolga/Documents/MyGit"
# Commit message with timestamp and custom changes in Australian format..
COMMIT_MSG="(ツ)_/¯ Edit: $(date '+%d-%m-%Y %I:%M:%S %p')"
# Add some tweaks
git config --global core.compression 9
git config --global core.deltaBaseCacheLimit 2g
git config --global diff.algorithm histogram
git config --global http.postBuffer 524288000
# Ensure the Git repository is initialized
if [ ! -d "$REPO_DIR/.git" ]; then
echo "Initializing Git repository in $REPO_DIR..."
git init "$REPO_DIR"
git remote add origin git@github.com:tolgaerok/solus.git
fi
# Check if the remote URL is set to SSH
remote_url=$(git -C "$REPO_DIR" remote get-url origin)
# Configure Git credential helper to cache credentials for 1 hour
git config --global credential.helper "cache --timeout=3600"
if [[ $remote_url == *"git@github.com"* ]]; then
echo ""
echo "Remote URL is set to SSH. Proceeding with the script..."
echo ""
else
echo "Remote URL is not set to SSH. Please set up SSH key-based authentication for the remote repository."
echo "If you haven't already, generate an SSH key pair:"
echo "ssh-keygen -t ed25519 -C 'your email'"
echo "Add your SSH key to the agent:"
echo "eval \$(ssh-agent -s)"
echo "ssh-add ~/.ssh/id_ed25519"
echo "Then, add your SSH public key to your GitHub account:"
echo "cat ~/.ssh/id_ed25519.pub"
echo "Finally, update your Git configuration to use SSH:"
echo "git config --global credential.helper store"
echo "Remote URL needs to be updated to SSH. Exiting..."
exit 1
fi
# Navigate to the repository directory
cd "$REPO_DIR" || exit
# Check if a rebase is in progress
if [ -d "$REPO_DIR/.git/rebase-merge" ]; then
echo "A rebase is currently in progress. Please resolve it before running this script."
echo "You can either continue the rebase with 'git rebase --continue' or abort it with 'git rebase --abort'."
exit 1
fi
# Print the current working directory for debugging
echo "Current working directory: $(pwd)"
# Add all changes
git add .
# Print the status for debugging
echo "Git status before committing:"
git status
# Check if there are changes to commit
if git status --porcelain | grep -qE '^\s*[MARCDU]'; then
echo "Changes detected, committing..."
# Commit changes with custom message
git commit -am "$COMMIT_MSG"
# Pull changes from the remote repository to avoid conflicts
echo "Pulling changes from remote repository..."
git pull --rebase origin main
# Push changes to the main branch
echo "Pushing changes to remote repository..."
git push origin main
echo "Files uploaded"
else
echo "No changes to commit."
echo "Nothing to Upload"
fi
end_time=$(date +%s)
time_taken=$((end_time - start_time))
notify-send --icon=ktimetracker --app-name="DONE" "Uploaded " "Completed:
(ツ)_/¯
Time taken: $time_taken
" -u normal