-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmart_commit.sh
More file actions
executable file
·56 lines (47 loc) · 1.64 KB
/
Copy pathsmart_commit.sh
File metadata and controls
executable file
·56 lines (47 loc) · 1.64 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
50
51
52
53
54
55
56
echo "Enter folder name (e.g., arrays,fundamentals,two_pointers,hashing,sliding_window,bit_manipulation,linked_list,dp):"
read folder
# Add -u to show files inside completely untracked directories
files=$(git status --porcelain -u | awk '{print $2}' | grep -E "^$folder/.*\.(py|sql|sh)$")
if [ -z "$files" ]; then
echo "No new or modified .py, .sql, or .sh files found in $folder/"
exit 0
fi
echo "Files to commit:"
echo "$files"
for file in $files; do
git add "$file"
if [ "$folder" = "daily_challenges" ]; then
today=$(LC_ALL=C date "+%B %d, %Y")
git commit -m "feat($folder): $today"
else
filename=$(basename "$file")
git commit -m "feat($folder): add solution for '${filename}'"
fi
done
# Also add -u here for the extra changes check
extra_changes=$(git status --porcelain -u | awk '{print $2}' | grep -vE "^$folder/.*\.(py|sql|sh)$")
stash_needed=false
if [ -n "$extra_changes" ]; then
echo "Extra changes found (outside $folder):"
echo "$extra_changes"
read -p "Do you want to commit them as 'chore: update project files'? (y/n): " confirm
if [ "$confirm" == "y" ]; then
git add $extra_changes
git commit -m "chore: update project files"
else
echo "Skipped committing extra changes. Stashing them temporarily..."
git stash push -u -k -m "smart_commit_auto_stash"
stash_needed=true
fi
fi
echo "Pulling latest changes with rebase..."
if git pull --rebase; then
echo "Pull successful. Now pushing..."
git push origin main
else
echo "Pull failed. Please resolve conflicts and run the script again."
fi
if [ "$stash_needed" = true ]; then
echo "Restoring your skipped changes..."
git stash pop
fi