-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgit-branch-description
executable file
·81 lines (67 loc) · 2.3 KB
/
git-branch-description
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Show a bunch of information about a given branch.
#
if [ -t 1 ]; then
readonly BOLD=`tput bold`
readonly YELLOW=`tput setaf 3`
readonly RESET=`tput sgr0`
readonly COLS=`tput cols`
else
readonly COLS=80
fi
if [ "$1" = "--help" ]; then
echo "Usage: `basename $0` <branch> <upstream>"
exit 0
fi
branch=$1
if [ -z "$branch" ]; then
branch=`git symbolic-ref --short HEAD`
fi
set -e
git log -n1 $branch > /dev/null
set +e
readonly first_date=`git reflog --format=format:%cd $branch | tail -n 2 | head -n 1`
readonly last_date=`git reflog -n 1 --format=format:%cd $branch`
echo "Branch $BOLD$branch$RESET"
echo "Branched: $YELLOW$first_date$RESET"
echo "Last commit: $YELLOW$last_date$RESET"
readonly description=`git config branch.$branch.description`
if [ -z "$description" ]; then
echo ""
echo "This branch has no description. Use:"
echo " git branch --edit-description <branch>"
else
echo ""
echo $description | fold -s
fi
echo ""
upstream=$2
if [ -z "$upstream" ]; then
upstream=`git symbolic-ref --short HEAD`
fi
if [ "$upstream" != "$branch" ]; then
printf '%*s' "${C:-$(($COLS/2-9))}" | tr ' ' =
printf "$YELLOW Unmerged commits$RESET "
printf '%*s\n' "${C:-$(($COLS/2-9))}" | tr ' ' =
readonly mergebase=`git merge-base $branch $upstream`
readonly branchsha=`git rev-list -n1 $branch`
readonly upstreamsha=`git rev-list -n1 $upstream`
if [ "$mergebase" = "$upstreamsha" ] || [ "$mergebase" = "$branchsha" ]; then
echo ""
echo "Branch $branch already merged into $upstream"
echo ""
else
echo "Commits on $RESET$BOLD$branch$RESET not in $BOLD$upstream$RESET:"
git cherry -v $upstream $branch | grep "^+" | sed -e "s/^+ /$YELLOW/" | sed -e "s/ /$RESET /"
echo ""
echo "Commits on $BOLD$branch$RESET already merged to $BOLD$upstream$RESET:"
git cherry -v $upstream $branch | grep "^-" | sed -e "s/^- /$YELLOW/" | sed -e "s/ /$RESET /"
echo ""
fi
fi
printf '%*s' "${C:-$(($COLS/2-5))}" | tr ' ' =
printf "${YELLOW} Activity $RESET"
printf '%*s\n' "${C:-$(($COLS/2-5))}" | tr ' ' =
git --no-pager reflog -v -n40 --date=relative --grep-reflog="from $branch" --grep-reflog="to $branch" HEAD
#git --no-pager reflog show --pretty --no-abbrev-commit $branch