Skip to content

Instantly share code, notes, and snippets.

@Fryguy
Created October 28, 2019 15:36
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 Fryguy/3490682c7761edeedba1ee28de5ed117 to your computer and use it in GitHub Desktop.
Save Fryguy/3490682c7761edeedba1ee28de5ed117 to your computer and use it in GitHub Desktop.
code-extractor
#!/bin/bash
# Also see https://github.com/juliancheal/code-extractor/blob/master/code_extractor.rb
SOURCE_URL=git@github.com:crystal-lang/crystal
SOURCE_REPO=crystal-lang/crystal
SOURCE_BRANCH=master
DEST_NAME=crystal-readline
DEST_DIR=$DEST_NAME
# List of all of the files and directories to extract, space-delimited
EXTRACTIONS="spec/std/readline_spec.cr src/readline.cr"
git clone -o upstream $SOURCE_URL $DEST_DIR
# Create branch for upstream deletion
cd $DEST_DIR
git checkout $SOURCE_BRANCH
git fetch upstream
git rebase upstream/$SOURCE_BRANCH
git checkout -b extract_$DEST_NAME
git rm -r $EXTRACTIONS
git commit -m "Extract $DEST_NAME"
# Cleanup
git remote rm upstream
for tag in $(git tag); do
git tag -d $tag
done
# Filter down to the extractions
git filter-branch --index-filter "
git read-tree --empty
git reset \$GIT_COMMIT -- $EXTRACTIONS
" --msg-filter "
cat -
echo
echo
echo \"(transferred from $SOURCE_REPO@\$GIT_COMMIT)\"
" -- $SOURCE_BRANCH -- $EXTRACTIONS
git checkout $SOURCE_BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment