Skip to content

Commit e918e61

Browse files
feat: git tickets command
This command is used to get the new tickets between two branches
1 parent eba8203 commit e918e61

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

scripts/git-tickets

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Prompt for a branch name with a default
3+
prompt_for_branch() {
4+
read -p "Enter the name of the $1 branch (default: $2): " branch
5+
echo "${branch:-$2}" # Return the entered branch name or the default if none was entered
6+
}
7+
8+
# Check for --update flag
9+
UPDATE_BRANCHES=false
10+
for arg in "$@"; do
11+
if [ "$arg" == "--update" ]; then
12+
UPDATE_BRANCHES=true
13+
break
14+
fi
15+
done
16+
17+
# Prompt for the first branch name if not provided
18+
if [ -z "$1" ] || [ "$1" == "--update" ]; then
19+
BRANCH1=$(prompt_for_branch "first" "master")
20+
else
21+
BRANCH1="$1"
22+
fi
23+
24+
# Prompt for the second branch name if not provided
25+
if [ -z "$2" ] || [ "$2" == "--update" ]; then
26+
BRANCH2=$(prompt_for_branch "second" "staging")
27+
else
28+
BRANCH2="$2"
29+
fi
30+
# Function to update or create temporary branches
31+
process_branch() {
32+
local branch_name=$1
33+
local temp_branch="temp_${branch_name}_$$"
34+
if $UPDATE_BRANCHES; then
35+
git checkout $branch_name &> /dev/null
36+
git pull origin $branch_name &> /dev/null
37+
echo "$branch_name"
38+
else
39+
git fetch origin $branch_name:$temp_branch &> /dev/null
40+
echo $temp_branch
41+
fi
42+
}
43+
44+
# Process the first branch
45+
BRANCH1=$(process_branch $BRANCH1)
46+
47+
# Process the second branch
48+
BRANCH2=$(process_branch $BRANCH2)
49+
50+
# If not updating branches, use the temporary branches for log
51+
if ! $UPDATE_BRANCHES; then
52+
# Run the git log command and process the output on temporary branches
53+
git log $BRANCH2..$BRANCH1 --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u
54+
55+
# Delete the temporary branches
56+
git branch -D $BRANCH1 &> /dev/null
57+
git branch -D $BRANCH2 &> /dev/null
58+
git status;
59+
else
60+
# Run the git log command and process the output on updated branches
61+
git log $BRANCH2..$BRANCH1 --oneline --no-merges | grep -Eio "(\w+)-([0-9]+)" | tr '[:lower:]' '[:upper:]' | sort -u
62+
63+
# Checkout to the first branch (assumed to be 'master')
64+
git checkout $BRANCH1 &> /dev/null
65+
git status
66+
fi

0 commit comments

Comments
 (0)