Updated gpull.
This commit is contained in:
19
gpull
19
gpull
@@ -5,13 +5,20 @@
|
||||
# Usage:
|
||||
# ./gpull [repo] [remote] [branch]
|
||||
#
|
||||
# repo – (optional) Directory of repository to pull, default is current directory.
|
||||
# repo – (optional) Directory of repository to pull, default is current
|
||||
directory.
|
||||
# remote – (optional) Remote name, default is origin.
|
||||
# branch – (optional) Branch name, default is current branch.
|
||||
#
|
||||
# The script will pull the specific remote branch into the local repository.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Function to handle errors gracefully without closing terminal
|
||||
handle_error() {
|
||||
echo "Error: $1"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Get command line arguments
|
||||
repo_dir=${1:-$(pwd)}
|
||||
remote=${2:-origin}
|
||||
@@ -19,15 +26,15 @@ branch=${3:-}
|
||||
|
||||
# Change to the specified directory
|
||||
if [ ! -d "$repo_dir" ]; then
|
||||
echo "Error: Directory '$repo_dir' does not exist."
|
||||
handle_error "Directory '$repo_dir' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$repo_dir" || exit 1
|
||||
cd "$repo_dir" || { handle_error "Failed to change to directory '$repo_dir'."; exit 1; }
|
||||
|
||||
# Check if the current directory is a git repository
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
echo "Error: '$repo_dir' is not a git repository."
|
||||
handle_error "'$repo_dir' is not a git repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -35,7 +42,7 @@ fi
|
||||
if [ -z "$branch" ]; then
|
||||
branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
if [ "$branch" = "HEAD" ]; then
|
||||
echo "Error: Not currently on a branch. Please specify a branch to pull."
|
||||
handle_error "Not currently on a branch. Please specify a branch to pull."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@@ -49,6 +56,6 @@ git pull "$remote" "$branch"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully pulled changes from $remote/$branch"
|
||||
else
|
||||
echo "Error: Failed to pull changes from $remote/$branch"
|
||||
handle_error "Failed to pull changes from $remote/$branch"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user