Rename a lot of SVN references to GIT
[TortoiseGit.git] / src / TortoiseProc / SyncDlg.cpp
blob8d2333ec78d7bb4a1d3605a0d1868fc9fd2c7439
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2009 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // SyncDlg.cpp : implementation file
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "SyncDlg.h"
26 #include "progressdlg.h"
27 #include "MessageBox.h"
28 #include "ImportPatchDlg.h"
29 #include "PathUtils.h"
30 #include "RebaseDlg.h"
31 #include "hooks.h"
33 // CSyncDlg dialog
35 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)
37 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)
38 : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)
40 m_pTooltip=&this->m_tooltips;
41 m_bInited=false;
42 m_CmdOutCurrentPos=0;
43 m_bAutoLoadPuttyKey = CAppUtils::IsSSHPutty();
44 m_bForce=false;
45 m_bBlock = false;
48 CSyncDlg::~CSyncDlg()
52 void CSyncDlg::DoDataExchange(CDataExchange* pDX)
54 CDialog::DoDataExchange(pDX);
55 DDX_Check(pDX, IDC_CHECK_PUTTY_KEY, m_bAutoLoadPuttyKey);
56 DDX_Check(pDX, IDC_CHECK_FORCE,m_bForce);
57 DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_ctrlURL);
58 DDX_Control(pDX, IDC_BUTTON_TABCTRL, m_ctrlDumyButton);
59 DDX_Control(pDX, IDC_BUTTON_PULL, m_ctrlPull);
60 DDX_Control(pDX, IDC_BUTTON_PUSH, m_ctrlPush);
61 DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlStatus);
62 DDX_Control(pDX, IDC_PROGRESS_SYNC, m_ctrlProgress);
63 DDX_Control(pDX, IDC_ANIMATE_SYNC, m_ctrlAnimate);
64 DDX_Control(pDX, IDC_BUTTON_SUBMODULE,m_ctrlSubmodule);
65 BRANCH_COMBOX_DDX;
69 BEGIN_MESSAGE_MAP(CSyncDlg, CResizableStandAloneDialog)
70 ON_BN_CLICKED(IDC_BUTTON_PULL, &CSyncDlg::OnBnClickedButtonPull)
71 ON_BN_CLICKED(IDC_BUTTON_PUSH, &CSyncDlg::OnBnClickedButtonPush)
72 ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSyncDlg::OnBnClickedButtonApply)
73 ON_BN_CLICKED(IDC_BUTTON_EMAIL, &CSyncDlg::OnBnClickedButtonEmail)
74 ON_BN_CLICKED(IDC_BUTTON_MANAGE, &CSyncDlg::OnBnClickedButtonManage)
75 BRANCH_COMBOX_EVENT
76 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbnEditchangeComboboxex)
77 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH, &CSyncDlg::OnCbnEditchangeComboboxex)
78 ON_MESSAGE(MSG_PROGRESSDLG_UPDATE_UI, OnProgressUpdateUI)
79 ON_BN_CLICKED(IDC_BUTTON_COMMIT, &CSyncDlg::OnBnClickedButtonCommit)
80 ON_BN_CLICKED(IDC_BUTTON_SUBMODULE, &CSyncDlg::OnBnClickedButtonSubmodule)
81 ON_WM_TIMER()
82 ON_REGISTERED_MESSAGE(WM_TASKBARBTNCREATED, OnTaskbarBtnCreated)
83 END_MESSAGE_MAP()
86 void CSyncDlg::EnableControlButton(bool bEnabled)
88 GetDlgItem(IDC_BUTTON_PULL)->EnableWindow(bEnabled);
89 GetDlgItem(IDC_BUTTON_PUSH)->EnableWindow(bEnabled);
90 GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(bEnabled);
91 GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(bEnabled);
92 GetDlgItem(IDOK)->EnableWindow(bEnabled);
93 GetDlgItem(IDC_BUTTON_SUBMODULE)->EnableWindow(bEnabled);
95 // CSyncDlg message handlers
97 void CSyncDlg::OnBnClickedButtonPull()
99 int CurrentEntry;
100 CurrentEntry = this->m_ctrlPull.GetCurrentEntry();
101 this->m_regPullButton = CurrentEntry;
103 this->m_bAbort=false;
104 this->m_GitCmdList.clear();
106 this->UpdateData();
107 UpdateCombox();
109 m_oldHash = g_Git.GetHash(_T("HEAD"));
111 if( CurrentEntry == 0)
113 if( g_Git.GetHash(this->m_strLocalBranch) != m_oldHash)
115 CMessageBox::Show(NULL,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
116 return;
120 if(this->m_strURL.IsEmpty())
122 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
123 return;
126 if(this->m_bAutoLoadPuttyKey)
128 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
131 this->SwitchToRun();
133 CString force;
134 if(this->m_bForce)
135 force = _T(" --force ");
137 CString cmd;
139 ShowTab(IDC_CMD_LOG);
141 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
142 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
143 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
145 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
147 ///Pull
148 if(CurrentEntry == 0) //Pull
150 CString remotebranch;
151 remotebranch = m_strRemoteBranch;
153 if(!IsURL())
155 CString configName;
156 configName.Format(L"branch.%s.merge", this->m_strLocalBranch);
157 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
159 configName.Format(L"branch.%s.remote", m_strLocalBranch);
160 CString pullRemote = g_Git.GetConfigValue(configName);
162 if(pullBranch == remotebranch && pullRemote == this->m_strURL)
163 remotebranch.Empty();
166 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
167 force += _T("--progress ");
169 cmd.Format(_T("git.exe pull -v %s \"%s\" %s"),
170 force,
171 m_strURL,
172 remotebranch);
174 m_CurrentCmd = GIT_COMMAND_PULL;
175 m_GitCmdList.push_back(cmd);
177 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
178 if (m_pThread==NULL)
180 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
182 else
184 m_pThread->m_bAutoDelete = TRUE;
185 m_pThread->ResumeThread();
190 ///Fetch
191 if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch
193 CString remotebranch;
194 if(this->IsURL() || m_strRemoteBranch.IsEmpty())
196 remotebranch=this->m_strRemoteBranch;
199 else
201 remotebranch.Format(_T("remotes/%s/%s"),
202 m_strURL,m_strRemoteBranch);
203 if(g_Git.GetHash(remotebranch).IsEmpty())
204 remotebranch=m_strRemoteBranch;
205 else
206 remotebranch=m_strRemoteBranch+_T(":")+remotebranch;
209 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
210 force += _T("--progress ");
212 cmd.Format(_T("git.exe fetch -v %s \"%s\" %s"),
213 force,
214 m_strURL,
215 remotebranch);
217 if(CurrentEntry == 1)
218 m_CurrentCmd = GIT_COMMAND_FETCH;
219 else
220 m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;
221 m_GitCmdList.push_back(cmd);
223 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
224 if (m_pThread==NULL)
226 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
228 else
230 m_pThread->m_bAutoDelete = TRUE;
231 m_pThread->ResumeThread();
235 ///Remote Update
236 if(CurrentEntry == 3)
238 m_CurrentCmd = GIT_COMMAND_REMOTE;
239 cmd=_T("git.exe remote update");
240 m_GitCmdList.push_back(cmd);
242 InterlockedExchange(&m_bBlock, TRUE);
244 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
245 if (m_pThread==NULL)
247 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
248 InterlockedExchange(&m_bBlock, FALSE);
250 else
252 m_pThread->m_bAutoDelete = TRUE;
253 m_pThread->ResumeThread();
258 void CSyncDlg::PullComplete()
260 EnableControlButton(true);
261 SwitchToInput();
262 this->FetchOutList(true);
264 CString newhash;
265 newhash = g_Git.GetHash(_T("HEAD"));
267 if( this ->m_GitCmdStatus )
269 CTGitPathList list;
270 if(g_Git.ListConflictFile(list))
272 this->m_ctrlCmdOut.SetSel(-1,-1);
273 this->m_ctrlCmdOut.ReplaceSel(_T("Get conflict files fail\n"));
275 this->ShowTab(IDC_CMD_LOG);
276 return;
279 if(list.GetCount()>0)
281 this->m_ConflictFileList.Clear();
282 CTGitPathList list;
283 CTGitPath path;
284 list.AddPath(path);
286 this->m_ConflictFileList.GetStatus(&list,true);
287 this->m_ConflictFileList.Show(CTGitPath::LOGACTIONS_UNMERGED,
288 CTGitPath::LOGACTIONS_UNMERGED);
290 this->ShowTab(IDC_IN_CONFLICT);
292 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_NORMAL);
294 else
295 this->ShowTab(IDC_CMD_LOG);
298 else
300 if(newhash == this->m_oldHash)
302 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
303 this->m_InLogList.ShowText(_T("No commits get after pull"));
304 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
306 else
308 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
309 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
311 CString oldhash=m_oldHash.ToString();
312 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
314 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
315 &oldhash,&newhash);
317 this->ShowTab(IDC_IN_LOGLIST);
321 void CSyncDlg::FetchComplete()
323 EnableControlButton(true);
324 SwitchToInput();
325 this->FetchOutList(true);
327 ShowTab(IDC_CMD_LOG);
328 if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
330 CRebaseDlg dlg;
331 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
332 int response = dlg.DoModal();
333 if(response == IDOK)
335 return ;
338 if(response == IDC_REBASE_POST_BUTTON)
340 CString cmd, out, err;
341 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
342 g_Git.m_CurrentDir,
343 g_Git.FixBranchName(dlg.m_Upstream),
344 g_Git.FixBranchName(dlg.m_Branch));
345 if(g_Git.Run(cmd, &out, &err, CP_ACP))
347 CMessageBox::Show(NULL, out + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
348 return ;
351 CAppUtils::SendPatchMail(cmd,out);
356 void CSyncDlg::OnBnClickedButtonPush()
358 this->UpdateData();
359 UpdateCombox();
361 if(this->m_strURL.IsEmpty())
363 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
364 return;
367 this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();
368 this->SwitchToRun();
369 this->m_bAbort=false;
370 this->m_GitCmdList.clear();
372 ShowTab(IDC_CMD_LOG);
374 CString cmd;
375 CString arg;
377 CString error;
378 DWORD exitcode;
379 CTGitPathList list;
380 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
382 if (CHooks::Instance().PrePush(list,exitcode, error))
384 if (exitcode)
386 CString temp;
387 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
388 //ReportError(temp);
389 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
390 return ;
394 switch (m_ctrlPush.GetCurrentEntry())
396 case 1:
397 arg += _T(" --tags ");
398 break;
399 case 2:
400 arg += _T(" --all ");
401 break;
404 if(this->m_bForce)
405 arg += _T(" --force ");
407 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
408 arg += _T("--progress ");
410 cmd.Format(_T("git.exe push -v %s \"%s\" %s"),
411 arg,
412 m_strURL,
413 g_Git.FixBranchName(m_strLocalBranch));
415 if (!m_strRemoteBranch.IsEmpty())
417 cmd += _T(":") + m_strRemoteBranch;
420 m_GitCmdList.push_back(cmd);
422 m_CurrentCmd = GIT_COMMAND_PUSH;
424 if(this->m_bAutoLoadPuttyKey)
426 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
429 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
430 if (m_pThread==NULL)
432 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
434 else
436 m_pThread->m_bAutoDelete = TRUE;
437 m_pThread->ResumeThread();
441 void CSyncDlg::OnBnClickedButtonApply()
443 CString oldhash;
444 oldhash=g_Git.GetHash(_T("HEAD"));
446 CImportPatchDlg dlg;
447 CString cmd,output;
449 if(dlg.DoModal() == IDOK)
451 int err=0;
452 for(int i=0;i<dlg.m_PathList.GetCount();i++)
454 cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());
456 if(g_Git.Run(cmd,&output,CP_ACP))
458 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);
460 err=1;
461 break;
463 this->m_ctrlCmdOut.SetSel(-1,-1);
464 this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));
465 this->m_ctrlCmdOut.SetSel(-1,-1);
466 this->m_ctrlCmdOut.ReplaceSel(output);
469 CString newhash=g_Git.GetHash(_T("HEAD"));
471 this->m_InLogList.Clear();
472 this->m_InChangeFileList.Clear();
474 if(newhash == oldhash)
476 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
477 this->m_InLogList.ShowText(_T("No commits get from patch"));
478 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
481 else
483 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
484 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
486 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
487 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
488 &oldhash,&newhash);
490 this->FetchOutList(true);
493 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);
495 if(err)
497 this->ShowTab(IDC_CMD_LOG);
499 else
501 this->ShowTab(IDC_IN_LOGLIST);
506 void CSyncDlg::OnBnClickedButtonEmail()
508 CString cmd, out, err;
510 this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();
511 this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);
512 this->m_ctrlURL.GetWindowText(this->m_strURL);
513 m_strURL=m_strURL.Trim();
514 m_strRemoteBranch=m_strRemoteBranch.Trim();
516 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
517 g_Git.m_CurrentDir,
518 m_strURL+_T('/')+m_strRemoteBranch,g_Git.FixBranchName(m_strLocalBranch));
520 if (g_Git.Run(cmd, &out, &err, CP_ACP))
522 CMessageBox::Show(NULL, out + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
523 return ;
526 CAppUtils::SendPatchMail(cmd,out);
529 void CSyncDlg::ShowProgressCtrl(bool bShow)
531 int b=bShow?SW_NORMAL:SW_HIDE;
532 this->m_ctrlAnimate.ShowWindow(b);
533 this->m_ctrlProgress.ShowWindow(b);
534 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
535 if(b == SW_NORMAL)
536 this->m_ctrlAnimate.Play(0,-1,-1);
537 else
538 this->m_ctrlAnimate.Stop();
540 void CSyncDlg::ShowInputCtrl(bool bShow)
542 int b=bShow?SW_NORMAL:SW_HIDE;
543 this->m_ctrlURL.ShowWindow(b);
544 this->m_ctrlLocalBranch.ShowWindow(b);
545 this->m_ctrlRemoteBranch.ShowWindow(b);
546 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);
547 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);
548 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);
549 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);
550 this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);
551 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);
552 this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);
553 this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);
555 BOOL CSyncDlg::OnInitDialog()
557 CResizableStandAloneDialog::OnInitDialog();
558 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
560 // Let the TaskbarButtonCreated message through the UIPI filter. If we don't
561 // do this, Explorer would be unable to send that message to our window if we
562 // were running elevated. It's OK to make the call all the time, since if we're
563 // not elevated, this is a no-op.
564 CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
565 typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct);
566 HMODULE hUser = ::LoadLibrary(_T("user32.dll"));
567 if (hUser)
569 ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx");
570 if (pfnChangeWindowMessageFilterEx)
572 pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs);
574 FreeLibrary(hUser);
576 m_pTaskbarList.Release();
577 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
579 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->EnableWindow(CAppUtils::IsSSHPutty());
582 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
583 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
584 this->m_ctrlAnimate.Play(0,-1,-1);
587 // ------------------ Create Tabctrl -----------
588 CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);
589 CRect rectDummy;
590 pwnd->GetWindowRect(&rectDummy);
591 this->ScreenToClient(rectDummy);
593 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))
595 TRACE0("Failed to create output tab window\n");
596 return FALSE; // fail to create
598 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
600 // -------------Create Command Log Ctrl ---------
601 DWORD dwStyle;
602 dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL ;
604 if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))
606 TRACE0("Failed to create Log commits window\n");
607 return FALSE; // fail to create
610 CHARFORMAT m_Format;
611 memset(&m_Format, 0, sizeof(CHARFORMAT));
612 m_Format.cbSize = sizeof(CHARFORMAT);
613 m_Format.dwMask = CFM_FACE | CFM_BOLD;
614 wcsncpy(m_Format.szFaceName, L"Courier New", LF_FACESIZE - 1);
615 m_ctrlCmdOut.SetDefaultCharFormat(m_Format);
617 m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut,_T("Log"),-1);
619 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
621 //---------- Create in coming list ctrl -----------
622 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
624 if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))
626 TRACE0("Failed to create output commits window\n");
627 return FALSE; // fail to create
630 m_ctrlTabCtrl.InsertTab(&m_InLogList,_T("In Commits"),-1);
632 m_InLogList.m_ColumnRegKey=_T("SyncIn");
633 m_InLogList.InsertGitColumn();
635 //----------- Create In Change file list -----------
636 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
638 if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))
640 TRACE0("Failed to create output change files window\n");
641 return FALSE; // fail to create
643 m_ctrlTabCtrl.InsertTab(&m_InChangeFileList,_T("In ChangeList"),-1);
645 m_InChangeFileList.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("OutSyncDlg"),
646 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)|
647 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2)),false);
650 //---------- Create Conflict List Ctrl -----------------
651 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
653 if( !m_ConflictFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CONFLICT))
655 TRACE0("Failed to create output change files window\n");
656 return FALSE; // fail to create
658 m_ctrlTabCtrl.InsertTab(&m_ConflictFileList,_T("Conflict"),-1);
660 m_ConflictFileList.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("OutSyncDlg"),
661 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)|
662 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2)|
663 GITSLC_POPCONFLICT|GITSLC_POPRESOLVE),false);
666 //---------- Create Commit Out List Ctrl---------------
668 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
670 if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))
672 TRACE0("Failed to create output commits window\n");
673 return FALSE; // fail to create
677 m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),-1);
679 m_OutLogList.m_ColumnRegKey = _T("SyncOut");
680 m_OutLogList.InsertGitColumn();
682 //------------- Create Change File List Control ----------------
684 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
686 if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))
688 TRACE0("Failed to create output change files window\n");
689 return FALSE; // fail to create
691 m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),-1);
693 m_OutChangeFileList.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("OutSyncDlg"),
694 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_COMPARETWO)|
695 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDGITLC_GNUDIFF2)),false);
697 this->m_tooltips.Create(this);
699 AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);
701 AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);
702 AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);
703 AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);
704 AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);
705 AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);
706 AddAnchor(IDC_BUTTON_SUBMODULE,BOTTOM_LEFT);
707 AddAnchor(IDC_BUTTON_APPLY,BOTTOM_RIGHT);
708 AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_RIGHT);
709 AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);
710 AddAnchor(IDOK,BOTTOM_RIGHT);
711 AddAnchor(IDHELP,BOTTOM_RIGHT);
712 AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);
713 AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);
714 AddAnchor(IDC_BUTTON_COMMIT,BOTTOM_LEFT);
716 BRANCH_COMBOX_ADD_ANCHOR();
718 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
720 CString WorkingDir=g_Git.m_CurrentDir;
721 WorkingDir.Replace(_T(':'),_T('_'));
722 m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;
725 this->AddOthersToAnchor();
727 this->m_ctrlPush.AddEntry(CString(_T("Pus&h")));
728 this->m_ctrlPush.AddEntry(CString(_T("Push ta&gs")));
729 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
731 this->m_ctrlPull.AddEntry(CString(_T("&Pull")));
732 this->m_ctrlPull.AddEntry(CString(_T("Fetc&h")));
733 this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Re&base")));
734 this->m_ctrlPull.AddEntry(CString(_T("Remote Update")));
736 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Update")));
737 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Init")));
738 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Sync")));
740 WorkingDir.Replace(_T(':'),_T('_'));
742 CString regkey ;
743 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);
745 this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);
746 this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);
747 this->m_regSubmoduleButton = CRegDWORD(regkey+_T("\\Submodule"));
748 this->m_regAutoLoadPutty = CRegDWORD(regkey + _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
750 this->UpdateData();
751 this->m_bAutoLoadPuttyKey = m_regAutoLoadPutty;
752 if(!CAppUtils::IsSSHPutty())
753 m_bAutoLoadPuttyKey = false;
754 this->UpdateData(FALSE);
756 this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);
757 this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);
758 this->m_ctrlSubmodule.SetCurrentEntry(this->m_regSubmoduleButton);
760 CString sWindowTitle;
761 GetWindowText(sWindowTitle);
762 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
764 EnableSaveRestore(_T("SyncDlg"));
766 this->m_ctrlURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir, _T("url"));
768 STRING_VECTOR list;
770 if(!g_Git.GetRemoteList(list))
772 for(unsigned int i=0;i<list.size();i++)
774 m_ctrlURL.AddString(list[i]);
777 m_ctrlURL.SetCurSel(0);
778 m_ctrlRemoteBranch.SetCurSel(0);
779 m_ctrlURL.SetURLHistory(true);
781 this->LoadBranchInfo();
783 this->m_bInited=true;
784 FetchOutList();
786 m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);
787 m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
788 m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
789 m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
791 m_ctrlRemoteBranch.m_bWantReturn = TRUE;
792 m_ctrlURL.m_bWantReturn = TRUE;
794 this->m_Gitverion = CAppUtils::GetMsysgitVersion();
796 return TRUE; // return TRUE unless you set the focus to a control
797 // EXCEPTION: OCX Property Pages should return FALSE
800 void CSyncDlg::OnBnClickedButtonManage()
802 CAppUtils::LaunchRemoteSetting();
803 Refresh();
806 void CSyncDlg::Refresh()
808 theApp.DoWaitCursor(1);
810 CString local;
811 CString remote;
812 CString url;
813 this->m_ctrlLocalBranch.GetWindowText(local);
814 this->m_ctrlRemoteBranch.GetWindowText(remote);
815 this->m_ctrlURL.GetWindowText(url);
817 this->LoadBranchInfo();
819 this->m_ctrlLocalBranch.AddString(local);
820 this->m_ctrlRemoteBranch.AddString(remote);
821 this->m_ctrlURL.AddString(url);
823 m_OutLogList.ShowText(_T("Refresh ..."));
824 this->FetchOutList(true);
825 theApp.DoWaitCursor(-1);
828 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)
830 if (pMsg->message == WM_KEYDOWN)
832 switch (pMsg->wParam)
835 case VK_F5:
837 if (m_bBlock)
838 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
839 Refresh();
841 break;
843 /* Avoid TAB control destroy but dialog exist*/
844 case VK_ESCAPE:
845 case VK_CANCEL:
847 TCHAR buff[128];
848 ::GetClassName(pMsg->hwnd,buff,128);
850 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0)
852 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
853 return TRUE;
858 m_tooltips.RelayEvent(pMsg);
859 return __super::PreTranslateMessage(pMsg);
861 void CSyncDlg::FetchOutList(bool force)
863 if(!m_bInited)
864 return;
865 m_OutChangeFileList.Clear();
866 this->m_OutLogList.Clear();
868 CString remote;
869 this->m_ctrlURL.GetWindowText(remote);
870 CString remotebranch;
871 this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
872 remotebranch=remote+_T("/")+remotebranch;
874 if(IsURL())
876 CString str;
877 str=_T("Don't know what will push because you enter URL");
878 m_OutLogList.ShowText(str);
879 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
880 m_OutLocalBranch.Empty();
881 m_OutRemoteBranch.Empty();
883 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
884 return ;
887 else if(g_Git.GetHash(remotebranch).IsEmpty())
889 CString str;
890 str.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch);
891 m_OutLogList.ShowText(str);
892 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
893 m_OutLocalBranch.Empty();
894 m_OutRemoteBranch.Empty();
896 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
897 return ;
899 else
901 CString localbranch;
902 localbranch=this->m_ctrlLocalBranch.GetString();
904 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)
906 m_OutLogList.ClearText();
907 m_OutLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
908 &remotebranch,&localbranch);
910 CString str;
911 if(m_OutLogList.GetItemCount() == 0)
913 str.Format(_T("No commits ahead \"%s\""),remotebranch);
914 m_OutLogList.ShowText(str);
915 this->m_ctrlStatus.SetWindowText(str);
916 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
917 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
919 else
921 str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);
922 this->m_ctrlStatus.SetWindowText(str);
924 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);
926 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);
927 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);
930 this->m_OutLocalBranch=localbranch;
931 this->m_OutRemoteBranch=remotebranch;
936 bool CSyncDlg::IsURL()
938 CString str;
939 this->m_ctrlURL.GetWindowText(str);
940 if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)
941 return true;
942 else
943 return false;
945 void CSyncDlg::OnCbnEditchangeComboboxex()
947 SetTimer(IDT_INPUT, 1000, NULL);
948 this->m_OutLogList.ShowText(_T("Wait for input"));
950 //this->FetchOutList();
953 UINT CSyncDlg::ProgressThread()
955 m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);
956 InterlockedExchange(&m_bBlock, FALSE);
957 return 0;
961 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)
963 if(wParam == MSG_PROGRESSDLG_START)
965 m_ctrlAnimate.Play(0,-1,-1);
966 this->m_ctrlProgress.SetPos(0);
967 if (m_pTaskbarList)
969 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NORMAL);
970 m_pTaskbarList->SetProgressValue(m_hWnd, 0, 100);
974 if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)
976 //m_bDone = true;
977 m_ctrlAnimate.Stop();
978 m_ctrlProgress.SetPos(100);
979 //this->DialogEnableWindow(IDOK,TRUE);
980 if (m_pTaskbarList)
981 m_pTaskbarList->SetProgressState(m_hWnd, TBPF_NOPROGRESS);
983 //if(wParam == MSG_PROGRESSDLG_END)
984 if(this->m_CurrentCmd == GIT_COMMAND_PUSH )
986 if(!m_GitCmdStatus)
988 CTGitPathList list;
989 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
990 DWORD exitcode;
991 CString error;
992 if (CHooks::Instance().PostPush(list,exitcode, error))
994 if (exitcode)
996 CString temp;
997 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
998 //ReportError(temp);
999 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
1000 return false;
1005 EnableControlButton(true);
1006 SwitchToInput();
1007 this->FetchOutList(true);
1009 if(this->m_CurrentCmd == GIT_COMMAND_PULL )
1011 PullComplete();
1013 if(this->m_CurrentCmd == GIT_COMMAND_FETCH || this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
1015 FetchComplete();
1017 if(this->m_CurrentCmd == GIT_COMMAND_SUBMODULE)
1019 //this->m_ctrlCmdOut.SetSel(-1,-1);
1020 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
1021 //this->m_ctrlCmdOut.SetSel(-1,-1);
1022 EnableControlButton(true);
1023 SwitchToInput();
1025 if(this->m_CurrentCmd == GIT_COMMAND_REMOTE)
1027 this->FetchOutList(true);
1028 EnableControlButton(true);
1029 SwitchToInput();
1033 if(lParam != 0)
1034 ParserCmdOutput((char)lParam);
1036 return 0;
1040 void CSyncDlg::ParserCmdOutput(char ch)
1042 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut,m_ctrlProgress,m_hWnd,m_pTaskbarList,m_LogText,ch);
1044 void CSyncDlg::OnBnClickedButtonCommit()
1046 CString proc=CPathUtils::GetAppDirectory();
1047 proc += _T("TortoiseProc.exe /command:commit");
1048 proc += _T(" /path:\"");
1049 proc += g_Git.m_CurrentDir;
1051 CAppUtils::LaunchApplication(proc,IDS_ERROR_CANNON_FIND_TORTOISEPROC,false);
1054 void CSyncDlg::OnOK()
1056 UpdateCombox();
1057 this->UpdateData();
1058 m_ctrlURL.SaveHistory();
1059 SaveHistory();
1060 m_regAutoLoadPutty = this->m_bAutoLoadPuttyKey;
1061 __super::OnOK();
1064 void CSyncDlg::OnBnClickedButtonSubmodule()
1066 this->UpdateData();
1067 UpdateCombox();
1069 this->m_regSubmoduleButton = this->m_ctrlSubmodule.GetCurrentEntry();
1071 this->SwitchToRun();
1073 this->m_bAbort=false;
1074 this->m_GitCmdList.clear();
1076 ShowTab(IDC_CMD_LOG);
1078 CString cmd;
1080 switch (m_ctrlSubmodule.GetCurrentEntry())
1082 case 0:
1083 cmd=_T("git.exe submodule update --init");
1084 break;
1085 case 1:
1086 cmd=_T("git.exe submodule init");
1087 break;
1088 case 2:
1089 cmd=_T("git.exe submodule sync");
1090 break;
1093 m_GitCmdList.push_back(cmd);
1095 m_CurrentCmd = GIT_COMMAND_SUBMODULE;
1097 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1098 if (m_pThread==NULL)
1100 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1102 else
1104 m_pThread->m_bAutoDelete = TRUE;
1105 m_pThread->ResumeThread();
1109 void CSyncDlg::OnTimer(UINT_PTR nIDEvent)
1111 if( nIDEvent == IDT_INPUT)
1113 KillTimer(IDT_INPUT);
1114 this->FetchOutList(true);
1118 LRESULT CSyncDlg::OnTaskbarBtnCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
1120 m_pTaskbarList.Release();
1121 m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList);
1122 return 0;