blob: 41b031fe73515b767e5f5183999e4a9a48b11c59 [file] [log] [blame]
Eitan Adler3fc60b52012-04-17 00:24:58 -04001#!/usr/bin/env bash
Robert R Evansa4d02422010-10-02 15:07:29 -07002
3function git_remote {
4 echo "Running: git remote add origin ${GIT_HOSTING}:$1.git"
5 git remote add origin $GIT_HOSTING:$1.git
6}
7
8function git_first_push {
9 echo "Running: git push origin master:refs/heads/master"
10 git push origin master:refs/heads/master
11}
12
13function git_remove_missing_files() {
14 git ls-files -d -z | xargs -0 git update-index --remove
Robert R Evans034a3b02010-10-04 12:47:25 -070015}
16
17# Adds files to git's exclude file (same as .gitignore)
18function local-ignore() {
19 echo "$1" >> .git/info/exclude
Florian Baumannaaa10712010-11-22 13:07:08 +010020}
21
22# get a quick overview for your git repo
23function 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 Baumannb2857a32011-03-27 20:44:17 +020057function git_stats {
58# awesome work from https://github.com/esc/git-stats
59# including some modifications
60
61if [ -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
91else
92 echo "you're currently not in a git repository"
93fi
94}
David DeSandro11b59552011-06-20 16:13:34 -040095