-
Notifications
You must be signed in to change notification settings - Fork 3
/
bzrtags.sh
executable file
·84 lines (70 loc) · 2.31 KB
/
bzrtags.sh
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
#!/bin/bash
##
## Bazaar Tags Check 2014.9.12
## Copyright (c) 2014 Renato Silva
## GNU GPLv2 licensed
##
## This program goes recursively through a directory hierarchy and checks all
## of the contained Bazaar branches for tag synchronization with parent branch.
## Usage and options:
##
## @script.name [options] [root directory if not current]
##
## --no-color Disable colors in output.
## -h, --help This help text.
##
print_name() {
local branch_name="$(basename "$(readlink -m "$1")")"
printf "${green_color}%$2s${normal_color} " "$branch_name:"
}
# Convert SSH locations to HTTPS
branch_location() {
location="$1"
if [[ "$location" = bzr+ssh:* ]]; then
location="${location/bzr+ssh/https}"
location="${location/\/+branch/}"
location="${location/bazaar./}"
fi
echo "$location"
}
check() {
branch="$(dirname "$0")"
config=".bzr/branch/branch.conf"
print_name "$branch" "-35"
cd "$branch"
[[ -f "$config" ]] && parent=$(grep ^parent_location "$config" | awk -F' *= *' '{ print $2 }')
if [[ -z "$parent" ]]; then
echo "No parent."
return
fi
echo >> "$local_tags"
echo >> "$parent_tags"
print_name "$branch" >> "$local_tags"
print_name "$branch" >> "$parent_tags"
echo >> "$local_tags"
echo >> "$parent_tags"
bzr tags >> "$local_tags"
bzr tags --directory $(branch_location "$parent") >> "$parent_tags"
cd - > /dev/null
echo "Done."
}
source easyoptions || exit
export -f branch_location
export -f print_name
export -f check
# Colorize text if standard output is a terminal and colors have not been disabled
if [[ -t 1 && -z "$no_color" ]]; then
export normal_color="\e[0m"
export green_color="\e[0;32m"
export diff_command="colordiff"
fi
temp_dir="/tmp/bzrtags.$(date +%s.%N)"
export local_tags="$temp_dir/tags.local.txt"
export parent_tags="$temp_dir/tags.parent.txt"
mkdir "$temp_dir"
touch "$local_tags"
touch "$parent_tags"
trap "rm -rf $temp_dir" EXIT
find "${arguments[0]:-.}" -name ".bzr" -type d -print0 | xargs -0 -l -r bash -c check | iconv -f cp850 -t iso-8859-1
echo; ${diff_command:-diff} -U1000000000 "${local_tags}" "$parent_tags" | sed -E "s/(\e.*)?---.*/--- Local tags/" | sed -E "s/(\e.*)?\+\+\+.*/+++ Parent tags/" | grep -v "@@.*@@"
exit 0