profile-git 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. git-ignore() {
  2. local site="https://raw.githubusercontent.com/github/gitignore/master"
  3. if [[ $1 == "--global" ]]; then
  4. shift
  5. ignore_file=${HOME}/.gitignore_global
  6. site+="/Global"
  7. else
  8. ignore_file="./.gitignore"
  9. fi
  10. echo "## ${1}.gitignore" >> "${ignore_file}"
  11. wget -qO- "${site}/${1}.gitignore" >> "${ignore_file}"
  12. }
  13. git-inject-clang-format() {
  14. local fromdir todir
  15. fromdir=${HOME}/.dotfiles/resources
  16. todir=.git/hooks
  17. mkdir -p "${todir}/pre-commit.d"
  18. git config hooks.clangformat.style file
  19. cp ${fromdir}/clang-format.template ./.clang-format
  20. cp ${fromdir}/pre-commit-all.hook ${todir}/pre-commit
  21. cp ${fromdir}/clang-format.hook ${todir}/pre-commit.d/clang-format
  22. }
  23. git-create() {
  24. mkcd "${1}"; shift
  25. git init
  26. echo '## User Defined Gitignore' > .gitignore
  27. local message="Initializing repository"
  28. if [[ $# -ge 1 ]]; then
  29. for i in "$@"; do git-ignore "${i}"; done
  30. message+=" with ignore lists: [ $1"
  31. [[ $# -eq 1 ]] || message+="$(printf ", %s" "${@:2}")"
  32. message+=" ]"
  33. fi
  34. maybe_do git-ignore-local
  35. git add .gitignore
  36. git commit -m "${message}"
  37. }
  38. git-sync-release() {
  39. rel="release/${1}"
  40. br="$(git branch | grep '^\*' | cut -c3-)"
  41. # Confirm that this is a real branch
  42. (git branch -r | grep "${rel}" &>/dev/null) || return 1
  43. # Merge dev
  44. # Make sure that we're not doing a weird clobber
  45. git checkout "${rel}" || return 2
  46. # Sanity check...
  47. git pull
  48. git merge --ff-only origin/dev || return 3
  49. # Update origin:release
  50. git push
  51. git checkout "${br}"
  52. # Don't delete if we're on this branch
  53. [[ "${br}" == "${rel}" ]] || git branch -D "${rel}"
  54. }
  55. alias git-graph="git log --graph --pretty=oneline --abbrev-commit --decorate --all"
  56. alias git-history-graph="git log --graph --pretty='format:%C(auto)%h (%<(50,trunc)%s, %ad)%d' --abbrev-commit --decorate --all"
  57. git-weeks-ago() {
  58. weeks="${1:-1}"
  59. end="$(date +"%Y-%m-%d" --date="${weeks} weeks ago Sunday")"
  60. begin="$(date +"%Y-%m-%d" --date="$((weeks+1)) weeks ago Sunday")"
  61. echo "--after ${begin} --before ${end}"
  62. }
  63. alias git-cleanup='(git branch --merged | egrep -v "(^\*|^\+|master|dev)" | xargs git branch -d); (git fetch --prune 2>&1 | grep deleted | sed "s/.*-> origin\///" | xargs git branch -D)'