Skip to content

Instantly share code, notes, and snippets.

@CyrusRoshan
Last active June 7, 2016 01:24
Show Gist options
  • Save CyrusRoshan/1e1ab2d5311164e989d0feb0df4f936f to your computer and use it in GitHub Desktop.
Save CyrusRoshan/1e1ab2d5311164e989d0feb0df4f936f to your computer and use it in GitHub Desktop.
Zsh functions for making it easy to work with large godeps in production. Add to .zshrc and use in your normal workflow
# Just like regular godep, use at root of repo
godep() {
case $* in
rebuild* ) shift; command rm -rf Godeps && rm -rf vendor && godep save;;
remove* ) shift; command rm -rf Godeps && rm -rf vendor;;
* ) command godep "$@";;
esac
return
}
# Usage: create godep-rebuild branch (or use a custom branch name) from a specific commit.
# This commit should be located at the point where you'd normally merge your new branch into dev or master.
# Make your changes on your branch for your new fix or feature, commit changes, then run depmerge.
# Submit your pr to the godep-rebuild (or custom branch name) on github.
# Github incorrectly shows more file changes thn actually exist between the two diffs, so depmerge automatically prints out a list of the changed files between the two branches on each run.
# You'll have to use git diff or a visual diff tool to view file changes instead of github's web client, if you want to view a proper diff.
# On the plus side, this method works for situations where you've commited both package files and vendored dependencies in the same commit, and separates those changes easily while preserving commit history :D
depmerge() {
originalBranch=$(git symbolic-ref --short HEAD);
if [[ "$@" != "" ]];
then
godepBranch=$@;
else
godepBranch="godep-rebuild";
fi
git checkout $godepBranch &&
godep remove
git checkout $originalBranch Godeps &&
git checkout $originalBranch vendor &&
git add Godeps &&
git add vendor &&
git commit -m "Godep rebuild.";
git checkout $originalBranch &&
branchDiff=$(git diff --name-status $godepBranch..$originalBranch | cat) &&
echo $branchDiff &&
# copy branch diff command here instead of using zsh var because if we have too many diffs, zsh will error with "command too long"
changedFileCount=$(git diff --name-status $godepBranch..$originalBranch | cat | wc -l) &&
echo $changedFileCount total files changed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment