Skip to content

Instantly share code, notes, and snippets.

@nivsherf
Created September 8, 2018 09:06
Show Gist options
  • Save nivsherf/66cb49196ad4683652318164bf83ead7 to your computer and use it in GitHub Desktop.
Save nivsherf/66cb49196ad4683652318164bf83ead7 to your computer and use it in GitHub Desktop.
Sinon doc change propagation - the other way around
#!/bin/sh
# Usage example: ./propagate_docs_change_top_down.sh 4.1.1 stubs
# Will propagate changes already made in release-source/release/stubs.md from to earlier versions, until and including 4.4.1
# If a section name is omitted, the release.md file will be used.
# Make sure you have SINON_HOME pointing to the repository root.
# You'll need git and the npm "semver" package installed (npm i -g semver)
cd $SINON_HOME/docs
EARLIEST_VERSION=$1
FILENAME=/$2.md
if [ -z "$2" ]; then FILENAME=.md; fi
EDITOR=`git config core.editor`
EDITOR=${EDITOR:-vim}
VERSIONS=($(ls -C _releases/*.md | xargs semver -c -r ">=$EARLIEST_VERSION"))
# Make a temp copy of the originals so that they can be used as the common parent in the 3-way merge
cp -r _releases .tmp_releases
PREV_FILE=release-source/release$FILENAME
COMMON_ANCESTOR=_releases/v${VERSIONS[${#VERSIONS[@]}-1]}$FILENAME
for ((i=${#VERSIONS[@]}-1; i>=0; i--));
do
CUR_VER=${VERSIONS[$i]}
if ! git merge-file _releases/v$CUR_VER$FILENAME $COMMON_ANCESTOR $PREV_FILE ; then
$EDITOR _releases/v$CUR_VER$FILENAME
fi
PREV_FILE=_releases/v$CUR_VER$FILENAME
COMMON_ANCESTOR=.tmp_releases/v$CUR_VER$FILENAME
done
rm -rf .tmp_releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment