Skip to content

Instantly share code, notes, and snippets.

@kiyokura
Created December 13, 2015 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiyokura/d1ef7d8641e4fe66e82a to your computer and use it in GitHub Desktop.
Save kiyokura/d1ef7d8641e4fe66e82a to your computer and use it in GitHub Desktop.
# =================================================================
# リポジトリチェックアウトしてoriginからPullした後にMsBuild実行する
# =================================================================
# *****************************************************************
# 関数定義
# *****************************************************************
function IsSuccessSwitchBranch($stdout,$stderr)
{
# stdoutを検査?
# Already on '<branch name>'
# Switch to branch '<branch name>'
# のどちらかが入ってる?
return $true
}
function IsSuccessPull($stdout,$stderr)
{
# stdoutを検査して成功したときに出てくるメッセージを検索する?
return $true
}
# *****************************************************************
# 実行処理部
# *****************************************************************
$dClass = [System.Management.Automation.Host.ChoiceDescription]
$cClass = "System.Collections.ObjectModel.Collection"
$descriptions = New-Object "$cClass``1[$dClass]"
# 選択肢の定義
$questions =
(("&1:Exit"),("Exit")),
(("&2:master"),("master branch")),
(("&3:feature/A"),("feature branch A")),
(("&4:feature/B"),("feature branch B")),
(("&5:feature/C"),("feature branch C"))
# 選択肢処理
$questions | %{$descriptions.Add((New-Object $dclass $_))}
$caption = "Target Selection"
$message = "Which branch?"
$result = $host.UI.PromptForChoice($caption, $message, $descriptions,0)
$selection = $descriptions[$result].Label.replace("&","")
if ($selection.Remove($selection.IndexOf(":")) -eq 1) {
"Exit Process."
exit
}else{
"$selection is selected."
}
# 選択されたブランチの取得
$branchName = $selection.Remove(0,$selection.IndexOf(":")+1)
$branchName
# ブランチのチェックアウト
$process = Start-Process -FilePath git -ArgumentList "checkout $branchName" -NoNewWindow -PassThru -Wait
$stdout = $process.StandardOutput
$stderr = $process.StandardError
$stdout
$stderr
$isSuccessSwitchBranch = IsSuccessSwitchBranch($stdout,$stderr)
# チェックアウトの成功判定
if($isSuccessSwitchBranch -ne $true){
"failt to chechout branch."
exit
}
# ブランチのPULL
$process = Start-Process -FilePath git -ArgumentList "git pull origin" -NoNewWindow -PassThru -Wait
$stdout = $process.StandardOutput
$stderr = $process.StandardError
$stdout
$stderr
$isSuccessPull = IsSuccessPull($stdout,$stderr)
# チェックアウトの成功判定
if($isSuccessPull -ne $true){
"failt to pull origin."
exit
}
# デプロイのためのビルドスクリプト実行
# http://hidari-lab.hatenablog.com/entry/2014/12/18/003516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment