Advertisement
eacousineau

Git Utilities - Setting Submodule Branches

Mar 2nd, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.46 KB | None | 0 0
  1. # TODO
  2. #   Fork off of gitify? Make 'git_aliases.sh', store hash in .gitconfig, if it doesn't match, then source it? Might be cumbersome...
  3. #   Can't figure out how to execute exported functions in a submodule foreach... Change git shell from sh to bash?
  4. #       http://stackoverflow.com/questions/6483443/how-to-launch-a-bash-function-using-git-alias
  5. #       Or just invoke 'bash -c' explicitly, if needed
  6. #   The command using 'eval' do not fully escape the sub-commands... Need to figure that out, look at git-submodule.sh
  7. #       Is it because of $@ instead of $* ?
  8.  
  9. function git-setup-basic()
  10. {
  11.     # Config stuff
  12.     # Push to current branch
  13.     # Alternative: 'tracking' (make sure to use `git push -u`?)
  14.     # See: http://longair.net/blog/2011/02/27/an-asymmetry-between-git-pull-and-git-push/
  15.     git config --global push.default current
  16.     # Extras
  17.     git config --global merge.tool meld
  18.     git config --global diff.tool meld
  19.     git config --global color.ui auto
  20.  
  21.     # Aliases
  22.     git config --global alias.sfe 'submodule foreach'
  23.     git config --global alias.sfer 'submodule foreach --recursive'
  24.     # Add everything (new files, deleted files) and then commit
  25.     git config --global alias.acommit '!git add -A && git commit -m'
  26.  
  27.     # branch-get based on: http://stackoverflow.com/a/13003854/170413
  28.     git config --global alias.branch-get 'rev-parse --abbrev-ref HEAD'
  29. }
  30.  
  31. # Set and checkout branches defined in .gitmodules
  32. # TODO
  33. #   Currently working with 1.7.9.5, but latest 1.8.2.rc1 from repo has new submodule branch features as well. Figure out how to integrate...
  34. #       Look at how `git pull` works with the new submodule.$name.update options, namely 'merge'
  35. #   How to make this recursive? Is it worth it?
  36. #   Use the same config style as git-submodule.sh, first check normal git config, then check .gitmodules? Would have to sync though...
  37. #   Look into how to split this up
  38. #   Specifying certain submodules? Or mark a set of submodules as the 'interesting' ones to push, pull, branch, commit, etc?
  39. #   Call in a submodule and know supermodule's path? GitPython?
  40. #   Add these as shell ! aliases?
  41. function git-sfe-branch-write() { git sfe 'git config -f $toplevel/.gitmodules submodule.$name.branch $(git branch-get)'; }
  42. function git-sfe-branch-checkout() { git sfe 'if branch=$(git config -f $toplevel/.gitmodules submodule.$name.branch 2>/dev/null); then git checkout $branch; fi'; }
  43.  
  44. function git-sfe-acommit { git sfe "git acommit \"$1\" || echo Skip"; }
  45.  
  46. # TODO Get these to match up, currently they don't
  47. #   git sfe "git add -A && git commit -m \"'ello\""
  48. #   git-tsfe "git add -A && git commit -m \"'ello\""
  49. #       This one works at top-level, but once it's passed to sfe, it's lost... Not sure why
  50.  
  51. # Submodule foreach, depth/child-first recursion
  52. function git-sfed() { git sfe "git sfe \"$@\" && eval \"$@\""; }
  53.  
  54. # Child-first recursion
  55. function git-tsfe() { git sfe "git sfe \"$@\" && eval \"$@\"" && echo "Entering supermodule '$(basename $PWD)'" && eval "$@"; }
  56. function git-tsfe-acommit() { git-tsfe "git acommit \"$1\" || echo Skip"; }
  57.  
  58. # Instead of 'git add -A ...', make a command that checks if directory is dirty, and if so call up 'git gui' - better practice for knowing what changes?
  59.  
  60. # Trying out mb14's suggestion: http://stackoverflow.com/a/14856390/170413
  61. # Issue with escaping the quotes as well - bash function fun...
  62. #   git-sfed-mb14 "git add -A && git commit -m \"'ello\""
  63. function git-sfed-mb14()
  64. {
  65.     git submodule foreach --recursive | tac | sed 's/Entering //' | xargs -n 1 bash -c "cd \$1 && eval \"$@\"" _
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement