Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Automatically set upstream and improve commit message handling #67

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions src/bash/functions
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ msg() {
printf "\n%s \033[1;34m[INFORMATION]\033[0m %s\n\n" "$timestamp" "$2"
;;
*)
printf "\n%s [ NOTICE ] %s\n\n" "$timestamp" "$2"
printf "\n%s [ NOTICE ] %s\n\n" "$timestamp" "$1"
;;
esac
}
Expand Down Expand Up @@ -93,24 +93,13 @@ gacp() {
# Default commit message
message="minor update"

# Default upstream setting
set_upstream=false
# If there is an argument, set the message to the argument

# Check if the first argument is a commit message or an option
if [[ $# -gt 0 ]] && [[ $1 != -* ]]; then
if [[ $# -gt 0 ]]; then
message=$1
shift
fi

# Parse command-line options
while getopts u option; do
case "${option}"
in
u) set_upstream=true;;
*) wmsg "Invalid option: -${OPTARG}.";;
esac
done

# Add all changes to the staging area
imsg "Adding changes to the staging area..."
(git add . && kmsg "Changes added to staging area.") || emsg "Failed to add changes to the staging area."
Expand All @@ -121,13 +110,18 @@ gacp() {

imsg "Pushing all changes to the GitHub repository..."
# Check if the upstream origin should be set
if $set_upstream; then
# Push the changes to the remote repository and set the upstream branch to the current branch
(git push --set-upstream origin "$(git rev-parse --abbrev-ref HEAD)" && kmsg "Push and set upstream completed.") || emsg "Failed to push changes and set upstream."
else
# Push the changes to the remote repository
(git push && kmsg "Push completed.") || emsg "Failed to push changes."
fi
{
(git push && kmsg "Push completed.") \
|| \
( \
git push --set-upstream origin "$(git rev-parse --abbrev-ref HEAD)" \
&& \
kmsg "Push and set upstream completed." \
) \
|| \
emsg "Failed to push changes to the remote repository."
# Push the changes to the remote repository
}
}


Expand Down