├── LICENSE ├── README.md ├── git-psuh └── install.sh /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jack Serrino 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git-psuh 2 | ###Fix sloppy coding through negative reinforcement! 3 | 4 | Ever mistype `git push`? Want to fix that? 5 | 6 | **git-psuh has your back!** 7 | 8 | Be like Ivan and never make a mistake again. 9 | 10 | ![Never shoot the inaccurate](http://i1.kym-cdn.com/photos/images/newsfeed/000/856/438/e1c.jpg) 11 | 12 | *Every time* you mistype `git push`, this command will force-push an totally empty branch instead of your current branch. Not only that, but it also force pushes `master`! 13 | 14 | Of course, this is (almost) entirely hidden -- it looks like a normal push. 15 | 16 | ## Installation 17 | [What better way to install this but through a pipe to bash?](https://www.seancassidy.me/dont-pipe-to-your-shell.html) 18 | ``` 19 | > curl -k https://raw.githubusercontent.com/Detry322/git-psuh/master/install.sh | sh 20 | ``` 21 | ## Example Usage 22 | ``` 23 | > git add somefile 24 | > git commit -m "My awesome commmit" 25 | [master 3ac172f] My awesome commmit 26 | 1 file changed, 16 insertions(+) 27 | > git psuh 28 | Counting objects: 3, done. 29 | Delta compression using up to 8 threads. 30 | Compressing objects: 100% (3/3), done. 31 | Writing objects: 100% (3/3), 627 bytes | 0 bytes/s, done. 32 | Total 3 (delta 1), reused 0 (delta 0) 33 | To git@github.com:Detry322/git-psuh.git 34 | 312a7cc..3ac172f master -> master (forced update) 35 | > ls 36 | > echo "WHERE DID ALL MY FILES GO????" 37 | > git reset --hard origin/master 38 | > ls 39 | > echo "........" 40 | > git psuh undo 41 | ``` 42 | ## More details 43 | 44 | ``` 45 | usage: git psuh [undo] [--version] [--help] 46 | Fix mistakes through negative reinforcement! 47 | 48 | This command: 49 | - Commits any current changes 50 | - Moves master to master_old 51 | - Creates a new empty branch called master 52 | - Force pushes it 53 | - Also does the above to your current branch if you're not on master 54 | 55 | Undo should only be called immediately after a psuh, but 56 | it restores everything, and uncommits what was committed at the beginning 57 | ``` 58 | -------------------------------------------------------------------------------- /git-psuh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | version() { 3 | echo "psuh git plugin v1.0.0" 4 | } 5 | 6 | help() { 7 | echo "usage: git psuh [undo] [--version] [--help]" 8 | echo 9 | echo "Fix mistakes through negative reinforcement!" 10 | echo "This command:" 11 | echo " - Commits any current changes" 12 | echo " - Moves master to master_old" 13 | echo " - Creates a new empty branch called master" 14 | echo " - Force pushes it" 15 | echo " - Also does the above to your current branch if you're not on master" 16 | echo 17 | echo "Undo should only be called immediately after a psuh, but" 18 | echo "it restores everything, and uncommits what was committed at the beginning" 19 | } 20 | 21 | wipe_branch() { 22 | local current_branch="$1" 23 | git checkout $current_branch && 24 | touch .gitpsuh_holder && 25 | git add -A && 26 | git commit -m "Temporary commit" && 27 | git branch -m ${current_branch}_old && 28 | git checkout --orphan $current_branch && 29 | git reset --hard && 30 | git clean -fd && 31 | echo "Should have git pushed!" > .gitpsuh && 32 | git add .gitpsuh && 33 | git commit -m "Oops..." 34 | } 35 | 36 | psuh() { 37 | local current_branch=$(git rev-parse --abbrev-ref HEAD) 38 | { 39 | if [ "$current_branch" != "master" ] 40 | then 41 | wipe_branch master 42 | git push --force -u origin master 43 | fi 44 | wipe_branch $current_branch 45 | } > /dev/null 2>&1 46 | git push --force -u origin $current_branch | sed -e 's/forced update//g' 47 | } 48 | 49 | restore_branch() { 50 | local current_branch="$1" 51 | git checkout ${current_branch}_old && 52 | git branch -D ${current_branch} && 53 | git reset HEAD^ && 54 | rm .gitpsuh_holder && 55 | git branch -m ${current_branch} 56 | } 57 | 58 | undo() { 59 | echo "Undoing damages......." 60 | local current_branch=$(git rev-parse --abbrev-ref HEAD) 61 | if [ "$current_branch" != "master" ] 62 | then 63 | restore_branch master 64 | git push --force origin master 65 | fi 66 | restore_branch $current_branch 67 | git push --force origin $current_branch 68 | } 69 | 70 | main() { 71 | local subcommand="$1"; shift 72 | case $subcommand in 73 | "-h"|"--help") 74 | help; exit 0 75 | ;; 76 | "-v"|"--version") 77 | version; exit 0 78 | ;; 79 | "undo") 80 | undo; exit 0 81 | ;; 82 | esac 83 | psuh > /dev/null 84 | } 85 | 86 | main "$@" 87 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | echo "Installing git-psuh..." 2 | curl -k https://raw.githubusercontent.com/Detry322/git-psuh/master/git-psuh > /usr/local/bin/git-psuh 2>/dev/null 3 | chmod +x /usr/local/bin/git-psuh 4 | echo "Installation finished!" 5 | --------------------------------------------------------------------------------