--- a/pull-request.sh Mon Jun 23 01:32:45 2014 +0300 +++ b/pull-request.sh Sun Jul 06 20:46:36 2014 +0300 @@ -26,28 +26,29 @@ # Get all heads and filter merges out since we don't generally want to post # pull requests for those. -allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g') +# allheads=$(hg heads --template '{node}@{parents}\n' |sed 's@ @#@g') +heads=$(hg heads --template '{node}\n') i=0 -for head in $allheads -do - if [ "$(echo $head |sed 's@#@ @g' |wc -w)" -le "1" ] - then - heads="${heads}$(echo $head |cut -f 1 -d '@') " - fi -done +#for head in $allheads +#do +# if [ "$(echo $head |sed 's@#@ @g' |wc -w)" -le "1" ] +# then +# heads="${heads}$(echo $head |cut -f 1 -d '@') " +# fi +#done -if [ -z "$heads" ] -then - echo "No non-merge heads. Nothing to do." - exit 0 -fi +#if [ -z "$allheads" ] +#then +# echo "No non-merge heads. Nothing to do." +# exit 0 +#fi numheads=$(echo $heads |wc -w) # Ask the user which head to request pull of. We do this even if there is just # one head, to give the user a chance to review exactly what is being submitted. -echo "There are $numheads non-merge heads:" +echo "There are $numheads heads:" for head in $heads do @@ -79,12 +80,53 @@ title=$(hg log -r ${head} -r tip --template '{desc}') source_repo=$(hg paths default |rev |cut -d '/' -f 1,2 |rev) -while [ "$(echo $title |wc -c)" -gt "255" ] -do - echo "Pull request title is too long, please input a new title" - echo -n "new title: " - read title -done +titlefile=$(tempfile) +echo "$title" >$titlefile +vim $titlefile +title=$(cat $titlefile) + +if [ -z "$title" ] +then + echo "no title given" + exit 1 +fi + +# Ensure history is compressed.. +upstream_tip=$(hg log -r upstream_tip --template '{node}\n') +parents=$(hg log -r $head --debug --template '{parents}\n') +p1=$(hg log -r $(echo $parents |cut -f 1 -d ' ') --template '{node}\n') +p2=$(hg log -r $(echo $parents |cut -f 2 -d ' ') --template '{node}\n') + +if [ "$p1" != "$upstream_tip" -a "$p2" != "$upstream_tip" ] +then + echo -n "history isn't compressed! compress now? [y/n] " + read answer + if [ "$answer" = "y" ] + then + bookmarks=$(hg log -r $head --template '{bookmarks}') + oldhead=$head + hg up -r upstream_tip && + hg revert --all -r $head && + hg commit -m "$title" || exit 1 + head=$(hg id -i) + hg bookmarks -f $bookmarks + hg up -r $oldhead && hg commit -m "- closed head $oldhead" --close-branch && hg up -r $head + fi +fi + +# Ensure the head is pushed! +if [ -n $( hg outgoing --template '{node}\n' 2>/dev/null |grep $head ) ] +then + echo -en "$head is not pushed!\npush now? [y/n] " + read answer + if [ "$answer" != "y" ] + then + echo "abort: head is not pushed" + exit 1 + fi + + hg push -r $head -f +fi echo "Requesting pull of $head" @@ -95,9 +137,9 @@ |sed "s@{{HEAD}}@${head}@") # Get bitbucket credentials -echo -n "Username: " +echo -n "username: " read username -echo -n "Password: " +echo -n "password: " read -s password echo @@ -111,4 +153,4 @@ -d "$json" \ -o "$response" \ "https://api.bitbucket.org/2.0/repositories/${upstream}/pullrequests" \ - >/dev/stdout 2>&1 \ No newline at end of file + >/dev/stdout 2>&1