Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # This hook does two things:
  4. #
  5. # 1. update the "info" files that allow the list of references to be
  6. # queries over dumb transports such as http
  7. #
  8. # 2. if this repository looks like it is a non-bare repository, and
  9. # the checked-out branch is pushed to, then update the working copy.
  10. # This makes "push" function somewhat similarly to darcs and bzr.
  11. #
  12. # To enable this hook, make this file executable by "chmod +x post-update".
  13.  
  14. git-update-server-info
  15.  
  16. is_bare=$(git-config --get --bool core.bare)
  17.  
  18. if [ -z "$is_bare" ]
  19. then
  20. # for compatibility's sake, guess
  21. git_dir_full=$(cd $GIT_DIR; pwd)
  22. case $git_dir_full in */.git) is_bare=false;; *) is_bare=true;; esac
  23. fi
  24.  
  25. update_wc() {
  26. ref=$1
  27. echo "Push to checked out branch $ref" >&2
  28. if [ ! -f $GIT_DIR/logs/HEAD ]
  29. then
  30. echo "E:push to non-bare repository requires a HEAD reflog" >&2
  31. exit 1
  32. fi
  33. if (cd $GIT_WORK_TREE; git-diff-files -q --exit-code >/dev/null)
  34. then
  35. wc_dirty=0
  36. else
  37. echo "W:unstaged changes found in working copy" >&2
  38. wc_dirty=1
  39. desc="working copy"
  40. fi
  41. if git diff-index --cached HEAD@{1} >/dev/null
  42. then
  43. index_dirty=0
  44. else
  45. echo "W:uncommitted, staged changes found" >&2
  46. index_dirty=1
  47. if [ -n "$desc" ]
  48. then
  49. desc="$desc and index"
  50. else
  51. desc="index"
  52. fi
  53. fi
  54. if [ "$wc_dirty" -ne 0 -o "$index_dirty" -ne 0 ]
  55. then
  56. new=$(git rev-parse HEAD)
  57. echo "W:stashing dirty $desc - see git-stash(1)" >&2
  58. ( trap 'echo trapped $$; git symbolic-ref HEAD "'"$ref"'"' 2 3 13 15 ERR EXIT
  59. git-update-ref --no-deref HEAD HEAD@{1}
  60. cd $GIT_WORK_TREE
  61. git stash save "dirty $desc before update to $new";
  62. git-symbolic-ref HEAD "$ref"
  63. )
  64. fi
  65.  
  66. # eye candy - show the WC updates :)
  67. echo "Updating working copy" >&2
  68. (cd $GIT_WORK_TREE
  69. git-diff-index -R --name-status HEAD >&2
  70. git-reset --hard HEAD
  71. git log --numstat |ruby -e 'print STDIN.read.gsub(%r!ssh://.*$!,"").gsub(/^(Author|Date):.*$\n?/,"")' > CHANGELOG)
  72. }
  73.  
  74. if [ "$is_bare" = "false" ]
  75. then
  76. active_branch=`git-symbolic-ref HEAD`
  77. export GIT_DIR=$(cd $GIT_DIR; pwd)
  78. GIT_WORK_TREE=${GIT_WORK_TREE-..}
  79. for ref
  80. do
  81. if [ "$ref" = "$active_branch" ]
  82. then
  83. update_wc $ref
  84. fi
  85. done
  86. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement