Repository navigation
Expand file tree
/
Copy pathsell.sh
More file actions
executable file
·98 lines (81 loc) · 2.18 KB
/
Copy pathsell.sh
File metadata and controls
executable file
·98 lines (81 loc) · 2.18 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
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
#!/bin/sh
set -e
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "Error: This script must be run inside a git repository."
exit 1
fi
git add .
if git diff --staged --quiet; then
echo "No changes to commit. Working directory is clean."
exit 0
fi
CHANGELIST_FILE=$(mktemp)
git diff --staged --name-status > "$CHANGELIST_FILE"
git reset > /dev/null
echo "Starting to commit changed files individually..."
echo "---"
while IFS=$'\t' read -r status from_path to_path; do
filepath=""
action=""
subject=""
scope=""
type=""
filename=""
case "$status" in
A)
filepath="$from_path"
action="Add"
type="feat"
;;
M|T)
filepath="$from_path"
action="Update"
type="fix"
;;
D)
filepath="$from_path"
action="Remove"
type="refactor"
;;
R*)
git add "$from_path" "$to_path"
filepath="$to_path"
action="Rename"
type="refactor"
;;
C*)
filepath="$to_path"
action="Copy"
type="feat"
;;
*)
filepath="$from_path"
action="Modify"
type="chore"
;;
esac
if ! [[ "$status" =~ ^R.* ]]; then
git add "$filepath"
fi
scope=$(dirname "$filepath")
if [ "$scope" = "." ]; then
scope="root"
fi
if [[ "$status" =~ ^R.* ]]; then
old_filename=$(basename "$from_path")
new_filename=$(basename "$to_path")
subject="$type($scope): $action $old_filename to $new_filename"
elif [[ "$status" =~ ^C.* ]]; then
original_filename=$(basename "$from_path")
new_filename=$(basename "$to_path")
subject="$type($scope): $action $original_filename to $new_filename"
else
filename=$(basename "$filepath")
subject="$type($scope): $action $filename"
fi
git commit -m "$subject" > /dev/null
echo "✅ Committed: $subject"
done < "$CHANGELIST_FILE"
rm "$CHANGELIST_FILE"
echo "---"
echo "All changed files have been committed individually."