Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [[ $# -lt 3 ]] ; then
  4. echo "Usage: merge-my-repos <sub_directory> <path_to_repo> <prefix_for_tags>"
  5. exit 1
  6. fi
  7.  
  8. DIR=$1
  9. REPO=$2
  10. TAG_PREFIX=$3
  11.  
  12. shopt -s extglob
  13.  
  14. if [ -d "$DIR" ]; then
  15. echo "Specified Directory exits!"
  16. exit 1
  17. fi
  18.  
  19. for old_tag in `git tag`
  20. do
  21. git tag -d $old_tag
  22. done
  23.  
  24.  
  25. git remote add other $REPO
  26. git fetch other --tags
  27.  
  28. for old_tag in `git tag`
  29. do
  30. git tag "${TAG_PREFIX}${old_tag}" $old_tag
  31. git tag -d $old_tag
  32. done
  33.  
  34. for branch in `git branch -r | grep -v HEAD | grep "other/" | cut -d '/' -f 2- `
  35. do
  36.  
  37. git checkout -b temporaryBranch other/$branch
  38. rm -rf $DIR
  39. mkdir $DIR
  40. mv ./!($DIR) $DIR
  41. mv ./.!(git|idea||.) $DIR
  42.  
  43. git add .
  44. git commit -q -m "Moved all files in branch '$branch' to subdirectory '$DIR'"
  45.  
  46. git branch -D $branch
  47.  
  48. git checkout -t origin/$branch
  49.  
  50. if [[ $? -ne 0 ]] ; then
  51. git branch $branch
  52. git checkout $branch
  53. else
  54. git merge temporaryBranch --allow-unrelated-histories --commit --no-edit
  55. fi
  56.  
  57. git branch -D temporaryBranch
  58.  
  59. done
  60.  
  61. git checkout master
  62.  
  63. git remote remove other
  64.  
  65. git push --all -u
  66.  
  67. git push --tags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement