Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Execute this script and you might have a better idea of how git-svn works
  4. # I think the main point here is to ilustrate how to commit/update from git-svn
  5. # ultility
  6. #
  7. # Keep in mind that when merge svn branches you won't get the feature branch
  8. # commits on top of your target branch. Instead it will only modify your files
  9. # on your working copy and than you can commit the merge.
  10. #
  11. # Also, you should avoid fetching code from multiples sources. Pretend you are
  12. # working on a undistribuited SCM, because you kinda are.
  13.  
  14. # Sandbox configuration. Change this variable if you want it in somewhere else
  15. SANDBOX=/tmp/sandbox
  16.  
  17. # Do not change this
  18. SVN_REPO=$SANDBOX/svn_repo
  19. SVN_URL=file:///$SANDBOX/svn_repo
  20. SVN_CLONE=$SANDBOX/svn_clone
  21. GIT_CLONE=$SANDBOX/git_clone
  22.  
  23. ###############################################################################
  24. # Setup: Reset sandbox
  25. ###############################################################################
  26.  
  27. rm -rf $SANDBOX
  28. mkdir -p $SANDBOX
  29.  
  30. ###############################################################################
  31. # create repository
  32. ###############################################################################
  33.  
  34. svnadmin create $SVN_REPO
  35.  
  36. # creating folders
  37. svn mkdir $SVN_URL/trunk -m "Created trunk"
  38. svn mkdir $SVN_URL/branches -m "Created branches"
  39. svn mkdir $SVN_URL/tags -m "Created tags"
  40.  
  41. ###############################################################################
  42. # svn clone and adding of files
  43. ###############################################################################
  44.  
  45. mkdir -p $SVN_CLONE
  46. cd $SVN_CLONE
  47. svn co $SVN_URL/trunk .
  48.  
  49. # adding files
  50. echo "# Git SVN Test" >> README.md
  51. svn add README.md
  52. svn commit -m "First trunk commit"
  53.  
  54. echo "Short description comes here" >> README.md
  55. svn add README.md
  56. svn commit -m "Second trunk commit"
  57.  
  58. ###############################################################################
  59. # git clone
  60. ###############################################################################
  61.  
  62. # -s is the same as '-T trunk -b branches -t tags'
  63. git svn clone $SVN_URL $GIT_CLONE -s
  64.  
  65. ###############################################################################
  66. # Creating branch via svn, and switching to it: Hilarious
  67. ###############################################################################
  68.  
  69. cd $SVN_CLONE
  70. svn copy $SVN_URL/trunk $SVN_URL/branches/new-feature -m "Creating a new branch"
  71.  
  72. svn switch $SVN_URL/branches/new-feature
  73.  
  74. # Commiting some changes
  75.  
  76. echo "# New Feature" >> NEW_FEATURE.md
  77. svn add NEW_FEATURE.md
  78. svn commit -m "First new-feature branch commit"
  79.  
  80. echo "Short description" >> NEW_FEATURE.md
  81. svn add NEW_FEATURE.md
  82. svn commit -m "Second new-feature branch commit"
  83.  
  84.  
  85. ###############################################################################
  86. # Updating add commiting to trunk from git
  87. ###############################################################################
  88.  
  89. cd $GIT_CLONE
  90.  
  91. git svn rebase
  92.  
  93. echo "A third line" >> README.md
  94. git commit -am "First commit to trunk via git" # local commit
  95.  
  96. echo "A fourth line" >> README.md
  97. git commit -am "Second commit to trunk via git" # local commit
  98.  
  99. # push to svn repo
  100. git svn dcommit
  101.  
  102. ###############################################################################
  103. # Checking out the feature branch from git
  104. ###############################################################################
  105.  
  106. cd $GIT_CLONE
  107.  
  108. git svn fetch # update the remote branches information
  109.  
  110. git checkout -b new-feature new-feature
  111.  
  112. # changing and commiting to feature branch
  113.  
  114. echo "A third line" >> NEW_FEATURE.md
  115. git commit -am "First commit to new-feature branch via git" # local commit
  116.  
  117. echo "A fourth line" >> NEW_FEATURE.md
  118. git commit -am "Second commit to new-feature branch via git" # local commit
  119.  
  120. # push to svn repo
  121. git svn dcommit
  122.  
  123. ###############################################################################
  124. # Merging feature branch to trunk with git
  125. ###############################################################################
  126.  
  127. # CAUTION:
  128. # All the feature branch commits are grouped into one commit when merging via git
  129. # This is somehow a svn limitation and not git-svn
  130.  
  131. cd $GIT_CLONE
  132.  
  133. git checkout master
  134. git merge new-feature -m "Merged all commits from new-feature branch into a single commit to trunk via git"
  135. git branch -d new-feature
  136. git svn dcommit
  137.  
  138. ###############################################################################
  139. # Merging feature branch to trunk in with svn: If you were to
  140. ###############################################################################
  141.  
  142. # if you were to merge with svn
  143. # cd $SVN_CLONE
  144. # svn switch $SVN_URL/trunk
  145. # svn merge $SVN_URL/branches/new-feature
  146. # svn commit -m "Merged all commits from new-feature branch into a single commit to trunk via svn"
  147.  
  148. ###############################################################################
  149. # Checking: switching to trunk and updating in svn
  150. ###############################################################################
  151.  
  152. cd $SVN_CLONE
  153. svn switch $SVN_URL/trunk
  154. svn update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement