Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. function SharedSteps {
  2. git fetch origin
  3. git checkout master;git reset --hard origin/master; git pull
  4. git checkout $featurebranch;git reset --hard origin/$featurebranch; git pull;
  5. }
  6.  
  7. function SharedPostSteps {
  8. param(
  9. [boolean] $checkForConflicts
  10. )
  11. $statusOutput = git status --porcelain
  12. $cleanDirectory = $statusOutput.length -eq 0
  13. If ($cleanDirectory -and $checkForConflicts) {
  14. Write-Warning "Nice merge (0 Conflicts). Now Running the Build, always build the project locally before pushing to origin"
  15. gitk
  16. }
  17. elseif($conflicts){
  18. Write-Warning "Conflicts found. Fix them and always build the project locally before pushing to origin"
  19. Write-Warning "Opening VS Code to see conflicts"
  20. Write-Warning "Get you out of a horrifying merge? say git merge --abort"
  21. code .
  22. }
  23. else{
  24. Write-Warning "Opening VS Code to preview staged chnages"
  25. Write-Warning "Press Ctl+C to skip this step..."
  26. Write-Warning "Get you out of a horrifying merge? say git merge --abort"
  27. code .
  28. }
  29.  
  30. }
  31.  
  32. function MergeFeatureBranch {
  33. param(
  34. [string] $featurebranch,
  35. [string] $options
  36. )
  37.  
  38. $statusOutput = git status --porcelain
  39. $cleanDirectory = $statusOutput.length -eq 0
  40. $cleanDirectoryText = If ($cleanDirectory) {
  41. "Working Directory is clean"
  42. } Else {
  43. "Pending Work in Directory"
  44. }
  45. Write-Host $cleanDirectoryText;
  46.  
  47. if(-not $cleanDirectory){
  48. Write-Host "Aborted. Please save/commit your local changes";
  49. return
  50. }
  51.  
  52. try{
  53.  
  54. $date = Get-Date -UFormat "%Y-%m-%d-%H-%M-%S"
  55. $userName = git config user.name
  56. $optionAuto ="Merging (No PR) master into local '$featurebranch' directly, if there're conflicts (banching & PR)"
  57. $optionNoPR = "Merging (No PR) master into local '$featurebranch' directly"
  58. $optionPreviewToMaster = "Preview Merging '$featurebranch' into Master (what the branch has so far)"
  59. $optionWithPR = "Merging (With PR) master into '$featurebranch' (branching off '$featurebranch')"
  60. $optionPreviewToBranch = "Preview Merging master to '$featurebranch' (how differnt is master)"
  61. $optionHotFixToMaster = "Merging (With PR) hotfix into master (branching off master)"
  62.  
  63. if($options -Contains "-no-pr"){
  64. SharedSteps
  65. Write-Host $optionNoPR
  66. git merge master;
  67. SharedPostSteps -checkForConflicts $true
  68. }
  69. elseif($options -Contains "-re"){
  70. SharedSteps
  71. Write-Host $optionPreviewToMaster
  72. git checkout master;
  73. git merge --no-commit --no-ff $featurebranch
  74. SharedPostSteps -checkForConflicts $false
  75. }
  76. elseif($options -Contains "-pr"){
  77. SharedSteps
  78. Write-Host $optionWithPR
  79. git checkout -b $userName/master-MergeMasterInto-$featurebranch-$date;git merge master;
  80. SharedPostSteps -checkForConflicts $true
  81. }
  82. elseif($options -Contains "-n"){
  83. SharedSteps
  84. Write-Host $optionPreviewToBranch
  85. git merge --no-commit --no-ff master
  86. SharedPostSteps -checkForConflicts $false
  87. }
  88. elseif($options -Contains "-auto"){
  89. SharedSteps
  90. Write-Host $optionAuto
  91. git merge master;
  92. $statusOutput = git status --porcelain
  93. $cleanDirectory = $statusOutput.length -eq 0
  94. If (-not $cleanDirectory) {
  95. Write-Warning "Conflicts found. Switching to PR option"
  96. git merge --abort
  97. SharedSteps
  98. Write-Host $optionWithPR
  99. git checkout -b $userName/master-MergeMasterInto-$featurebranch-$date;git merge master;
  100. }
  101. SharedPostSteps -checkForConflicts $true
  102. }
  103. elseif($options -Contains "-hotfix"){
  104. $featurebranch = "hotfix"
  105. SharedSteps
  106. Write-Host $optionHotFixToMaster
  107. git checkout master;
  108. git checkout -b $userName/master-MergeHotfix-into-master-$date;git merge hotfix;
  109. SharedPostSteps -checkForConflicts $true
  110. }
  111. else{
  112. Write-Host
  113. Write-Host "-auto `t" $optionAuto
  114. Write-Host "-pr `t" $optionWithPR
  115. Write-Host "-no-pr `t" $optionNoPR
  116. Write-Host "-n `t" $optionPreviewToBranch
  117. Write-Host "-re `t" $optionPreviewToMaster
  118. Write-Host "-hotfix `t" $optionHotFixToMaster
  119. Write-Host
  120. }
  121.  
  122. }
  123. catch {
  124. $exception = $_.exception | Format-List -force | Out-String
  125. Write-Warning "Unexpected Error Mergeing Feature branch '$featurebranch':"
  126. Write-Host $exception
  127. }
  128. }
  129.  
  130.  
  131. Export-ModuleMember -Function @(
  132. "MergeFeatureBranch"
  133. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement