@@ -22,6 +22,7 @@ const WCHAR PR_NUMBER[] = L"PR_NUMBER";
22
22
23
23
void GitHubPrApp::initSettings (_In_ const std::wstring &targetDir)
24
24
{
25
+ constexpr bool saveEnvStr = false ;
25
26
constexpr bool skipSave = true ;
26
27
27
28
::SetConsoleTitle (GITHUB_PR);
@@ -55,20 +56,17 @@ void GitHubPrApp::initSettings(_In_ const std::wstring &targetDir)
55
56
std::wstring profileName = curDir + PROFILE_SUFFIX;
56
57
profile = std::move (PrivateProfile (profileName));
57
58
58
- gitRemoteName = _initSetting (GIT_REMOTE_NAME, [this ]() {return _getRemoteName (); }, skipSave );
59
+ gitRemoteName = _initSetting (GIT_REMOTE_NAME, [this ]() {return _getRemoteName (); }, saveEnvStr );
59
60
branchPrefix = _initSetting (BRANCH_PREFIX, [this ]() {return _getBranchPrefix (); }, skipSave);
60
61
prNumber = _initSetting (PR_NUMBER, [this ]() {return _getPrNumber (); }, skipSave);
61
62
62
63
{
63
- BatchCommand cmd (IDR_CMD_CHECKOUT_BRANCH );
64
+ BatchCommand cmd (L" @%GIT% checkout %BRANCH_NAME% > NUL 2>&1 \r\n @ECHO %ERRORLEVEL% " );
64
65
auto retList = cmd.invokeAndGetLines ();
65
- if (! retList.empty ()) {
66
- currentBranch = retList. back ( );
66
+ if (retList.empty ()) {
67
+ THROW_APP_EXCEPTION ( " git checkout may not work correctly. " );
67
68
}
68
- }
69
- if (!currentBranch.empty ()) {
70
- setEnvStr (L" CURRENT_BRANCH" , currentBranch.c_str ());
71
- homeBranch = _initSetting (HOME_BRANCH, [this ]() {return _getHomeBranch (); }, skipSave);
69
+ branchNameExists = retList.front () == L" 0" ;
72
70
}
73
71
}
74
72
@@ -114,7 +112,7 @@ std::wstring GitHubPrApp::_getRemoteName() const
114
112
{
115
113
std::list<std::wstring> remotes;
116
114
{
117
- BatchCommand cmd (IDR_CMD_ENUM_REMOTES );
115
+ BatchCommand cmd (L" @%GIT% remote " );
118
116
remotes = cmd.invokeAndGetLines ();
119
117
remotes.remove (L" " );
120
118
}
@@ -174,7 +172,7 @@ std::wstring GitHubPrApp::_getHomeBranch() const
174
172
{
175
173
std::list<std::wstring> branchs;
176
174
{
177
- BatchCommand cmd (IDR_CMD_ENUM_BRANCHS );
175
+ BatchCommand cmd (L" @%GIT% branch --list " );
178
176
branchs = cmd.invokeAndGetLines ();
179
177
branchs.remove (L" " );
180
178
std::wregex reBranch (L" ^\\ *?\\ s+(.+)$" );
@@ -218,8 +216,18 @@ std::wstring GitHubPrApp::_getHomeBranch() const
218
216
219
217
void GitHubPrApp::executeBatch () const
220
218
{
219
+ // 実行するコマンドを組み立てる
220
+ std::wostringstream os;
221
+ if (!branchNameExists) {
222
+ os << L" @%GIT% fetch %GIT_REMOTE_NAME% pull/%PR_NUMBER%/head:%BRANCH_NAME%" << std::endl;
223
+ os << L" @%GIT% checkout %BRANCH_NAME%" << std::endl;
224
+ }
225
+ else {
226
+ os << L" @%GIT% pull %GIT_REMOTE_NAME% pull/%PR_NUMBER%/head" << std::endl;
227
+ }
228
+
221
229
// バッチファイルを実行する
222
- BatchCommand cmd (IDR_CMD_GET_PR );
230
+ BatchCommand cmd (os. str () );
223
231
auto lines (cmd.invokeAndGetLines ());
224
232
std::for_each (lines.cbegin (), lines.cend (), [](const std::wstring &line) {std::wcout << line << std::endl; });
225
233
}
0 commit comments