#!/bin/bash . "$rootdir/include/JSON.sh" # $1 = list of tickets without prefix # $2 = prefix to prepend prepend_prefix() { echo "$1" | $SED -e "s/\(^\|[[:space:]]\+\)\([0-9]\+\)/\1$2-\2/g" } # $1 = message # $2 = ticket prefix extract_tickets() { local msg="$(echo "$1" | tr '\n' ' ')" local prefix="$2" local tickets= while true do echo "$msg" | grep -q "\<$prefix-[0-9]\+\>" || break tickets+="$(echo "$msg" | $SED -e "s/.*\<\($prefix-[0-9]\+\)\>.*$/\1/") " msg=$(echo "$msg" | $SED -e "s/^\(.*\)\<$prefix-[0-9]\+\>.*$/\1/") done echo $tickets } # $1 = list of tickets # $2 = ticket to remove remove_ticket() { echo "$1" | $SED -e "s/^\(.*\)\<$2\>[[:space:]]*\(.*\)$/\1 \2/;s/^[[:space:]]*//" } # $1 = ticket (with project prefix) get_ticket_title() { eval echo "$(wget -q -O - $JIRA_URL/rest/api/2/issue/$1 | tokenize | parse | sed -n 's/^\["fields","summary"\][[:space:]]*\(.*\)/\1/p')" } # analyses conflicts # $1 = source branch # $2 = target branch with conflicts # $3 = list of conflicts # $4 = list of revisions not merged yet # $5 = list of revisions merged # $6 = function to use for determining limiting revision # $7 = operator to use for comparing with limit # $8 = ticket prefix # $9 = non-empty if conflicts should be resolved analyse_conflicts() { ( src="$1" tgt="$2" limit=$($6 "$5") revs="$(subtract_list "$4" "$5")" cmpop="$7" prefix="$8" resolve="$9" OLDIFS="$IFS" IFS="" while read -r line do IFS="$OLDIFS" fqfile="$(echo "$line" | $SED 's/^....... *//')" file="${fqfile#$local_root/$tgt/}" reason= if echo "$line" | grep -q "^C...... " then do_message "Text conflict in " -n red elif echo "$line" | grep -q "^.C..... " then do_message "Property conflict in " -n red elif echo "$line" | grep -q "^......C " then if ! read -r reason then break fi reason="$(echo "$reason" | $SED 's/^[^>]*> *//')" do_message "Tree conflict in " -n red else do_message "Unknown conflict in " -n red fi do_message "$file" -n standout if [ -n "$reason" ] then do_message ": " -n red do_message "$reason" yellow else do_message ":" red fi tickets= for rev in $revs do [ $rev $cmpop $limit ] && break if [ -n "$(do_svn log -q -v -r $rev "$local_root/$src" | $SED -n "0,/^Changed paths:/d;/^.... $(echo "/$src/$file" | $SED 's/\//\\\//g')/p")" ] then for ticket in $(extract_tickets "$(get_log_message "$src" $rev)" "$prefix") do echo "$tickets" | grep -q "\<$ticket\>" || tickets+="$ticket " done fi done for ticket in $tickets do do_message " possible conflict with $ticket: " -n do_message "$(get_ticket_title "$ticket")" yellow done if [ -n "$resolve" ] then resolve_conflict "$fqfile" <&3 || exit 1 fi IFS="" done 3<&0 <<< "$3" ) } resolve_conflict() { local answer= while [ "$answer" != d -a "$answer" != a -a "$answer" != r ] do do_message "(d)elete, (r)esolve interactively or (a)bort? " -n standout read answer done case $answer in d) svn rm --force "$1" svn resolve --accept working "$1" return 0 ;; r) svn resolve "$1" || return 1 ;; *) return 1 ;; esac }