Skip to content

Commit

Permalink
added git check to pull latest
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCee committed Dec 29, 2024
1 parent 1c6c02d commit 3267d7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
27 changes: 27 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,30 @@ install_brew_and_packages() {
echo "Homebrew and packages installation completed successfully."
}

func_git_commit_check() {

echo "${INFO} Git Commit: $(git rev-parse --short HEAD)"

branch=$(git branch --show-current)

# Fetch latest changes
git fetch origin

# Check if the branch is behind
BEHIND=$(git rev-list --count $branch..origin/$branch)

if [ "$BEHIND" -gt 0 ]; then
echo "Your branch is $BEHIND commit(s) behind origin/$branch. Overwriting local changes..."
git reset --hard origin/$branch

if [ $? -eq 0 ]; then
echo "Local branch successfully overwritten with origin/$branch."
else
echo "❌ Error during reset. Please check for issues."
exit 1
fi
else
echo "✅ Your branch is up to date with origin/$branch."
fi
}

32 changes: 4 additions & 28 deletions install-synology-homebrew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ if [[ $DARWIN == 0 ]]; then
error=true
fi

# Check if Homebrew is installed
if [[ ! -x $HOMEBREW_PATH/bin/brew ]]; then
echo "Homebrew is not installed. Checking environment for requirements..."

# Check if Git is installed
if ! git --version > /dev/null 2>&1; then
echo "Git not installed. Adding the SynoCommunity repository..."
Expand Down Expand Up @@ -106,37 +102,13 @@ if [[ $DARWIN == 0 ]]; then
echo "✅ Git is already installed."
fi # Closes 'if ! git --version'

else
echo "✅ Homebrew is already installed."
fi # Closes 'if [[ ! -x $HOMEBREW_PATH/bin/brew ]]'

# If any error occurred, exit with status 1 (triggers func_cleanup_exit)
if $error ; then
echo "❌ Exiting due to errors."
exit 1
fi
fi # end $DARWIN=0

echo "${INFO} Git Commit: $(git rev-parse --short HEAD)"
# Fetch latest updates from remote (but don't merge)
git fetch origin

# Get the branch name
branch=$(git branch --show-current)

# Compare local branch with remote
if git rev-list --count $branch..origin/$branch > /dev/null 2>&1; then
BEHIND=$(git rev-list --count $branch..origin/$branch)

if [ "$BEHIND" -gt 0 ]; then
echo "⚠️ Your branch is $BEHIND commit(s) behind origin/$branch."
else
echo "✅ Your branch is up to date with origin/$branch."
fi
else
echo "❌ Error: Unable to compare with remote. Check if the branch exists on remote."
fi

# Define the location of YAML
CONFIG_YAML_PATH="./config.yaml"

Expand Down Expand Up @@ -216,6 +188,8 @@ fi

echo "Starting $( [[ "$selection" -eq 1 ]] && echo 'Minimal Install' || echo 'Full Setup' )..."

func_git_commit_check

export HOMEBREW_NO_ENV_HINTS=1
export HOMEBREW_NO_AUTO_UPDATE=1

Expand Down Expand Up @@ -250,6 +224,8 @@ if [[ -d /home/linuxbrew ]]; then
fi
fi # end DARWIN=0

[[ $DARWIN == 1 ]] && func_git_commit_check

install_brew_and_packages

echo "--------------------------PATH SET-------------------------------"
Expand Down

0 comments on commit 3267d7b

Please sign in to comment.