Last active
November 28, 2017 12:15
-
-
Save valscion/dfc12ff5afd5d38e93439cbaab9cdd73 to your computer and use it in GitHub Desktop.
Depfu + Git LFS. MIT licensed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# MIT License | |
# | |
# Copyright (c) 2017 Vesa Laakso | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
set -eo pipefail | |
if [[ $# != "1" ]]; then | |
echo 'Usage: depfu-lfs <depfu-update-branch>' | |
echo '' | |
echo 'Examples:' | |
echo ' depfu-lfs webmock-3.1.1' | |
echo ' depfu-lfs depfu/update/webmock-3.1.1' | |
exit 0 | |
fi | |
# Stash any changes if exist | |
git stash save -q "stash-for:depfu-lfs" | |
# Store the result of whether anything was stashed | |
did_stash=false | |
if [[ "$(git stash list -n1)" == *"stash-for:depfu-lfs" ]]; then | |
did_stash=true | |
printf "\e[34mStashed changes\e[0m\n" | |
fi | |
branch="" | |
if [[ "$1" == "depfu/update/"* ]]; then | |
# https://stackoverflow.com/a/30524983 | |
if (git ls-remote --exit-code --heads origin "$1" > /dev/null); then | |
branch="$1" | |
fi | |
elif (git ls-remote --exit-code --heads origin "depfu/update/$1" > /dev/null); then | |
branch="depfu/update/$1" | |
fi | |
if [[ "$branch" == "" ]]; then | |
printf "\e[31mCould not find a remote depfu branch for '\e[33m$1\e[31m'\e[0m\n" | |
[[ $did_stash == true ]] && (git stash pop -q; printf "\e[34mRestored stashed changes\e[0m\n") | |
exit 1 | |
fi | |
git checkout "$branch" | |
git add vendor/cache/*.gem | |
git commit --reuse-message=HEAD --amend | |
git push --force-with-lease | |
git checkout - | |
git branch -D "$branch" | |
[[ $did_stash == true ]] && (git stash pop -q; printf "\e[34mRestored stashed changes\e[0m\n") | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment