Eitan Adler | 3fc60b5 | 2012-04-17 00:24:58 -0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Robert R Evans | a4d0242 | 2010-10-02 15:07:29 -0700 | [diff] [blame] | 2 | |
| 3 | function git_remote { |
| 4 | echo "Running: git remote add origin ${GIT_HOSTING}:$1.git" |
| 5 | git remote add origin $GIT_HOSTING:$1.git |
| 6 | } |
| 7 | |
| 8 | function git_first_push { |
| 9 | echo "Running: git push origin master:refs/heads/master" |
| 10 | git push origin master:refs/heads/master |
| 11 | } |
| 12 | |
| 13 | function git_remove_missing_files() { |
| 14 | git ls-files -d -z | xargs -0 git update-index --remove |
Robert R Evans | 034a3b0 | 2010-10-04 12:47:25 -0700 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | # Adds files to git's exclude file (same as .gitignore) |
| 18 | function local-ignore() { |
| 19 | echo "$1" >> .git/info/exclude |
Florian Baumann | aaa1071 | 2010-11-22 13:07:08 +0100 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | # get a quick overview for your git repo |
| 23 | function git_info() { |
| 24 | if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then |
| 25 | # print informations |
| 26 | echo "git repo overview" |
| 27 | echo "-----------------" |
| 28 | echo |
| 29 | |
| 30 | # print all remotes and thier details |
| 31 | for remote in $(git remote show); do |
| 32 | echo $remote: |
| 33 | git remote show $remote |
| 34 | echo |
| 35 | done |
| 36 | |
| 37 | # print status of working repo |
| 38 | echo "status:" |
| 39 | if [ -n "$(git status -s 2> /dev/null)" ]; then |
| 40 | git status -s |
| 41 | else |
| 42 | echo "working directory is clean" |
| 43 | fi |
| 44 | |
| 45 | # print at least 5 last log entries |
| 46 | echo |
| 47 | echo "log:" |
| 48 | git log -5 --oneline |
| 49 | echo |
| 50 | |
| 51 | else |
| 52 | echo "you're currently not in a git repository" |
| 53 | |
| 54 | fi |
| 55 | } |
| 56 | |
Florian Baumann | b2857a3 | 2011-03-27 20:44:17 +0200 | [diff] [blame] | 57 | function git_stats { |
| 58 | # awesome work from https://github.com/esc/git-stats |
| 59 | # including some modifications |
| 60 | |
| 61 | if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then |
| 62 | echo "Number of commits per author:" |
| 63 | git --no-pager shortlog -sn --all |
| 64 | AUTHORS=$( git shortlog -sn --all | cut -f2 | cut -f1 -d' ') |
| 65 | LOGOPTS="" |
| 66 | if [ "$1" == '-w' ]; then |
| 67 | LOGOPTS="$LOGOPTS -w" |
| 68 | shift |
| 69 | fi |
| 70 | if [ "$1" == '-M' ]; then |
| 71 | LOGOPTS="$LOGOPTS -M" |
| 72 | shift |
| 73 | fi |
| 74 | if [ "$1" == '-C' ]; then |
| 75 | LOGOPTS="$LOGOPTS -C --find-copies-harder" |
| 76 | shift |
| 77 | fi |
| 78 | for a in $AUTHORS |
| 79 | do |
| 80 | echo '-------------------' |
| 81 | echo "Statistics for: $a" |
| 82 | echo -n "Number of files changed: " |
| 83 | git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f3 | sort -iu | wc -l |
| 84 | echo -n "Number of lines added: " |
| 85 | git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f1 | awk '{s+=$1} END {print s}' |
| 86 | echo -n "Number of lines deleted: " |
| 87 | git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f2 | awk '{s+=$1} END {print s}' |
| 88 | echo -n "Number of merges: " |
| 89 | git log $LOGOPTS --all --merges --author=$a | grep -c '^commit' |
| 90 | done |
| 91 | else |
| 92 | echo "you're currently not in a git repository" |
| 93 | fi |
| 94 | } |
David DeSandro | 11b5955 | 2011-06-20 16:13:34 -0400 | [diff] [blame] | 95 | |