Guest User

Untitled

a guest
Feb 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1.  
  2. # Log some output to stderr, prefix command name
  3. warn() {
  4. echo "`basename $0`: $@" 2>&1
  5. }
  6. # Error with some string
  7. die() {
  8. warn $1
  9. exit
  10. }
  11.  
  12. # Checks if a branch is dirty.
  13. is_dirty() {
  14. git diff-index --quiet HEAD
  15. }
  16.  
  17. # Get all the branches in a way we can iterate over
  18. branch_names() {
  19. git branch | sed -e 's/[ \*]*//g'
  20. }
  21.  
  22. # Get all the remote branch names
  23. remote_branch_names() {
  24. git branch -r | sed -e 's/[ \*]*//g'
  25. }
  26.  
  27. # Get the current branch name.
  28. current_branch_name() {
  29. git branch | grep "^\*" | sed -e 's/[ \*]*//g'
  30. }
  31.  
  32. # Checks if our branch is dirty, if so, stashes it
  33. stash_it() {
  34. [ -z "$1" ] && die "stash_it(): Must supply an argument"
  35. VERB=$1
  36.  
  37. is_dirty
  38. if [ X"$?" = X"1" ]; then
  39. CURRENT_BRANCH_NAME=`current_branch_name`
  40. warn "Stashing branch '${CURRENT_BRANCH_NAME}'"
  41. git stash save "git-simple: stashing before ${VERB}"
  42. fi
  43. }
Add Comment
Please, Sign In to add comment