Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. GIT_CONFIG='.git/config'
  4.  
  5. OLD_REP=$1
  6. NEW_REP=$2
  7. WORKSPACE=$3
  8.  
  9. # show usage
  10. if [ -z "$OLD_REP" -o -z "$NEW_REP" ]; then
  11. echo "git-svn-relocate OLD_REPOSITORY NEW_REPOSITORY [GIT_WORKSPACE]"
  12. exit 1
  13. fi
  14.  
  15. # change woking directory
  16. if [ $WORKSPACE ]; then
  17. cd $WORKSPACE
  18. if [ 0 -ne $? ]; then
  19. echo "invalid git workspace"
  20. exit 1
  21. fi
  22. fi
  23.  
  24. # git config file is exists?
  25. if [ ! -f $GIT_CONFIG ];then
  26. echo "not exists $GIT_CONFIG"
  27. exit 1
  28. fi
  29.  
  30. # check old repository
  31. grep $OLD_REP $GIT_CONFIG > /dev/null
  32. if [ 0 -ne $? ]; then
  33. echo "url not found (invalid old repository)"
  34. exit 1
  35. fi
  36.  
  37. # check current branch
  38. RET=`git branch| grep master | grep '*'`
  39. if [ -z "$RET" ]; then
  40. echo "not master branch"
  41. exit 1
  42. fi
  43.  
  44. # check git index
  45. RET=`git diff`
  46. if [ "$RET" ]; then
  47. echo "dirty workspace..."
  48. exit 1
  49. fi
  50.  
  51. # start relocation
  52. echo "rewrite url $OLD_REP -> $NEW_REP"
  53. sed -i -e "s|$OLD_REP|$NEW_REP|" $GIT_CONFIG
  54.  
  55. RET=`git svn fetch`
  56. if [ 0 -ne $? -o -z "$RET" ]; then
  57. echo "revert url $NEW_REP -> $OLD_REP"
  58. sed -i -e "s|$NEW_REP|$OLD_REP|" $GIT_CONFIG
  59. if [ -z "$RET" ]; then
  60. echo "empty fetch from new repository."
  61. else
  62. echo "invalid repository?"
  63. fi
  64. exit 1
  65. fi
  66.  
  67. echo "rewrite url $NEW_REP -> $OLD_REP"
  68. sed -i -e "s|$NEW_REP|$OLD_REP|" $GIT_CONFIG
  69. git svn rebase -l
  70. echo "rewrite url $OLD_REP -> $NEW_REP"
  71. sed -i -e "s|$OLD_REP|$NEW_REP|" $GIT_CONFIG
  72.  
  73. echo "repository relocation is completed"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement