forked from sakura-editor/sakura
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sakura-editor#440 from m-tmatma/feauture/easy-PR-r…
…eview Pull Request を簡単にローカルに取得するためのバッチファイルを追加 (take2)
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@echo off | ||
|
||
set yyyy=%date:~0,4% | ||
set mm=%date:~5,2% | ||
set dd=%date:~8,2% | ||
set time2=%time: =0% | ||
set hh=%time2:~0,2% | ||
set mn=%time2:~3,2% | ||
set ss=%time2:~6,2% | ||
set timestamp=%yyyy%%mm%%dd%-%hh%%mn%%ss% | ||
set PR_NUMBER=%1 | ||
set REMOTE_NAME=%2 | ||
set BRANCH_NAME=PR-%PR_NUMBER%/%timestamp% | ||
|
||
if "%PR_NUMBER%" == "" ( | ||
echo usage : get-PR.bat PR-Number [remote name] | ||
echo example1: get-PR.bat 1 | ||
echo example2: get-PR.bat 1 upstream | ||
echo example3: get-PR.bat 1 origin | ||
echo. | ||
echo [remote name] | ||
echo 1. If "remote name" is valid, it is used as the origin of PR. | ||
echo 2. If "remote name" is invalid and env SAKURA_EDITOR_REMOTE_NAME is valid, | ||
echo env SAKURA_EDITOR_REMOTE_NAME is used as the origin of PR. | ||
echo 3. Otherwise, "origin" is used as the origin of PR. | ||
exit /b 1 | ||
) | ||
|
||
if not "%REMOTE_NAME%" == "" ( | ||
@rem nothing to do | ||
) else if not "%SAKURA_EDITOR_REMOTE_NAME%" == "" ( | ||
set REMOTE_NAME=%SAKURA_EDITOR_REMOTE_NAME% | ||
) else ( | ||
set REMOTE_NAME=origin | ||
) | ||
|
||
@echo fetching pull request %PR_NUMBER% from %REMOTE_NAME% | ||
echo git fetch %REMOTE_NAME% pull/%PR_NUMBER%/head:%BRANCH_NAME% | ||
git fetch %REMOTE_NAME% pull/%PR_NUMBER%/head:%BRANCH_NAME% || exit /b 1 | ||
|
||
@echo checkout PR %PR_NUMBER% to branch %BRANCH_NAME% | ||
@echo git checkout %BRANCH_NAME% | ||
git checkout %BRANCH_NAME% || exit /b 1 | ||
|
||
exit /b 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# PR(Pull Request) を簡単にローカルに取得する方法 | ||
|
||
<!-- TOC --> | ||
|
||
- [PR(Pull Request) を簡単にローカルに取得する方法](#prpull-request-を簡単にローカルに取得する方法) | ||
- [コマンドライン引数](#コマンドライン引数) | ||
- [remote name](#remote-name) | ||
- [動作](#動作) | ||
- [使用例](#使用例) | ||
- [例1: PR36 をローカルに取得したい場合 (SAKURA_EDITOR_REMOTE_NAME を設定していない場合)](#例1-pr36-をローカルに取得したい場合-sakura_editor_remote_name-を設定していない場合) | ||
- [例2: Fork したリポジトリで PR40 を取得したい場合](#例2-fork-したリポジトリで-pr40-を取得したい場合) | ||
|
||
<!-- /TOC --> | ||
|
||
``` | ||
get-PR.bat <PR-Number> [<remote name>] | ||
``` | ||
|
||
|
||
## コマンドライン引数 | ||
|
||
|引数名|意味|必須|例| | ||
|:--|:--|:--|:--| | ||
|PR-Number|PR 番号|○|100| | ||
|remote name|git remote の名前|×|origin| | ||
|
||
## remote name | ||
|
||
PR を取得するための remote name の取得先 | ||
|
||
|優先順位|取得先| | ||
|:--|:--| | ||
|1|バッチファイルの第2引数| | ||
|2|環境変数 SAKURA_EDITOR_REMOTE_NAME| | ||
|3|origin| | ||
|
||
|
||
## 動作 | ||
|
||
|
||
`PR-xx/yyyymmdd-HHMMSS` というローカルブランチに取得してチェックアウトします。 | ||
実行した後に PR が更新された場合は単純に再実行します。 | ||
|
||
|フィールド名|意味| | ||
|--|--| | ||
|xx|PR番号| | ||
|yyyy|西暦| | ||
|mm|月| | ||
|dd|日| | ||
|HH|時間| | ||
|MM|分| | ||
|SS|秒| | ||
|
||
|
||
## 使用例 | ||
|
||
### 例1: PR36 をローカルに取得したい場合 (SAKURA_EDITOR_REMOTE_NAME を設定していない場合) | ||
|
||
``` | ||
git clone https://github.com/sakura-editor/sakura.git | ||
cd sakura | ||
get-PR.bat 36 | ||
``` | ||
|
||
### 例2: Fork したリポジトリで PR40 を取得したい場合 | ||
|
||
`<forkname>` は適宜 GitHub 上での自分のユーザー名等に読み替えます。 | ||
|
||
|
||
``` | ||
git clone https://github.com/<forkname>/sakura.git | ||
cd sakura | ||
git remote add upstream https://github.com/sakura-editor/sakura.git | ||
git fetch upstream | ||
get-PR.bat 40 upstream | ||
set SAKURA_EDITOR_REMOTE_NAME=upstream | ||
get-PR.bat 40 | ||
``` |