Skip to content

Instantly share code, notes, and snippets.

@fatso83
Forked from nivsherf/edit_sinon_docs.sh
Created September 7, 2018 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatso83/ce2d30a9de2d8fca994e8b6786b48d9f to your computer and use it in GitHub Desktop.
Save fatso83/ce2d30a9de2d8fca994e8b6786b48d9f to your computer and use it in GitHub Desktop.
Sinon Doc Editor
#!/bin/sh
# Usage example: ./edit_sinon_docs.sh stubs 4.1.1
# Will open stubs.md from 4.1.1 for editing and propagate the changes to later versions.
# 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
FILENAME=$1.md
FROM_VERSION=$2
EDITOR=`git config core.editor`
EDITOR=${EDITOR:-vim}
LATER_VERSIONS=($(ls -C _releases/*.md | xargs semver -c -r ">$FROM_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
$EDITOR _releases/v$FROM_VERSION/$FILENAME
prev=$FROM_VERSION
for ver in "${LATER_VERSIONS[@]}"
do
if ! git merge-file _releases/v$ver/$FILENAME .tmp_releases/v$prev/$FILENAME _releases/v$prev/$FILENAME ; then
$EDITOR _releases/v$ver/$FILENAME
fi
prev=$ver
done
git merge-file release-source/release/$FILENAME .tmp_releases/v$prev/$FILENAME _releases/v$prev/$FILENAME
rm -rf .tmp_releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment