From d7d0eaef9d4102eee65b148cc653feea1b61e69d Mon Sep 17 00:00:00 2001 From: "user.name" Date: Sat, 20 May 2023 12:36:08 +0100 Subject: [PATCH] Remove pull feature --- commit | 11 +--- commit~ | 175 -------------------------------------------------------- 2 files changed, 1 insertion(+), 185 deletions(-) delete mode 100755 commit~ diff --git a/commit b/commit index 701b110..6cc6d46 100755 --- a/commit +++ b/commit @@ -31,16 +31,7 @@ if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then fi fi -# Check if there are any changes in the remote repository -remote_changes=$(git fetch && git rev-list HEAD..origin/master --count) -if [ $remote_changes -gt 0 ]; then - read -p "There are $remote_changes remote change(s). Do you want to pull the changes? (y/n): " pull_changes - if [ "$pull_changes" == "y" ]; then - git pull origin master - fi -fi - -# Prompt for user input +#Prompt for user input read -p "Enter commit message: " message echo diff --git a/commit~ b/commit~ deleted file mode 100755 index d547e7a..0000000 --- a/commit~ +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/bash - -# Check if the --help flag is used -if [[ "$*" == *"--help"* ]]; then - echo "Usage: commit [options] [files]" - echo - echo "Options:" - echo " --help Display this help message" - echo " --verbose Display verbose output" - echo - echo "Description:" - echo " This script helps you stage, commit, and push changes to a Git repository." - echo " It prompts for a commit message and performs the necessary Git commands." - echo - echo "Examples:" - echo " commit => Commit all changes (assumes git add .)" - echo " commit file1.txt file2.txt => Stage and commit specific files" - echo " commit --verbose file.txt => Commit changes with verbose output" - echo - exit 0 -fi - -# Check if the current directory is a Git repository -if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then - read -p "The current directory is not a Git repository. Would you like to initialize it? (y/n): " initialize - if [ "$initialize" == "y" ]; then - git init - else - echo "Script terminated. Please initialize a Git repository to continue." - exit 1 - fi -fi - -# Prompt for user input -read -p "Enter commit message: " message -echo - -# Validate that the commit message is not empty -if [[ -z "$message" ]]; then - echo "Error: commit message cannot be empty" - exit 1 -fi - -# Validate the length of the commit message -if [[ ${#message} -gt 50 ]]; then - echo "Error: commit message exceeds the maximum length of 50 characters" - exit 1 -fi - -# Set git config for the current user -if ! git config --global user.name ""; then - echo "Error: unable to set git user name" - exit 1 -fi - -if ! git config --global user.email ""; then - echo "Error: unable to set git user email" - exit 1 -fi - -# Check if the --verbose flag is used -verbose_flag="" -for arg in "$@"; do - if [ "$arg" == "--verbose" ]; then - verbose_flag="--verbose" - break - fi -done - -# Remove the --verbose flag from the arguments -new_args=() -for arg in "$@"; do - if [ "$arg" != "--verbose" ]; then - new_args+=("$arg") - fi -done - -set -- "${new_args[@]}" - -# Check if any files are specified -if [ $# -eq 0 ]; then - # No files specified, assume all changes should be staged and committed - if [[ -n "$verbose_flag" ]]; then - # Display staging output when verbose flag is used - echo "--- Staging Output ---" - if ! git add .; then - echo "--- Changes staged unsuccessfully ---" - exit 1 - fi - echo "--- Changes staged successfully ---" - else - # Suppress output when verbose flag is not used - if ! git add . > /dev/null 2>&1; then - echo "Error: unable to add changes to the staging area" - echo "(Consider using the --verbose flag for more information)" - exit 1 - fi - fi - - # Check if any changes were added to the staging area - staged_files=$(git diff --cached --name-only) - if [[ -z "$staged_files" ]]; then - echo "No recent changes have been made to any files" - echo "(Consider using the --verbose flag for more information)" - exit 1 - else - echo "Changes staged successfully:" - echo "$staged_files" - fi -else - - # Stage specified files - if [[ -n "$verbose_flag" ]]; then - # Display staging output when verbose flag is used - echo "--- Staging Output ---" - if ! git add "$@"; then - echo "--- Changes staged unsuccessfully ---" - exit 1 - fi - echo "--- Changes staged successfully ---" - else - # Suppress output when verbose flag is not used - if ! git add "$@" > /dev/null 2>&1; then - echo "Error: unable to add changes to the staging area" - echo "(Consider using the --verbose flag for more information)" - exit 1 - fi - fi - - # Check if any changes were added to the staging area - staged_files=$(git diff --cached --name-only -- "$@") - if [[ -z "$staged_files" ]]; then - echo "No recent changes have been made to the specified file(s)" - echo "(Consider using the --verbose flag for more information)" - exit 1 - else - echo "Changes staged successfully:" - echo "$staged_files" - fi -fi -echo - -# Commit the changes with the commit message -if [[ -n "$verbose_flag" ]]; then - # Display commit output when verbose flag is used - echo "--- Commit Output ---" - git commit "$verbose_flag" -m "$message" - echo "--- Changes committed successfully ---" -else - # Suppress output when verbose flag is not used - if ! git commit -m "$message" > /dev/null 2>&1; then - echo "Error: unable to commit changes" - echo "(Consider using the --verbose flag for more information)" - exit 1 - fi - echo "Changes committed successfully" -fi -echo - -# Push the changes to the remote repository -if [[ -n "$verbose_flag" ]]; then - # Display push output when verbose flag is used - echo "--- Push Output ---" - git push - echo "--- Changes pushed successfully ---" -else - # Suppress output when verbose flag is not used - if ! git push > /dev/null 2>&1; then - echo "Error: unable to push changes to the remote repository" - echo "(Consider using the --verbose flag for more information)" - exit 1 - fi - echo "Changes pushed successfully" -fi -echo