profile-git 2.1 KB

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