forked from lbt/git-pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgp_common
106 lines (91 loc) · 2.64 KB
/
gp_common
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# gitpkg common shell functions and variables
# DISTRO should go to some config file
DISTRO=mer
pkg_branch=pkg-$DISTRO
ME=$(basename $0)
# Input: $pkgdir
# Output: $ver $rel
get_info_from_packaging() {
_pkgdir=${1:-.}
# See if there's a yaml or a .spec
_vrfile=$(cd $_pkgdir; find . -maxdepth 1 -name '*yaml' -print -quit)
_vrfile=${vrfile:-$(cd $_pkgdir; find . -maxdepth 1 -name '*spec' -print -quit)}
if [[ -f $_pkgdir/$_vrfile ]]; then
ver=$(grep Version: $_pkgdir/$_vrfile | cut -f2 -d: | tr -d ' ')
rel=$(grep Release: $_pkgdir/$_vrfile | cut -f2 -d: | tr -d ' ')
name=$(grep Name: $_pkgdir/$_vrfile | cut -f2 -d: | tr -d ' ')
echo "Found Version/Release: $ver-$rel in the packaging"
fi
}
# Input:
# Output:
# http://stackoverflow.com/a/3879077/337649
require_clean_work_tree() {
# Update the index
git update-index -q --ignore-submodules --refresh
local _err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --
then
echo >&2 "cannot $1: you have unstaged changes."
git diff-files --name-status -r --ignore-submodules -- >&2
_err=1
fi
# Disallow uncommitted changes in the index
if ! git diff-index --cached --quiet HEAD --ignore-submodules --
then
echo >&2 "cannot $1: your index contains uncommitted changes."
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2
_err=1
fi
if [ $_err = 1 ]
then
echo >&2 "Please commit or stash them before using $ME."
exit 1
fi
}
count_commits() {
git rev-list $1..$2 | wc -l
}
# Sets global initial_branch
save_initial_branch() {
initial_branch=$(git symbolic-ref HEAD)
initial_branch=${initial_branch##refs/heads/}
}
git_tag_cleanly() {
git tag $@
tag_cleanup_list+=" $1"
}
cleanup(){
echo "Attempting to switch back to $initial_branch in git"
git checkout -f $initial_branch
if [[ $tag_cleanup_list ]] ; then
echo "cleaning up tags: $tag_cleanup_list"
for tag in $tag_cleanup_list; do
git tag -d $tag
done
fi
if [[ $branch_cleanup_list ]]; then
echo "cleaning up branches: $branch_cleanup_list"
for branch in $branch_cleanup_list; do
git branch -D $branch
done
fi
}
# If the first arg is 'usage' then usage() is called right before exit
fatal() {
if [[ $1 == "usage" ]]; then
shift
usage=1
fi
if [[ $1 ]]; then
echo "$@"
else # support fatal << EOF
cat
fi
[[ $usage ]] && usage
exit 1
}
export GIT_AUTHOR_EMAIL=${GIT_AUTHOR_EMAIL:-$(git config user.email)}
export GIT_AUTHOR_NAME=${GIT_AUTHOR_NAME:-$(git config user.name)}