@san-siva/gitsy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (16) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/g-cb +47 -0
  4. package/g-co +106 -0
  5. package/g-db +122 -0
  6. package/g-diff +228 -0
  7. package/g-dlc +109 -0
  8. package/g-pull +72 -0
  9. package/g-push +67 -0
  10. package/g-rmf +57 -0
  11. package/g-rto +50 -0
  12. package/g-s +50 -0
  13. package/g-wa +155 -0
  14. package/g-wr +260 -0
  15. package/package.json +70 -0
  16. package/utils +464 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Santhosh Siva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # gitsy
2
+
3
+ A set of bash utilities for managing Git repositories with ease. Provides user-friendly commands with helpful prompts, color-coded outputs, and automation.
4
+
5
+ ## Available Commands
6
+
7
+ - `g-co` - Checkout branch
8
+ - `g-pull` - Pull changes from remote
9
+ - `g-push` - Push changes to remote
10
+ - `g-wa` - Create git worktree
11
+ - `g-wr` - Remove git worktree
12
+ - `g-db` - Delete branch
13
+ - `g-dlc` - Discard last commit
14
+ - `g-rmf` - Stash working directory
15
+ - `g-rto` - Reset to remote branch
16
+ - `g-cb` - Show current branch
17
+ - `g-s` - Show git status
18
+ - `g-diff` - Compare branches
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ git clone https://github.com/san-siva/gitsy.git
24
+ cd gitsy
25
+
26
+ # Add to your PATH in .bashrc or .zshrc
27
+ export PATH="$PATH:/path/to/gitsy"
28
+ ```
29
+
30
+ **Dependencies:** `git`, `figlet`, `lolcat`
31
+
32
+ ## Documentation
33
+
34
+ For complete documentation, usage examples, and detailed command reference, visit the [gitsy documentation website](https://gitsy-56895.web.app).
35
+
36
+ Quick start:
37
+ ```bash
38
+ # Run any command with --help to see available options
39
+ g-co --help
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ Contributions are welcome! Please fork the repo and submit pull requests. For bugs or feature requests, open an issue on the repository.
45
+
46
+ ## License
47
+
48
+ This project is licensed under the MIT License.
49
+
50
+ ## Contact
51
+
52
+ Author: Santhosh Siva
53
+ GitHub: https://github.com/san-siva
package/g-cb ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Author: Santhosh Siva
4
+ # Date Created: 03-08-2025
5
+
6
+ # Description:
7
+ # This script returns the current branch name in a git repository.
8
+
9
+ source "$(dirname "${BASH_SOURCE[0]}")/utils"
10
+
11
+ set_flags() {
12
+ while [ $# -gt 0 ]; do
13
+ case "$1" in
14
+ -h | --help)
15
+ echo "g-cb - show current branch name"
16
+ echo " "
17
+ echo "g-cb [options]"
18
+ echo " "
19
+ echo "options:"
20
+ echo "-h, --help show brief help"
21
+ exit 0
22
+ ;;
23
+ *)
24
+ echo "${RED}Unknown option:${NC} $1"
25
+ exit 1
26
+ ;;
27
+ esac
28
+ shift
29
+ done
30
+ }
31
+
32
+ main() {
33
+ set_flags "$@"
34
+ validate_dependencies git
35
+ print_banner
36
+ print_message "${BLUE}Fetching current branch...${NC}" 1
37
+ current_branch_name=$(git rev-parse --abbrev-ref HEAD)
38
+ if [ -z "$current_branch_name" ]; then
39
+ print_message "${RED}Failed to get current branch.${NC}"
40
+ exit 1
41
+ fi
42
+ echo "$current_branch_name" | indent
43
+ copy_to_clipboard "$current_branch_name" "Current branch name copied to clipboard."
44
+ }
45
+
46
+ main "$@"
47
+ exit 0
package/g-co ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Author: Santhosh Siva
4
+ # Date Created: 03-08-2025
5
+
6
+ # Description:
7
+ # A script to checkout branches, optionally stash changes, and manage git workflow efficiently.
8
+
9
+ source "$(dirname "${BASH_SOURCE[0]}")/utils"
10
+
11
+ # Default Values
12
+ stash=false
13
+ target_branch=
14
+
15
+ set_flags() {
16
+ while [ $# -gt 0 ]; do
17
+ case "$1" in
18
+ -h | --help)
19
+ echo "g-co - attempt to checkout to branch"
20
+ echo " "
21
+ echo "g-co [options]"
22
+ echo " "
23
+ echo "options:"
24
+ echo "-h, --help show brief help"
25
+ echo "--target-branch BRANCH, --target-branch=BRANCH, -t=BRANCH, -t BRANCH specify the target branch"
26
+ echo "--stash-changes stash changes before proceeding"
27
+ exit 0
28
+ ;;
29
+ -t=* | --target-branch=*)
30
+ target_branch="${1#*=}"
31
+ if [ -z "$target_branch" ]; then
32
+ echo "${RED}Error: No target branch specified.$NC"
33
+ exit 1
34
+ fi
35
+ ;;
36
+ -t | --target-branch)
37
+ shift
38
+ if [ $# -gt 0 ]; then
39
+ target_branch="$1"
40
+ else
41
+ echo "${RED}Error: No target branch specified.$NC"
42
+ exit 1
43
+ fi
44
+ ;;
45
+ -s | --stash-changes)
46
+ stash=true
47
+ ;;
48
+ *)
49
+ echo "${RED}Unknown option:${NC} $1"
50
+ exit
51
+ ;;
52
+ esac
53
+ shift
54
+ done
55
+ }
56
+
57
+ checkout_or_create_branch() {
58
+ local step_number=2
59
+ if [ "${stash}" = true ]; then
60
+ step_number=3
61
+ fi
62
+
63
+ print_message "${BLUE}Checking-out to branch ${NC}origin/${target_branch}${BLUE}.${NC}" $step_number
64
+
65
+ # Check if branch exists locally
66
+ if branch_exists_locally "${target_branch}"; then
67
+ fetch_changes "${target_branch}"
68
+ checkout_branch "${target_branch}" $((step_number + 1))
69
+ return
70
+ fi
71
+
72
+ print_message "${RED}Branch not found locally.${NC}"
73
+
74
+ print_message "${BLUE}Checking if branch exists on remote...${NC}" $((step_number + 1))
75
+ if branch_exists_on_remote "${target_branch}"; then
76
+ print_message "${GREEN}Branch available on remote.${NC}"
77
+ fetch_changes "${target_branch}"
78
+ checkout_branch "${target_branch}"
79
+ return
80
+ fi
81
+
82
+ print_message "${RED}Branch not found on remote.${NC}"
83
+
84
+ create_new_branch=$(prompt_user true "Create new branch?" $((step_number + 2)))
85
+ if [ "${create_new_branch}" = "y" ]; then
86
+ checkout_branch "${target_branch}" true
87
+ return
88
+ fi
89
+
90
+ print_message "${RED}Aborted.${NC}"
91
+ exit 1
92
+ }
93
+
94
+ main() {
95
+ set_flags "$@"
96
+ validate_dependencies git figlet lolcat
97
+ print_banner
98
+ check_if_target_branch_is_set $target_branch
99
+ already_on_branch $target_branch
100
+ stash_changes $stash
101
+ checkout_or_create_branch
102
+ }
103
+
104
+ # Run the script
105
+ main "$@"
106
+ exit 0
package/g-db ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Author: Santhosh Siva
4
+ # Date Created: 12-02-2025
5
+
6
+ # Description:
7
+ # A script to delete a branch locally and push the deletion to remote.
8
+
9
+ source "$(dirname "${BASH_SOURCE[0]}")/utils"
10
+
11
+ # Default Values
12
+ target_branch=
13
+
14
+ set_flags() {
15
+ while [ $# -gt 0 ]; do
16
+ case "$1" in
17
+ -h | --help)
18
+ echo "g-db - delete a branch locally and optionally on remote"
19
+ echo " "
20
+ echo "g-db [options]"
21
+ echo " "
22
+ echo "options:"
23
+ echo "-h, --help show brief help"
24
+ echo "--target-branch BRANCH, --target-branch=BRANCH, -t=BRANCH, -t BRANCH specify the branch to delete"
25
+ exit 0
26
+ ;;
27
+ -t=* | --target-branch=*)
28
+ target_branch="${1#*=}"
29
+ if [ -z "$target_branch" ]; then
30
+ echo "${RED}Error: No target branch specified.$NC"
31
+ exit 1
32
+ fi
33
+ ;;
34
+ -t | --target-branch)
35
+ shift
36
+ if [ $# -gt 0 ]; then
37
+ target_branch="$1"
38
+ else
39
+ echo "${RED}Error: No target branch specified.$NC"
40
+ exit 1
41
+ fi
42
+ ;;
43
+ *)
44
+ echo "${RED}Unknown option:${NC} $1"
45
+ exit 1
46
+ ;;
47
+ esac
48
+ shift
49
+ done
50
+ }
51
+
52
+
53
+ delete_local_branch() {
54
+ local branch=$1
55
+ local step_number=3
56
+
57
+ if ! branch_exists_locally "${branch}"; then
58
+ print_message "${RED}Branch ${NC}${branch}${RED} does not exist locally.${NC}"
59
+ return 0
60
+ fi
61
+
62
+ current_branch=$(fetch_current_branch)
63
+ if [ "${branch}" = "${current_branch}" ]; then
64
+ print_message "${RED}Cannot delete the branch you are currently on.${NC}"
65
+ print_message "${RED}Please checkout to another branch first.${NC}"
66
+ exit 1
67
+ fi
68
+
69
+ print_message "${BLUE}Deleting local branch ${NC}${branch}${BLUE}...${NC}" $step_number
70
+
71
+ if ! git -c color.ui=always branch -d "${branch}" 2>&1 | indent; then
72
+ print_message "${RED}Failed to delete local branch ${NC}${branch}${RED}. [Fail]${NC}"
73
+ print_message "${PROMPT}Hint: Branch may not be fully merged. Use 'git branch -D ${branch}' to force delete.${NC}"
74
+ exit 1
75
+ fi
76
+
77
+ print_message "${GREEN}Local branch ${NC}${branch}${GREEN} deleted successfully.${NC}"
78
+ }
79
+
80
+ prompt_remote_deletion() {
81
+ local branch=$1
82
+
83
+ if ! branch_exists_on_remote "${branch}"; then
84
+ return 0
85
+ fi
86
+
87
+ delete_remote=$(prompt_user "true" "Delete branch on remote as well?" 5)
88
+ if [ "$delete_remote" = "n" ]; then
89
+ print_message "${BLUE}Skipping remote branch deletion.${NC}"
90
+ return 0
91
+ fi
92
+
93
+ print_message "${BLUE}Deleting remote branch ${NC}origin/${branch}${BLUE}...${NC}" 6
94
+ if ! git -c color.ui=always push origin --delete "${branch}" 2>&1 | indent; then
95
+ print_message "${RED}Failed to delete remote branch ${NC}origin/${branch}${RED}. [Fail]${NC}"
96
+ exit 1
97
+ fi
98
+
99
+ print_message "${GREEN}Remote branch ${NC}origin/${branch}${GREEN} deleted successfully.${NC}"
100
+ }
101
+
102
+ prompt_user_confirmation() {
103
+ local branch=$1
104
+ confirm=$(prompt_user "false" "Are you sure you want to delete branch ${branch}?" 2)
105
+ if [ "$confirm" = "n" ]; then
106
+ print_message "${RED}Operation cancelled by user.${NC}"
107
+ exit 0
108
+ fi
109
+ }
110
+
111
+ main() {
112
+ set_flags "$@"
113
+ validate_dependencies git figlet lolcat
114
+ print_banner
115
+ check_if_target_branch_is_set "$target_branch"
116
+ prompt_user_confirmation "$target_branch"
117
+ delete_local_branch "$target_branch"
118
+ prompt_remote_deletion "$target_branch"
119
+ }
120
+
121
+ main "$@"
122
+ exit 0
package/g-diff ADDED
@@ -0,0 +1,228 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Author: Santhosh Siva
4
+ # Date Created: 03-08-2025
5
+
6
+ # Description:
7
+ # A script to compare changes between two git branches.
8
+
9
+ source "$(dirname "${BASH_SOURCE[0]}")/utils"
10
+
11
+ target_branch=""
12
+ source_branch=""
13
+ full_diff=false
14
+ files_only=false
15
+
16
+ set_flags() {
17
+ while [ $# -gt 0 ]; do
18
+ case "$1" in
19
+ -h | --help)
20
+ echo "g-diff - compare changes between two git branches"
21
+ echo " "
22
+ echo "g-diff [options]"
23
+ echo " "
24
+ echo "options:"
25
+ echo "-h, --help show brief help"
26
+ echo "--target-branch BRANCH, --target-branch=BRANCH, -t=BRANCH, -t BRANCH specify the target branch"
27
+ echo "--source-branch BRANCH, --source-branch=BRANCH, -s=BRANCH, -s BRANCH specify the source branch (defaults to current branch)"
28
+ echo "-f, --full show full diff and copy to clipboard"
29
+ echo "--files-only show only file names (no stats, no clipboard)"
30
+ exit 0
31
+ ;;
32
+ -f | --full)
33
+ full_diff=true
34
+ ;;
35
+ --files-only)
36
+ files_only=true
37
+ ;;
38
+ -t=* | --target-branch=*)
39
+ target_branch="${1#*=}"
40
+ if [ -z "$target_branch" ]; then
41
+ print_message "${RED}Error: No target branch specified.${NC}"
42
+ exit 1
43
+ fi
44
+ ;;
45
+ -t | --target-branch)
46
+ shift
47
+ if [ $# -gt 0 ]; then
48
+ target_branch="$1"
49
+ else
50
+ print_message "${RED}Error: No target branch specified.${NC}"
51
+ exit 1
52
+ fi
53
+ ;;
54
+ -s=* | --source-branch=*)
55
+ source_branch="${1#*=}"
56
+ if [ -z "$source_branch" ]; then
57
+ print_message "${RED}Error: No source branch specified.${NC}"
58
+ exit 1
59
+ fi
60
+ ;;
61
+ -s | --source-branch)
62
+ shift
63
+ if [ $# -gt 0 ]; then
64
+ source_branch="$1"
65
+ else
66
+ print_message "${RED}Error: No source branch specified.${NC}"
67
+ exit 1
68
+ fi
69
+ ;;
70
+ *)
71
+ print_message "${RED}Unknown option:${NC} $1"
72
+ exit 1
73
+ ;;
74
+ esac
75
+ shift
76
+ done
77
+ }
78
+
79
+ format_diff_output() {
80
+ echo ""
81
+ local current_file=""
82
+ local in_hunk=false
83
+ local skip_next_line=false
84
+
85
+ # Process git diff output line by line
86
+ git diff "${source_branch}..origin/${target_branch}" | while IFS= read -r line; do
87
+ if [[ "$line" =~ ^diff\ --git\ a/(.+)\ b/(.+)$ ]]; then
88
+ # New file section
89
+ if [ -n "$current_file" ]; then
90
+ echo ""
91
+ fi
92
+ current_file="${BASH_REMATCH[1]}"
93
+ echo "${BLUE}file:${NC} ${current_file}"
94
+
95
+ # Get stats for this file
96
+ local adds=$(git diff --numstat "${source_branch}..origin/${target_branch}" -- "$current_file" | awk '{print $1}')
97
+ local dels=$(git diff --numstat "${source_branch}..origin/${target_branch}" -- "$current_file" | awk '{print $2}')
98
+ if [ -n "$adds" ] && [ -n "$dels" ]; then
99
+ echo "${BLUE}stats:${NC} ${GREEN}+${adds}${NC} ${RED}-${dels}${NC}"
100
+ fi
101
+ echo "${BLUE}changes:${NC}"
102
+ echo ""
103
+ in_hunk=false
104
+ elif [[ "$line" =~ ^index\ .* ]]; then
105
+ # Skip index line
106
+ continue
107
+ elif [[ "$line" =~ ^---\ ]]; then
108
+ # Skip --- line
109
+ continue
110
+ elif [[ "$line" =~ ^\+\+\+\ ]]; then
111
+ # Skip +++ line
112
+ continue
113
+ elif [[ "$line" =~ ^@@ ]]; then
114
+ # Hunk header
115
+ in_hunk=true
116
+ echo " ${line}"
117
+ elif $in_hunk; then
118
+ # Inside a hunk, show the actual changes
119
+ # Colorize the line
120
+ if [[ "$line" =~ ^\+ ]]; then
121
+ echo " ${GREEN}${line}${NC}"
122
+ elif [[ "$line" =~ ^- ]]; then
123
+ echo " ${RED}${line}${NC}"
124
+ else
125
+ echo " ${line}"
126
+ fi
127
+ fi
128
+ done
129
+ echo ""
130
+ }
131
+
132
+ has_changes() {
133
+ ! git diff --quiet "${source_branch}..origin/${target_branch}" 2>&1
134
+ }
135
+
136
+ show_full_diff() {
137
+ if has_changes; then
138
+ # Capture and display formatted output
139
+ local formatted_output=$(format_diff_output)
140
+ echo "$formatted_output" | indent
141
+
142
+ # Copy formatted output to clipboard (strip color codes)
143
+ local clipboard_content=$(sed $'s/\033\[[0-9;]*m//g' <<< "${formatted_output}")
144
+ copy_to_clipboard "$clipboard_content" "Formatted diff copied to clipboard."
145
+ else
146
+ print_message "${BLUE}No changes found between ${NC}${source_branch}${BLUE} and ${NC}${target_branch}${BLUE}.${NC}"
147
+ fi
148
+ }
149
+
150
+ show_files_only() {
151
+ local filenames
152
+ if ! filenames=$(git diff --name-only "${source_branch}..origin/${target_branch}" 2>&1); then
153
+ echo "$filenames" | indent
154
+ print_message "${RED}Failed to compare branches.${NC}"
155
+ exit 1
156
+ fi
157
+
158
+ if [ -n "$filenames" ]; then
159
+ echo "$filenames" | indent
160
+ else
161
+ print_message "${BLUE}No changes found between ${NC}${source_branch}${BLUE} and ${NC}${target_branch}${BLUE}.${NC}"
162
+ fi
163
+ }
164
+
165
+ show_stat_summary() {
166
+ local result
167
+ if ! result=$(git -c color.ui=always diff --stat "${source_branch}..origin/${target_branch}" 2>&1); then
168
+ echo "$result" | indent
169
+ print_message "${RED}Failed to compare branches.${NC}"
170
+ exit 1
171
+ fi
172
+
173
+ if [ -n "$result" ]; then
174
+ echo "$result" | indent
175
+
176
+ # Copy stats to clipboard (strip color codes)
177
+ local stats_content=$(git diff --stat "${source_branch}..origin/${target_branch}")
178
+ copy_to_clipboard "$stats_content" "Stats copied to clipboard."
179
+ else
180
+ print_message "${BLUE}No changes found between ${NC}${source_branch}${BLUE} and ${NC}${target_branch}${BLUE}.${NC}"
181
+ fi
182
+ }
183
+
184
+ compare_branches() {
185
+ local step_number=1
186
+
187
+ if [ -z "$source_branch" ]; then
188
+ print_message "${BLUE}Source branch not specified, using current branch...${NC}" $step_number
189
+ source_branch=$(fetch_current_branch true)
190
+ if [ -z "$source_branch" ]; then
191
+ print_message "${RED}Failed to get current branch.${NC}"
192
+ exit 1
193
+ fi
194
+ step_number=$((step_number + 1))
195
+ fi
196
+
197
+ print_message "${BLUE}Fetching latest changes for target branch ${NC}${target_branch}${BLUE}...${NC}" $step_number
198
+ if ! fetch_changes "${target_branch}"; then
199
+ print_message "${RED}Failed to fetch target branch ${NC}${target_branch}${RED}.${NC}"
200
+ exit 1
201
+ fi
202
+
203
+ step_number=$((step_number + 1))
204
+ print_message "${BLUE}Comparing ${NC}${source_branch}${BLUE} with ${NC}${target_branch}${BLUE}...${NC}" $step_number
205
+
206
+ if [ "$full_diff" = true ]; then
207
+ show_full_diff
208
+ return 0
209
+ fi
210
+
211
+ if [ "$files_only" = true ]; then
212
+ show_files_only
213
+ return 0
214
+ fi
215
+
216
+ show_stat_summary
217
+ }
218
+
219
+ main() {
220
+ set_flags "$@"
221
+ validate_dependencies git figlet lolcat
222
+ print_banner
223
+ check_if_target_branch_is_set $target_branch
224
+ compare_branches
225
+ }
226
+
227
+ main "$@"
228
+ exit 0
package/g-dlc ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Author: Santhosh Siva
4
+ # Date Created: 12-02-2025
5
+
6
+ # Description:
7
+ # A script to discard the last commit with optional force mode.
8
+
9
+ source "$(dirname "${BASH_SOURCE[0]}")/utils"
10
+
11
+ # Default Values
12
+ force_mode=false
13
+
14
+ set_flags() {
15
+ while [ $# -gt 0 ]; do
16
+ case "$1" in
17
+ -h | --help)
18
+ echo "g-dlc - discard the last commit"
19
+ echo " "
20
+ echo "g-dlc [options]"
21
+ echo " "
22
+ echo "options:"
23
+ echo "-h, --help show brief help"
24
+ echo "-f, --force force discard without checking uncommitted changes"
25
+ exit 0
26
+ ;;
27
+ -f=* | --force=*)
28
+ if [ "${1#*=}" = "true" ]; then
29
+ force_mode=true
30
+ fi
31
+ ;;
32
+ -f | --force)
33
+ shift
34
+ if [ $# -gt 0 ] && [ "$1" = "true" ]; then
35
+ force_mode=true
36
+ else
37
+ # If no argument or not 'true', treat -f as a flag
38
+ force_mode=true
39
+ continue
40
+ fi
41
+ ;;
42
+ *)
43
+ echo "${RED}Unknown option:${NC} $1"
44
+ exit 1
45
+ ;;
46
+ esac
47
+ shift
48
+ done
49
+ }
50
+
51
+ prompt_user_confirmation() {
52
+ local step_number=1
53
+ if [ "$force_mode" = "true" ]; then
54
+ confirm=$(prompt_user "false" "Are you sure you want to discard the last commit? (this action cannot be undone)" $step_number)
55
+ else
56
+ confirm=$(prompt_user "false" "Are you sure you want to discard the last commit?" $step_number)
57
+ fi
58
+
59
+ if [ "$confirm" = "n" ]; then
60
+ print_message "${RED}Operation cancelled by user.${NC}" 0
61
+ exit 0
62
+ fi
63
+ }
64
+
65
+ verify_no_uncommitted_changes() {
66
+ if [ "$force_mode" = "false" ]; then
67
+ print_message "${BLUE}Checking for uncommitted changes...${NC}" 2
68
+ if has_uncommitted_changes "."; then
69
+ print_message "${RED}Error: There are uncommitted changes in your working directory.${NC}" 0
70
+ print_message "${RED}Please commit or stash your changes before discarding the last commit.${NC}" 0
71
+ exit 1
72
+ fi
73
+ print_message "${GREEN}No uncommitted changes found.${NC}" 0
74
+ fi
75
+ }
76
+
77
+ discard_last_commit() {
78
+ print_message "${BLUE}Discarding the last commit...${NC}" 3
79
+
80
+ if [ "$force_mode" = "true" ]; then
81
+ reset_output=$(git -c color.ui=always reset --hard --no-recurse-submodules HEAD~1 2>&1)
82
+ else
83
+ reset_output=$(git -c color.ui=always reset --soft --no-recurse-submodules HEAD~1 2>&1)
84
+ fi
85
+ reset_exit_code=$?
86
+
87
+ if [ -n "$reset_output" ]; then
88
+ echo "$reset_output" | indent
89
+ fi
90
+ if [ $reset_exit_code -ne 0 ]; then
91
+ print_message "${RED}Failed to discard the last commit. [Fail]${NC}" 0
92
+ exit 1
93
+ fi
94
+
95
+ print_message "${GREEN}Last commit discarded successfully.${NC}" 0
96
+ }
97
+
98
+ main() {
99
+ set_flags "$@"
100
+ validate_dependencies git figlet lolcat
101
+ print_banner
102
+
103
+ prompt_user_confirmation
104
+ verify_no_uncommitted_changes
105
+ discard_last_commit
106
+ }
107
+
108
+ main "$@"
109
+ exit 0