Skip to content

Commit 0085e59

Browse files
committed
Add git-custom-commands
1 parent 0772cbf commit 0085e59

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

git-custom-commands/git-echo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
# git-echo
3+
# From repo https://github.com/wilsonmar/git-utilities
4+
# A test program for git custom commands
5+
# Usage: git echo hello
6+
echo $1

git-custom-commands/git-squash

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
# git-squash
3+
# From https://coderwall.com/p/bt93ia/extend-git-with-custom-commands
4+
# Usage: git squash 3
5+
# squashes the last 3 commits (HEAD~3)
6+
7+
source "$(git --exec-path)/git-sh-setup"
8+
9+
USAGE="COMMITS"
10+
function _squash() {
11+
if [[ $# == 1 ]]; then
12+
if [[ -n $(git rev-parse --verify --quiet HEAD~$1) ]]; then
13+
git rebase -i HEAD~$1
14+
else
15+
die "HEAD~$1 does not exist"
16+
fi
17+
else
18+
usage
19+
fi
20+
}
21+
22+
_squash $1

git-custom-commands/graph-dag

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# graph-dag.sh
3+
# Draw a graphviz diagram of the Git DAG
4+
# See https://wilsonmar.github.io/git-utilities
5+
#
6+
# Labels consist of the short SHA1 and any refs.
7+
# Unreachable commits (ignoring the reflog) will be marked with an asterisk and
8+
# drawn with dashed lines.
9+
#
10+
# Largely stolen from https://git.wiki.kernel.org/index.php/ExampleScripts
11+
#
12+
# Usage:
13+
# git graph-dag HEAD~10.. | dot -Tpng | display -antialias
14+
#
15+
# Accepts any range or arguments that git rev-list accepts.
16+
17+
set -e
18+
19+
if [[ -z $@ ]] ; then
20+
echo -e "Usage: git graph-dag HEAD~10.. | dot -Tpng | display -antialias"
21+
exit 1
22+
fi
23+
24+
echo "digraph lattice {"
25+
26+
# Draw the DAG and connect parents
27+
git rev-list --parents "$@" |
28+
while read commit parents
29+
do
30+
for p in $parents
31+
do
32+
echo "n$commit -> n$p"
33+
done
34+
done
35+
36+
# Make pretty labels with the short sha1 and any refs
37+
git rev-list --pretty=format:"%H %h %d" "$@" | awk '
38+
BEGIN {
39+
command = "git fsck --unreachable --no-reflogs | cut -d\" \" -f3"
40+
while (command | getline unr) unreachable[unr] = 1
41+
close(command)
42+
}
43+
44+
!/^commit/ {
45+
refs = ""
46+
for (i=3; i<=NF; i++) refs = refs " " $i
47+
48+
unreachable[$1] == 1 ? isunr = 1 : isunr = 0
49+
50+
printf "n%s [shape=Mrecord, style=%s, label=\"{%s%s}\"]\n", \
51+
$1, \
52+
isunr == 1 ? "dashed" : "filled", \
53+
isunr == 1 ? "*" $2 : $2, \
54+
refs == "" ? "" : refs
55+
}'
56+
57+
echo "}"

0 commit comments

Comments
 (0)