#!/bin/bash
set -e -o pipefail

#
# Merge latest changes from upstream into the current branch.
#
# Usage:
# $ ./upgrade.sh [no-lock]
#

# Find root of app
APP_DIR=$( dirname "${BASH_SOURCE[0]}" )
APP_DIR=$( cd "$APP_DIR/.."; pwd )

# Go to root dir
cd "$APP_DIR"

# Check Prerequisites
bin/composer --version > /dev/null

# Sets the upstream branch if non exists
git remote show upstream >/dev/null 2>&1 || {
	echo "Adding a git remote for upstream repo (https://github.com/xyu/heroku-wp)."
	git remote add upstream https://github.com/xyu/heroku-wp.git
}

# Stash changes
git stash

# Merge in latest change from upstream
git fetch upstream
git merge --no-commit --squash --no-ff upstream/master

# Maybe rebuild composer lock file
if [ "$1" = "no-lock" ]; then
	echo "Skipping building of composer.lock..."
else
	bin/composer update --ignore-platform-reqs
	git add composer.lock
fi

git commit --message="Upgraded Heroku WP from Upstream"

# Apply local changes
echo "Applying local (uncommitted) changes"
git stash pop

#!/bin/bash
set -e -o pipefail

#
# Merge latest changes from upstream into the current branch.
#
# Usage:
# $ ./upgrade.sh [no-lock]
#

# Find root of app
APP_DIR=$( dirname "${BASH_SOURCE[0]}" )
APP_DIR=$( cd "$APP_DIR/.."; pwd )

# Go to root dir
cd "$APP_DIR"

# Check Prerequisites
bin/composer --version > /dev/null

# Sets the upstream branch if non exists
git remote show upstream >/dev/null 2>&1 || {
	echo "Adding a git remote for upstream repo (https://github.com/xyu/heroku-wp)."
	git remote add upstream https://github.com/xyu/heroku-wp.git
}

# Stash changes
git stash

# Merge in latest change from upstream
git fetch upstream
git merge --no-commit --squash --no-ff upstream/master

# Maybe rebuild composer lock file
if [ "$2" = "no-lock" ]; then
	echo "Skipping building of composer.lock..."
else
	bin/composer update --ignore-platform-reqs
fi

# Show changes
echo "Merged changes from upstream:"
git status

# Apply local changes
echo "Applying local (uncommitted) changes"
git stash pop

--- 
+++ 
@@ -32,14 +32,15 @@
 git merge --no-commit --squash --no-ff upstream/master
 
 # Maybe rebuild composer lock file
-if [ "$1" = "no-lock" ]; then
+if [ "$2" = "no-lock" ]; then
 	echo "Skipping building of composer.lock..."
 else
 	bin/composer update --ignore-platform-reqs
-	git add composer.lock
 fi
 
-git commit --message="Upgraded Heroku WP from Upstream"
+# Show changes
+echo "Merged changes from upstream:"
+git status
 
 # Apply local changes
 echo "Applying local (uncommitted) changes"
Make sure we commit the composer.lock file when upgrading
