-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitcp
executable file
·103 lines (87 loc) · 2.32 KB
/
gitcp
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
#!/bin/bash
# Check for help flag
for arg in "$@"
do
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]
then
echo Ex: gitcp original.js new.js
exit 0
fi
done
# Enforce two arguments
if [ $# != 2 ]
then
echo Error, you need to provide two arguments
echo Ex: gitcp original.js new.js
exit 0
fi
original_path=$1
new_path=$2
branch=$(git symbolic-ref --short HEAD)
temp_branch=gitcp_temp_branch
temp_ext=.temp
# Create temp branch
echo
read -p "Press enter to create temp branch"
echo "Creating temp branch"
git checkout -b $temp_branch
# Move file to new name
echo
read -p "Press enter to move file to new name"
echo "Moving file to new name"
git mv $original_path $new_path
# Commit on temp branch
echo
read -p "Press enter to commit on temp branch"
echo "Committing on temp branch"
git commit -m "Rename file"
# Checkout original branch
echo
read -p "Press enter to check out original branch"
echo "Checking out original branch"
git checkout $branch
# Move original file to temp location
echo
read -p "Press enter to rename file to temp name"
echo "Renaming file to temp name"
git mv $original_path $original_path$temp_ext
# Commit temp file
echo
read -p "Press enter to commit temp file name"
echo "Committing temp file"
git commit -m "Rename temp"
# Merge temp branch
echo
read -p "Press enter to merge temp branch"
echo "Merging temp branch"
git merge $temp_branch
# Resolve merge conflicts
echo
read -p "Press enter to resolve merge conflicts"
echo "Resolving merge conflicts"
git add .
# Commit temp branch merge
echo
read -p "Press enter to commit temp branch merge"
echo "Committing temp branch merge"
git commit -m "Merge temp branch"
# Delete temp branch
echo
read -p "Press enter to delete temp branch"
echo "Deleting temp branch"
git branch -D $temp_branch
# Restore original file name
echo
read -p "Press enter to rename file to original name"
echo "Renaming file to original name"
git mv $original_path$temp_ext $original_path
# Commit original file Rename
echo
read -p "Press enter to commit original file name"
echo "Comitting original name"
git commit -m "Restore original"
echo
echo "-----------------------------------------------------------"
echo "Copy successful!"
echo "No changes were pushed. You may want to push your changes."
echo "-----------------------------------------------------------"