Clean up warning
[TortoiseGit.git] / src / TortoiseProc / SyncDlg.cpp
blob6069f3366070174f9aea200df538000a9a8e47b3
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 END_MESSAGE_MAP()
85 void CSyncDlg::EnableControlButton(bool bEnabled)
87 GetDlgItem(IDC_BUTTON_PULL)->EnableWindow(bEnabled);
88 GetDlgItem(IDC_BUTTON_PUSH)->EnableWindow(bEnabled);
89 GetDlgItem(IDC_BUTTON_APPLY)->EnableWindow(bEnabled);
90 GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(bEnabled);
91 GetDlgItem(IDOK)->EnableWindow(bEnabled);
92 GetDlgItem(IDC_BUTTON_SUBMODULE)->EnableWindow(bEnabled);
94 // CSyncDlg message handlers
96 void CSyncDlg::OnBnClickedButtonPull()
98 int CurrentEntry;
99 CurrentEntry = this->m_ctrlPull.GetCurrentEntry();
100 this->m_regPullButton = CurrentEntry;
102 this->m_bAbort=false;
103 this->m_GitCmdList.clear();
105 this->UpdateData();
106 UpdateCombox();
108 m_oldHash = g_Git.GetHash(_T("HEAD"));
110 if( CurrentEntry == 0)
112 if( g_Git.GetHash(this->m_strLocalBranch) != m_oldHash)
114 CMessageBox::Show(NULL,_T("Pull require local branch must be current branch"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
115 return;
119 if(this->m_strURL.IsEmpty())
121 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
122 return;
125 if(this->m_bAutoLoadPuttyKey)
127 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
130 this->SwitchToRun();
132 CString force;
133 if(this->m_bForce)
134 force = _T(" --force ");
136 CString cmd;
138 ShowTab(IDC_CMD_LOG);
140 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
141 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
142 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
144 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
146 ///Pull
147 if(CurrentEntry == 0) //Pull
149 CString remotebranch;
150 remotebranch = m_strRemoteBranch;
152 if(!IsURL())
154 CString configName;
155 configName.Format(L"branch.%s.merge", this->m_strLocalBranch);
156 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
158 configName.Format(L"branch.%s.remote", m_strLocalBranch);
159 CString pullRemote = g_Git.GetConfigValue(configName);
161 if(pullBranch == remotebranch && pullRemote == this->m_strURL)
162 remotebranch.Empty();
165 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
166 force += _T("--progress ");
168 cmd.Format(_T("git.exe pull -v %s \"%s\" %s"),
169 force,
170 m_strURL,
171 remotebranch);
173 m_CurrentCmd = GIT_COMMAND_PULL;
174 m_GitCmdList.push_back(cmd);
176 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
177 if (m_pThread==NULL)
179 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
181 else
183 m_pThread->m_bAutoDelete = TRUE;
184 m_pThread->ResumeThread();
189 ///Fetch
190 if(CurrentEntry == 1 || CurrentEntry ==2 ) //Fetch
192 CString remotebranch;
193 if(this->IsURL() || m_strRemoteBranch.IsEmpty())
195 remotebranch=this->m_strRemoteBranch;
197 }else
199 remotebranch.Format(_T("remotes/%s/%s"),
200 m_strURL,m_strRemoteBranch);
201 if(g_Git.GetHash(remotebranch).IsEmpty())
202 remotebranch=m_strRemoteBranch;
203 else
204 remotebranch=m_strRemoteBranch+_T(":")+remotebranch;
207 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
208 force += _T("--progress ");
210 cmd.Format(_T("git.exe fetch -v %s \"%s\" %s"),
211 force,
212 m_strURL,
213 remotebranch);
215 if(CurrentEntry == 1)
216 m_CurrentCmd = GIT_COMMAND_FETCH;
217 else
218 m_CurrentCmd = GIT_COMMAND_FETCHANDREBASE;
219 m_GitCmdList.push_back(cmd);
221 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
222 if (m_pThread==NULL)
224 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
226 else
228 m_pThread->m_bAutoDelete = TRUE;
229 m_pThread->ResumeThread();
233 ///Remote Update
234 if(CurrentEntry == 3)
236 m_CurrentCmd = GIT_COMMAND_REMOTE;
237 cmd=_T("git.exe remote update");
238 m_GitCmdList.push_back(cmd);
240 InterlockedExchange(&m_bBlock, TRUE);
242 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
243 if (m_pThread==NULL)
245 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
246 InterlockedExchange(&m_bBlock, FALSE);
248 else
250 m_pThread->m_bAutoDelete = TRUE;
251 m_pThread->ResumeThread();
256 void CSyncDlg::PullComplete()
258 EnableControlButton(true);
259 SwitchToInput();
260 this->FetchOutList(true);
262 CString newhash;
263 newhash = g_Git.GetHash(_T("HEAD"));
265 if( this ->m_GitCmdStatus )
267 CTGitPathList list;
268 if(g_Git.ListConflictFile(list))
270 this->m_ctrlCmdOut.SetSel(-1,-1);
271 this->m_ctrlCmdOut.ReplaceSel(_T("Get conflict files fail\n"));
273 this->ShowTab(IDC_CMD_LOG);
274 return;
277 if(list.GetCount()>0)
279 this->m_ConflictFileList.Clear();
280 CTGitPathList list;
281 CTGitPath path;
282 list.AddPath(path);
284 this->m_ConflictFileList.GetStatus(&list,true);
285 this->m_ConflictFileList.Show(CTGitPath::LOGACTIONS_UNMERGED,
286 CTGitPath::LOGACTIONS_UNMERGED);
288 this->ShowTab(IDC_IN_CONFLICT);
290 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_NORMAL);
292 else
293 this->ShowTab(IDC_CMD_LOG);
295 }else
297 if(newhash == this->m_oldHash)
299 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
300 this->m_InLogList.ShowText(_T("No commits get after pull"));
301 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
303 else
305 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
306 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
308 CString oldhash=m_oldHash.ToString();
309 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
311 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
312 &oldhash,&newhash);
314 this->ShowTab(IDC_IN_LOGLIST);
318 void CSyncDlg::FetchComplete()
320 EnableControlButton(true);
321 SwitchToInput();
322 this->FetchOutList(true);
324 ShowTab(IDC_CMD_LOG);
325 if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
327 CRebaseDlg dlg;
328 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
329 int response = dlg.DoModal();
330 if(response == IDOK)
332 return ;
335 if(response == IDC_REBASE_POST_BUTTON)
337 CString cmd,out;
338 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
339 g_Git.m_CurrentDir,
340 dlg.m_Upstream,dlg.m_Branch);
341 if(g_Git.Run(cmd,&out,CP_ACP))
343 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
344 return ;
347 CAppUtils::SendPatchMail(cmd,out);
352 void CSyncDlg::OnBnClickedButtonPush()
354 this->UpdateData();
355 UpdateCombox();
357 if(this->m_strURL.IsEmpty())
359 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
360 return;
363 this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();
364 this->SwitchToRun();
365 this->m_bAbort=false;
366 this->m_GitCmdList.clear();
368 ShowTab(IDC_CMD_LOG);
370 CString cmd;
371 CString arg;
373 CString error;
374 DWORD exitcode;
375 CTGitPathList list;
376 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
378 if (CHooks::Instance().PrePush(list,exitcode, error))
380 if (exitcode)
382 CString temp;
383 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
384 //ReportError(temp);
385 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
386 return ;
390 switch (m_ctrlPush.GetCurrentEntry())
392 case 1:
393 arg += _T(" --tags ");
394 break;
395 case 2:
396 arg += _T(" --all ");
397 break;
400 if(this->m_bForce)
401 arg += _T(" --force ");
403 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
404 arg += _T("--progress ");
406 cmd.Format(_T("git.exe push -v %s \"%s\" %s"),
407 arg,
408 m_strURL,
409 m_strLocalBranch);
411 if (!m_strRemoteBranch.IsEmpty())
413 cmd += _T(":") + m_strRemoteBranch;
416 m_GitCmdList.push_back(cmd);
418 m_CurrentCmd = GIT_COMMAND_PUSH;
420 if(this->m_bAutoLoadPuttyKey)
422 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
425 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
426 if (m_pThread==NULL)
428 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
430 else
432 m_pThread->m_bAutoDelete = TRUE;
433 m_pThread->ResumeThread();
437 void CSyncDlg::OnBnClickedButtonApply()
439 CString oldhash;
440 oldhash=g_Git.GetHash(_T("HEAD"));
442 CImportPatchDlg dlg;
443 CString cmd,output;
445 if(dlg.DoModal() == IDOK)
447 int err=0;
448 for(int i=0;i<dlg.m_PathList.GetCount();i++)
450 cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());
452 if(g_Git.Run(cmd,&output,CP_ACP))
454 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);
456 err=1;
457 break;
459 this->m_ctrlCmdOut.SetSel(-1,-1);
460 this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));
461 this->m_ctrlCmdOut.SetSel(-1,-1);
462 this->m_ctrlCmdOut.ReplaceSel(output);
465 CString newhash=g_Git.GetHash(_T("HEAD"));
467 this->m_InLogList.Clear();
468 this->m_InChangeFileList.Clear();
470 if(newhash == oldhash)
472 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
473 this->m_InLogList.ShowText(_T("No commits get from patch"));
474 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
476 }else
478 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
479 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
481 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
482 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
483 &oldhash,&newhash);
485 this->FetchOutList(true);
488 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);
490 if(err)
492 this->ShowTab(IDC_CMD_LOG);
493 }else
495 this->ShowTab(IDC_IN_LOGLIST);
500 void CSyncDlg::OnBnClickedButtonEmail()
502 CString cmd,out;
504 this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();
505 this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);
506 this->m_ctrlURL.GetWindowText(this->m_strURL);
507 m_strURL=m_strURL.Trim();
508 m_strRemoteBranch=m_strRemoteBranch.Trim();
510 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
511 g_Git.m_CurrentDir,
512 m_strURL+_T('/')+m_strRemoteBranch,m_strLocalBranch);
514 if(g_Git.Run(cmd,&out,CP_ACP))
516 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
517 return ;
520 CAppUtils::SendPatchMail(cmd,out);
523 void CSyncDlg::ShowProgressCtrl(bool bShow)
525 int b=bShow?SW_NORMAL:SW_HIDE;
526 this->m_ctrlAnimate.ShowWindow(b);
527 this->m_ctrlProgress.ShowWindow(b);
528 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
529 if(b == SW_NORMAL)
530 this->m_ctrlAnimate.Play(0,-1,-1);
531 else
532 this->m_ctrlAnimate.Stop();
534 void CSyncDlg::ShowInputCtrl(bool bShow)
536 int b=bShow?SW_NORMAL:SW_HIDE;
537 this->m_ctrlURL.ShowWindow(b);
538 this->m_ctrlLocalBranch.ShowWindow(b);
539 this->m_ctrlRemoteBranch.ShowWindow(b);
540 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);
541 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);
542 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);
543 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);
544 this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);
545 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);
546 this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);
547 this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);
549 BOOL CSyncDlg::OnInitDialog()
551 CResizableStandAloneDialog::OnInitDialog();
554 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->EnableWindow(CAppUtils::IsSSHPutty());
557 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
558 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
559 this->m_ctrlAnimate.Play(0,-1,-1);
562 // ------------------ Create Tabctrl -----------
563 CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);
564 CRect rectDummy;
565 pwnd->GetWindowRect(&rectDummy);
566 this->ScreenToClient(rectDummy);
568 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))
570 TRACE0("Failed to create output tab window\n");
571 return FALSE; // fail to create
573 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
575 // -------------Create Command Log Ctrl ---------
576 DWORD dwStyle;
577 dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL ;
579 if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))
581 TRACE0("Failed to create Log commits window\n");
582 return FALSE; // fail to create
585 CHARFORMAT m_Format;
586 memset(&m_Format, 0, sizeof(CHARFORMAT));
587 m_Format.cbSize = sizeof(CHARFORMAT);
588 m_Format.dwMask = CFM_FACE | CFM_BOLD;
589 wcsncpy(m_Format.szFaceName, L"Courier New", LF_FACESIZE - 1);
590 m_ctrlCmdOut.SetDefaultCharFormat(m_Format);
592 m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut,_T("Log"),-1);
594 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
596 //---------- Create in coming list ctrl -----------
597 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
599 if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))
601 TRACE0("Failed to create output commits window\n");
602 return FALSE; // fail to create
605 m_ctrlTabCtrl.InsertTab(&m_InLogList,_T("In Commits"),-1);
607 m_InLogList.m_ColumnRegKey=_T("SyncIn");
608 m_InLogList.InsertGitColumn();
610 //----------- Create In Change file list -----------
611 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
613 if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))
615 TRACE0("Failed to create output change files window\n");
616 return FALSE; // fail to create
618 m_ctrlTabCtrl.InsertTab(&m_InChangeFileList,_T("In ChangeList"),-1);
620 m_InChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
621 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
622 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);
625 //---------- Create Conflict List Ctrl -----------------
626 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
628 if( !m_ConflictFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CONFLICT))
630 TRACE0("Failed to create output change files window\n");
631 return FALSE; // fail to create
633 m_ctrlTabCtrl.InsertTab(&m_ConflictFileList,_T("Conflict"),-1);
635 m_ConflictFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
636 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
637 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)|
638 SVNSLC_POPCONFLICT|SVNSLC_POPRESOLVE),false);
641 //---------- Create Commit Out List Ctrl---------------
643 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
645 if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))
647 TRACE0("Failed to create output commits window\n");
648 return FALSE; // fail to create
652 m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),-1);
654 m_OutLogList.m_ColumnRegKey = _T("SyncOut");
655 m_OutLogList.InsertGitColumn();
657 //------------- Create Change File List Control ----------------
659 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
661 if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))
663 TRACE0("Failed to create output change files window\n");
664 return FALSE; // fail to create
666 m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),-1);
668 m_OutChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
669 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
670 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);
672 this->m_tooltips.Create(this);
674 AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);
676 AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);
677 AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);
678 AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);
679 AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);
680 AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);
681 AddAnchor(IDC_BUTTON_SUBMODULE,BOTTOM_LEFT);
682 AddAnchor(IDC_BUTTON_APPLY,BOTTOM_RIGHT);
683 AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_RIGHT);
684 AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);
685 AddAnchor(IDOK,BOTTOM_RIGHT);
686 AddAnchor(IDHELP,BOTTOM_RIGHT);
687 AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);
688 AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);
689 AddAnchor(IDC_BUTTON_COMMIT,BOTTOM_LEFT);
691 BRANCH_COMBOX_ADD_ANCHOR();
693 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
695 CString WorkingDir=g_Git.m_CurrentDir;
696 WorkingDir.Replace(_T(':'),_T('_'));
697 m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;
700 this->AddOthersToAnchor();
702 this->m_ctrlPush.AddEntry(CString(_T("Pus&h")));
703 this->m_ctrlPush.AddEntry(CString(_T("Push ta&gs")));
704 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
706 this->m_ctrlPull.AddEntry(CString(_T("&Pull")));
707 this->m_ctrlPull.AddEntry(CString(_T("Fetc&h")));
708 this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Re&base")));
709 this->m_ctrlPull.AddEntry(CString(_T("Remote Update")));
711 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Update")));
712 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Init")));
713 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Sync")));
715 WorkingDir.Replace(_T(':'),_T('_'));
717 CString regkey ;
718 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);
720 this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);
721 this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);
722 this->m_regSubmoduleButton = CRegDWORD(regkey+_T("\\Submodule"));
723 this->m_regAutoLoadPutty = CRegDWORD(regkey + _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
725 this->UpdateData();
726 this->m_bAutoLoadPuttyKey = m_regAutoLoadPutty;
727 if(!CAppUtils::IsSSHPutty())
728 m_bAutoLoadPuttyKey = false;
729 this->UpdateData(FALSE);
731 this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);
732 this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);
733 this->m_ctrlSubmodule.SetCurrentEntry(this->m_regSubmoduleButton);
735 CString str;
736 this->GetWindowText(str);
737 str += _T(" - ") + g_Git.m_CurrentDir;
738 this->SetWindowText(str);
740 EnableSaveRestore(_T("SyncDlg"));
742 this->m_ctrlURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir, _T("url"));
744 STRING_VECTOR list;
746 if(!g_Git.GetRemoteList(list))
748 for(unsigned int i=0;i<list.size();i++)
750 m_ctrlURL.AddString(list[i]);
753 m_ctrlURL.SetCurSel(0);
754 m_ctrlRemoteBranch.SetCurSel(0);
755 m_ctrlURL.SetURLHistory(true);
757 this->LoadBranchInfo();
759 this->m_bInited=true;
760 FetchOutList();
762 m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);
763 m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
764 m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
765 m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
767 m_ctrlRemoteBranch.m_bWantReturn = TRUE;
768 m_ctrlURL.m_bWantReturn = TRUE;
770 this->m_Gitverion = CAppUtils::GetMsysgitVersion();
772 return TRUE; // return TRUE unless you set the focus to a control
773 // EXCEPTION: OCX Property Pages should return FALSE
776 void CSyncDlg::OnBnClickedButtonManage()
778 CAppUtils::LaunchRemoteSetting();
779 Refresh();
782 void CSyncDlg::Refresh()
784 theApp.DoWaitCursor(1);
786 CString local;
787 CString remote;
788 CString url;
789 this->m_ctrlLocalBranch.GetWindowText(local);
790 this->m_ctrlRemoteBranch.GetWindowText(remote);
791 this->m_ctrlURL.GetWindowText(url);
793 this->LoadBranchInfo();
795 this->m_ctrlLocalBranch.AddString(local);
796 this->m_ctrlRemoteBranch.AddString(remote);
797 this->m_ctrlURL.AddString(url);
799 m_OutLogList.ShowText(_T("Refresh ..."));
800 this->FetchOutList(true);
801 theApp.DoWaitCursor(-1);
804 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)
806 if (pMsg->message == WM_KEYDOWN)
808 switch (pMsg->wParam)
811 case VK_F5:
813 if (m_bBlock)
814 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
815 Refresh();
817 break;
819 /* Avoid TAB control destroy but dialog exist*/
820 case VK_ESCAPE:
821 case VK_CANCEL:
823 TCHAR buff[128];
824 ::GetClassName(pMsg->hwnd,buff,128);
826 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0)
828 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
829 return TRUE;
834 m_tooltips.RelayEvent(pMsg);
835 return __super::PreTranslateMessage(pMsg);
837 void CSyncDlg::FetchOutList(bool force)
839 if(!m_bInited)
840 return;
841 m_OutChangeFileList.Clear();
842 this->m_OutLogList.Clear();
844 CString remote;
845 this->m_ctrlURL.GetWindowText(remote);
846 CString remotebranch;
847 this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
848 remotebranch=remote+_T("/")+remotebranch;
850 if(IsURL())
852 CString str;
853 str=_T("Don't know what will push because you enter URL");
854 m_OutLogList.ShowText(str);
855 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
856 m_OutLocalBranch.Empty();
857 m_OutRemoteBranch.Empty();
859 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
860 return ;
863 else if(g_Git.GetHash(remotebranch).IsEmpty())
865 CString str;
866 str.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch);
867 m_OutLogList.ShowText(str);
868 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
869 m_OutLocalBranch.Empty();
870 m_OutRemoteBranch.Empty();
872 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
873 return ;
875 else
877 CString localbranch;
878 localbranch=this->m_ctrlLocalBranch.GetString();
880 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)
882 m_OutLogList.ClearText();
883 m_OutLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
884 &remotebranch,&localbranch);
886 CString str;
887 if(m_OutLogList.GetItemCount() == 0)
889 str.Format(_T("No commits ahead \"%s\""),remotebranch);
890 m_OutLogList.ShowText(str);
891 this->m_ctrlStatus.SetWindowText(str);
892 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
893 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
895 else
897 str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);
898 this->m_ctrlStatus.SetWindowText(str);
900 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);
902 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);
903 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);
906 this->m_OutLocalBranch=localbranch;
907 this->m_OutRemoteBranch=remotebranch;
912 bool CSyncDlg::IsURL()
914 CString str;
915 this->m_ctrlURL.GetWindowText(str);
916 if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)
917 return true;
918 else
919 return false;
921 void CSyncDlg::OnCbnEditchangeComboboxex()
923 SetTimer(IDT_INPUT, 1000, NULL);
924 this->m_OutLogList.ShowText(_T("Wait for input"));
926 //this->FetchOutList();
929 UINT CSyncDlg::ProgressThread()
931 m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);
932 InterlockedExchange(&m_bBlock, FALSE);
933 return 0;
937 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)
939 if(wParam == MSG_PROGRESSDLG_START)
941 m_ctrlAnimate.Play(0,-1,-1);
942 this->m_ctrlProgress.SetPos(0);
945 if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)
947 //m_bDone = true;
948 m_ctrlAnimate.Stop();
949 m_ctrlProgress.SetPos(100);
950 //this->DialogEnableWindow(IDOK,TRUE);
952 //if(wParam == MSG_PROGRESSDLG_END)
953 if(this->m_CurrentCmd == GIT_COMMAND_PUSH )
955 if(!m_GitCmdStatus)
957 CTGitPathList list;
958 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
959 DWORD exitcode;
960 CString error;
961 if (CHooks::Instance().PostPush(list,exitcode, error))
963 if (exitcode)
965 CString temp;
966 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
967 //ReportError(temp);
968 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
969 return false;
974 EnableControlButton(true);
975 SwitchToInput();
976 this->FetchOutList(true);
978 if(this->m_CurrentCmd == GIT_COMMAND_PULL )
980 PullComplete();
982 if(this->m_CurrentCmd == GIT_COMMAND_FETCH || this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
984 FetchComplete();
986 if(this->m_CurrentCmd == GIT_COMMAND_SUBMODULE)
988 //this->m_ctrlCmdOut.SetSel(-1,-1);
989 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
990 //this->m_ctrlCmdOut.SetSel(-1,-1);
991 EnableControlButton(true);
992 SwitchToInput();
994 if(this->m_CurrentCmd == GIT_COMMAND_REMOTE)
996 this->FetchOutList(true);
997 EnableControlButton(true);
998 SwitchToInput();
1002 if(lParam != 0)
1003 ParserCmdOutput((char)lParam);
1005 return 0;
1009 void CSyncDlg::ParserCmdOutput(char ch)
1011 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut,m_ctrlProgress,m_LogText,ch);
1013 void CSyncDlg::OnBnClickedButtonCommit()
1015 CString proc=CPathUtils::GetAppDirectory();
1016 proc += _T("TortoiseProc.exe /command:commit");
1017 proc += _T(" /path:\"");
1018 proc += g_Git.m_CurrentDir;
1020 CAppUtils::LaunchApplication(proc,IDS_ERROR_CANNON_FIND_TORTOISEPROC,false);
1023 void CSyncDlg::OnOK()
1025 UpdateCombox();
1026 this->UpdateData();
1027 m_ctrlURL.SaveHistory();
1028 SaveHistory();
1029 m_regAutoLoadPutty = this->m_bAutoLoadPuttyKey;
1030 __super::OnOK();
1033 void CSyncDlg::OnBnClickedButtonSubmodule()
1035 this->UpdateData();
1036 UpdateCombox();
1038 this->m_regSubmoduleButton = this->m_ctrlSubmodule.GetCurrentEntry();
1040 this->SwitchToRun();
1042 this->m_bAbort=false;
1043 this->m_GitCmdList.clear();
1045 ShowTab(IDC_CMD_LOG);
1047 CString cmd;
1049 switch (m_ctrlSubmodule.GetCurrentEntry())
1051 case 0:
1052 cmd=_T("git.exe submodule update --init");
1053 break;
1054 case 1:
1055 cmd=_T("git.exe submodule init");
1056 break;
1057 case 2:
1058 cmd=_T("git.exe submodule sync");
1059 break;
1062 m_GitCmdList.push_back(cmd);
1064 m_CurrentCmd = GIT_COMMAND_SUBMODULE;
1066 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1067 if (m_pThread==NULL)
1069 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1071 else
1073 m_pThread->m_bAutoDelete = TRUE;
1074 m_pThread->ResumeThread();
1078 void CSyncDlg::OnTimer(UINT_PTR nIDEvent)
1080 if( nIDEvent == IDT_INPUT)
1082 KillTimer(IDT_INPUT);
1083 this->FetchOutList(true);