diff --git a/functions.sh b/functions.sh index 6dd4ba1..5862f92 100644 --- a/functions.sh +++ b/functions.sh @@ -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 +} + diff --git a/install-synology-homebrew.sh b/install-synology-homebrew.sh index 749bf02..23b7e34 100755 --- a/install-synology-homebrew.sh +++ b/install-synology-homebrew.sh @@ -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..." @@ -106,10 +102,6 @@ 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." @@ -117,26 +109,6 @@ if [[ $DARWIN == 0 ]]; then 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" @@ -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 @@ -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-------------------------------"