Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SharedSteps {
- git fetch origin
- git checkout master;git reset --hard origin/master; git pull
- git checkout $featurebranch;git reset --hard origin/$featurebranch; git pull;
- }
- function SharedPostSteps {
- param(
- [boolean] $checkForConflicts
- )
- $statusOutput = git status --porcelain
- $cleanDirectory = $statusOutput.length -eq 0
- If ($cleanDirectory -and $checkForConflicts) {
- Write-Warning "Nice merge (0 Conflicts). Now Running the Build, always build the project locally before pushing to origin"
- gitk
- }
- elseif($conflicts){
- Write-Warning "Conflicts found. Fix them and always build the project locally before pushing to origin"
- Write-Warning "Opening VS Code to see conflicts"
- Write-Warning "Get you out of a horrifying merge? say git merge --abort"
- code .
- }
- else{
- Write-Warning "Opening VS Code to preview staged chnages"
- Write-Warning "Press Ctl+C to skip this step..."
- Write-Warning "Get you out of a horrifying merge? say git merge --abort"
- code .
- }
- }
- function MergeFeatureBranch {
- param(
- [string] $featurebranch,
- [string] $options
- )
- $statusOutput = git status --porcelain
- $cleanDirectory = $statusOutput.length -eq 0
- $cleanDirectoryText = If ($cleanDirectory) {
- "Working Directory is clean"
- } Else {
- "Pending Work in Directory"
- }
- Write-Host $cleanDirectoryText;
- if(-not $cleanDirectory){
- Write-Host "Aborted. Please save/commit your local changes";
- return
- }
- try{
- $date = Get-Date -UFormat "%Y-%m-%d-%H-%M-%S"
- $userName = git config user.name
- $optionAuto ="Merging (No PR) master into local '$featurebranch' directly, if there're conflicts (banching & PR)"
- $optionNoPR = "Merging (No PR) master into local '$featurebranch' directly"
- $optionPreviewToMaster = "Preview Merging '$featurebranch' into Master (what the branch has so far)"
- $optionWithPR = "Merging (With PR) master into '$featurebranch' (branching off '$featurebranch')"
- $optionPreviewToBranch = "Preview Merging master to '$featurebranch' (how differnt is master)"
- $optionHotFixToMaster = "Merging (With PR) hotfix into master (branching off master)"
- if($options -Contains "-no-pr"){
- SharedSteps
- Write-Host $optionNoPR
- git merge master;
- SharedPostSteps -checkForConflicts $true
- }
- elseif($options -Contains "-re"){
- SharedSteps
- Write-Host $optionPreviewToMaster
- git checkout master;
- git merge --no-commit --no-ff $featurebranch
- SharedPostSteps -checkForConflicts $false
- }
- elseif($options -Contains "-pr"){
- SharedSteps
- Write-Host $optionWithPR
- git checkout -b $userName/master-MergeMasterInto-$featurebranch-$date;git merge master;
- SharedPostSteps -checkForConflicts $true
- }
- elseif($options -Contains "-n"){
- SharedSteps
- Write-Host $optionPreviewToBranch
- git merge --no-commit --no-ff master
- SharedPostSteps -checkForConflicts $false
- }
- elseif($options -Contains "-auto"){
- SharedSteps
- Write-Host $optionAuto
- git merge master;
- $statusOutput = git status --porcelain
- $cleanDirectory = $statusOutput.length -eq 0
- If (-not $cleanDirectory) {
- Write-Warning "Conflicts found. Switching to PR option"
- git merge --abort
- SharedSteps
- Write-Host $optionWithPR
- git checkout -b $userName/master-MergeMasterInto-$featurebranch-$date;git merge master;
- }
- SharedPostSteps -checkForConflicts $true
- }
- elseif($options -Contains "-hotfix"){
- $featurebranch = "hotfix"
- SharedSteps
- Write-Host $optionHotFixToMaster
- git checkout master;
- git checkout -b $userName/master-MergeHotfix-into-master-$date;git merge hotfix;
- SharedPostSteps -checkForConflicts $true
- }
- else{
- Write-Host
- Write-Host "-auto `t" $optionAuto
- Write-Host "-pr `t" $optionWithPR
- Write-Host "-no-pr `t" $optionNoPR
- Write-Host "-n `t" $optionPreviewToBranch
- Write-Host "-re `t" $optionPreviewToMaster
- Write-Host "-hotfix `t" $optionHotFixToMaster
- Write-Host
- }
- }
- catch {
- $exception = $_.exception | Format-List -force | Out-String
- Write-Warning "Unexpected Error Mergeing Feature branch '$featurebranch':"
- Write-Host $exception
- }
- }
- Export-ModuleMember -Function @(
- "MergeFeatureBranch"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement