Simple Git & GitHub CLI Shell Scripts
1#!/bin/bash
2
3function gmb {
4 if ! is_a_git_repo; then
5 echo "${BOLD} This won't work, you are not in a git repo !"
6 return 0
7 fi
8
9 if [ $# -eq 0 ]; then
10 echo "${BOLD} Fatal ! Specify the Branch to merge to $current_branch"
11 return 0
12 fi
13
14 current_branch=$(git branch | awk '/\*/ {print $2}')
15
16 # check if the branch doesn't exist
17 if ! is_a_git_branch "$1"; then
18 echo "${BOLD} Fatal ! $1 is a Non Existing branch "
19 return 0
20 fi
21
22 if [ "$current_branch" = "$1" ]; then
23 echo "${BOLD} Fatal ! Cannot Merge Identical Branch "
24 return 0
25 fi
26
27 git merge "$1"
28}
29
30# Resolve the full path to the script's directory
31REAL_PATH="$(dirname "$(readlink -f "$0")")"
32PARENT_DIR="$(dirname "$REAL_PATH")"
33CATEGORY="git.scripts"
34
35HELPS_DIR="$PARENT_DIR/helps/$CATEGORY"
36HELP_FILE="$(basename "$0" .sh)_help.sh"
37
38UTILS_DIR="$PARENT_DIR/utils"
39
40# Import necessary variables and functions
41source "$UTILS_DIR/check_git.sh"
42source "$UTILS_DIR/check_branch.sh"
43source "$UTILS_DIR/setup_git.sh"
44source "$UTILS_DIR/check_sudo.sh"
45source "$UTILS_DIR/colors.sh"
46source "$UTILS_DIR/usage.sh"
47
48# Import help file
49source "$HELPS_DIR/$HELP_FILE"
50
51# Usage function to display help
52function usage {
53 show_help "Usage" "${gmb_arguments[@]}"
54 show_help "Description" "${gmb_descriptions[@]}"
55 show_help "Options" "${gmb_options[@]}"
56 show_help "Examples" "${gmb_extras[@]}"
57 exit 0
58}
59
60# Check if --help is the first argument
61[ "$1" = "--help" ] && usage
62
63# prompt for sudo
64# password if required
65allow_sudo
66
67# Setting up git
68setup_git
69
70# Call gmb function
71gmb "$@"