forked from oldratlee/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvn-merge-stop-on-copy
executable file
·89 lines (76 loc) · 2.69 KB
/
svn-merge-stop-on-copy
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
#!/bin/bash
# @Function
# svn merge commit between version when source branch copy(--stop-on-copy)
# and head version of source branch.
#
# @Usage
# $ ./svnmerge.sh <source branch> [target branch]
# if no target branch, merge to current svn direcotry
#
# @online-doc https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/vcs.md#-svn-merge-stop-on-copy
# @author jiangjizhong(@jzwlqx)
# @author Jerry Lee (oldratlee at gmail dot com)
PROG="$(basename -- "$0")"
usage() {
cat <<EOF
Usage: ${PROG} <source branch> [target branch]
svn merge commit between version when source branch copy(--stop-on-copy)
and head version of source branch.
Source branch must be a remote branch.
Example:
${PROG} http://www.foo.com/project1/branches/feature1
# merge http://www.foo.com/project1/branches/feature1 to current svn directory
${PROG} http://www.foo.com/project1/branches/feature1 /path/to/svn/directory
# merge branch http://www.foo.com/project1/branches/feature1 to svn directory /path/to/svn/directory
# will prompt confirm for committing to target branch.
${PROG} http://www.foo.com/project1/branches/feature1 http://www.foo.com/project1/branches/feature2
# merge http://www.foo.com/project1/branches/feature1 to branch http://www.foo.com/project1/branches/feature2
# because http://www.foo.com/project1/branches/feature2 is remote url,
# will check out target branch to tmp directory, and prompt confirm for committing to target branch.
EOF
# shellcheck disable=SC2086
exit $1
}
[ $# -gt 2 ] && {
echo "too many arguments!"
usage 1
}
source_branch=$1
target=${2:-.}
[ -z "$source_branch" ] && {
echo "missing source branch argument!"
usage 1
}
[ -e "$source_branch" ] && {
echo "source branch must be a remote branch!"
usage 1
}
[ ! -d "$target" ] && {
workDir=$(mktemp -d) && svn co "$target" "$workDir" || {
echo "Fail to checkout target remote branch $target !"
exit 1
}
} || workDir="$target"
cleanupWhenExit() {
[ "$workDir" != "$target" ] && {
echo "rm tmp dir $workDir ."
rm -rf "$workDir"
}
}
trap cleanupWhenExit EXIT
svn_status_line=$(svn status --ignore-externals "$workDir" | grep -c -v ^X)
[ "$svn_status_line" -ne 0 ] && {
echo "svn work directory is modified!"
exit 1
}
cd "$workDir" &&
if from_version=$(svn log --stop-on-copy --quiet "$source_branch" | awk '$1~/^r[0-9]+/{print $1}' | tail -n1); then
echo "oldest version($from_version) of source branch $source_branch ."
echo "starting merge to $workDir ."
svn merge "-${from_version}:HEAD" "$source_branch"
else
echo "Fail to merge to work dir $workDir ."
exit 2
fi
read -r -p "Check In? (Y/N)" ci
[ "$ci" == "Y" ] && svn ci -m "svn merge -${from_version}:HEAD $source_branch"