Guest User

Untitled

a guest
Dec 21st, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #!/bin/bash
  2. # Usage: svn_merge {trunk url} {branch url}
  3. # This script requires 2 parameters. The first one is the full url of the trunk and the second is the full url of the branch. Do not add trailing slashes in the urls.
  4. TRUNK=$1
  5. BRANCH=$2
  6. TMP_DIR=~/svn/temp_merge_dir/
  7. BRANCH_DIR=`echo $BRANCH | rev | cut -d '/' -f 1 | rev`
  8. MERGED_DIR="MERGED_"$BRANCH_DIR
  9. TRUNK_DIR=`echo $TRUNK | rev | cut -d '/' -f 1 | rev`
  10. NEW_BRANCH=${BRANCH/$BRANCH_DIR/$MERGED_DIR}
  11. SVN_USER=$(whoami) # Change to your SVN username
  12. SVN_PASS="Add your SVN password"
  13. CHECK_TRUNK=$(svn info $TRUNK)
  14. CHECK_BRANCH=$(svn info $BRANCH)
  15.  
  16. # Setting your credentials to access the repo
  17. svn auth --username $SVN_USER --password $SVN_PASS # add this line to ~/.bashrc ~/.zshrc and prepend alias svn_auth= to it. Then use it just as svn_auth. Don't forget to declare and export SVN_USER and SVN_PASS also.
  18.  
  19. echo "$SVN_USER Authenticated successfully"
  20.  
  21. # First, create a temp folder to work and manage working copies
  22. CURRENT_DIR=$(pwd)
  23. BASE_DIR=$CURRENT_DIR
  24. mkdir -p $TMP_DIR
  25. cd $TMP_DIR
  26. echo "$TMP_DIR temporary folder created"
  27.  
  28. if [[ -z $CHECK_TRUNK ]]; then
  29. echo "The trunk $TRUNK doesn't exists"
  30. else
  31. # Second, download the trunk to the temp folder
  32. svn checkout $TRUNK
  33. cd $TRUNK_DIR
  34. CURRENT_DIR=$(pwd)
  35.  
  36. if [$CURRENT_DIR == $BASE_DIR/$TRUNK_DIR]
  37. then
  38. echo "Trunk downloaded and accessed successfully"
  39.  
  40. if [[ -z $CHECK_BRANCH ]]; then
  41. echo "The branch $BRANCH doesn't exists"
  42. else
  43. # Third, merge the branch into the trunk
  44. svn merge $BRANCH
  45. svn commit -m "Merge executed from $BRANCH to $TRUNK"
  46. echo "Merge and commit the branch $BRANCH_DIR into trunk $TRUNK"
  47.  
  48. # Fourth, rename the branch to flag it as merged
  49. svn mv $BRANCH $NEW_BRANCH
  50. svn commit -m "Branch renamed and flagged as merged"
  51. echo "Rename and flag the branch as merged"
  52. fi
  53. fi
  54. fi
  55.  
  56. # Finally, exit the temporary folder and delete it
  57. cd $BASE_DIR
  58. sudo rm -rf $TMP_DIR
  59. echo "Exiting the temporary folder and completing deletion."
Add Comment
Please, Sign In to add comment