Advertisement
pro-odoo

Untitled

Oct 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. function _checkout() {
  2. clear
  3. # Determine the name of the new branch
  4. if [ -z "$1" ]; then
  5. new_branch="$(__git_both_repo branch | grep '^\(*\|\s\)' | sort -u | fzf)"
  6. new_branch="${new_branch:2}"
  7. [ -z "$new_branch" ] && exit
  8. else
  9. new_branch="$1"
  10. fi
  11.  
  12. # Base branch (master, saas-15, ...)
  13. base_branch="$(__get_base_branch "$new_branch")"
  14. # Current branch
  15. current_branch="$(__get_current_branch)"
  16.  
  17. echo -e "Checkout branch $GREEN$new_branch$DEFAULT..."
  18.  
  19. repositories="$ODOO_PATH $ENTERPRISE_PATH"
  20. for repo in $repositories; do
  21. repo_name="$(__get_repo_name "$repo")"
  22.  
  23. # Stash
  24. __save-stash $repo $repo_name $current_branch
  25.  
  26. # Check existance of the branch
  27. git -C $repo rev-parse --verify "$new_branch" > /dev/null 2>&1
  28. if [[ "$?" != "0" ]]; then
  29. echo -e "[$BLUE$repo_name$DEFAULT] Would you like to create $GREEN$new_branch$DEFAULT ? y/n "
  30. read create
  31. if [[ "$create" == "y" ]]; then
  32. remote="$(git -C $repo remote -v | grep -m 1 -v dev | awk '{print $1}')"
  33. git -C $repo branch $new_branch $remote/$base_branch --no-track
  34. else
  35. new_branch=$current_branch
  36. fi
  37. fi
  38.  
  39. # Checkout
  40. echo -e "[$BLUE$repo_name$DEFAULT:$GREEN$new_branch$DEFAULT] Checkout..."
  41. git -C $repo checkout $new_branch > /dev/null 2>&1
  42.  
  43. # Remove files
  44. __clean-repo $repo $repo_name $new_branch
  45.  
  46. # Apply stash
  47. __apply-stash $repo $repo_name $new_branch
  48. done
  49.  
  50. echo -e "Checkout branch $GREEN$new_branch$DEFAULT done"
  51. _git status
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement