From 8871180029c07becaa9def688c0b27a9203b5b0c Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 19 Apr 2014 02:48:59 +0200 Subject: [PATCH] oojs-update.sh: Replace target dir instead of adding file copies * A command like "cp dist/* $TARGET_DIR" does not remove files that were deleted in the release dist. Using rsync instead. Though addition can happen, deletion should never happen as we refer to these files in Resources.php. But we also shouldn't leave behind old files mixed with new files, so delete them. Our structure unit tests for resources take care of catching references to files that don't (or no longer) exist. * Use bash -n instead of != "". * Refactor slightly to make it re-usable in other projects without too much modification (only REPO_DIR and TARGET_DIR need updating, the rest is generic now). * The "git commit " doesn't properly take care of staging deletion of files removed by the update script, nor does it reliably (?) stage new files. Instead using a combination of "git add -u " (The -u stages deletion and modifcation of tracked files), and "git add " (stages modification and creation of files in that directory). Change-Id: Ieb20978c887c5a141f31cab704b8d239f1572af0 --- maintenance/resources/update-oojs.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/maintenance/resources/update-oojs.sh b/maintenance/resources/update-oojs.sh index f26350f848..2c50002986 100755 --- a/maintenance/resources/update-oojs.sh +++ b/maintenance/resources/update-oojs.sh @@ -1,23 +1,24 @@ #!/usr/bin/env bash -if [ "$2" != "" ] +if [ -n "$2" ] then + # Too many parameters echo >&2 "Usage: $0 []" exit 1 fi -MW_DIR=$(cd $(dirname $0)/../..; pwd) # e.g. mediawiki-core/ -NPM_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'mw-update-oojs'` # e.g. /tmp/mw-update-oojs.rI0I5Vir - -# Prepare MediaWiki working copy -cd $MW_DIR -git reset resources/lib/oojs/ && git checkout resources/lib/oojs/ && git fetch origin || exit 1 +REPO_DIR=$(cd $(dirname $0)/../..; pwd) # Root dir of the git repo working tree +TARGET_DIR=resources/lib/oojs # Destination relative to the root of the repo +NPM_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'update-oojs'` # e.g. /tmp/update-oojs.rI0I5Vir +# Prepare working tree +cd $REPO_DIR && +git reset $TARGET_DIR && git checkout $TARGET_DIR && git fetch origin && git checkout -B upstream-oojs origin/master || exit 1 # Fetch upstream version cd $NPM_DIR -if [ "$1" != "" ] +if [ -n "$1" ] then npm install oojs@$1 || exit 1 else @@ -32,14 +33,14 @@ then fi # Copy file(s) -mv ./node_modules/oojs/dist/* $MW_DIR/resources/lib/oojs/ || exit 1 - -# Generate commit -cd $MW_DIR || exit 1 +rsync --recursive --delete --force ./node_modules/oojs/dist $REPO_DIR/$TARGET_DIR || exit 1 # Clean up temporary area rm -rf $NPM_DIR +# Generate commit +cd $REPO_DIR || exit 1 + COMMITMSG=$(cat <