use gitdll gethash and clean up some warning
[TortoiseGit.git] / src / TortoiseProc / SyncDlg.cpp
blobdc1d8cccb37a573090499b6e785f4fd41bad7b8b
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 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,m_oldHash.ToString());
310 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
311 &this->m_oldHash.ToString(),&newhash);
313 this->ShowTab(IDC_IN_LOGLIST);
317 void CSyncDlg::FetchComplete()
319 EnableControlButton(true);
320 SwitchToInput();
321 this->FetchOutList(true);
323 ShowTab(IDC_CMD_LOG);
324 if( (!this->m_GitCmdStatus) && this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
326 CRebaseDlg dlg;
327 dlg.m_PostButtonTexts.Add(_T("Email &Patch..."));
328 int response = dlg.DoModal();
329 if(response == IDOK)
331 return ;
334 if(response == IDC_REBASE_POST_BUTTON)
336 CString cmd,out;
337 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
338 g_Git.m_CurrentDir,
339 dlg.m_Upstream,dlg.m_Branch);
340 if(g_Git.Run(cmd,&out,CP_ACP))
342 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
343 return ;
346 CAppUtils::SendPatchMail(cmd,out);
351 void CSyncDlg::OnBnClickedButtonPush()
353 this->UpdateData();
354 UpdateCombox();
356 if(this->m_strURL.IsEmpty())
358 CMessageBox::Show(NULL,_T("URL can't Empty"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
359 return;
362 this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();
363 this->SwitchToRun();
364 this->m_bAbort=false;
365 this->m_GitCmdList.clear();
367 ShowTab(IDC_CMD_LOG);
369 CString cmd;
370 CString arg;
372 CString error;
373 DWORD exitcode;
374 CTGitPathList list;
375 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
377 if (CHooks::Instance().PrePush(list,exitcode, error))
379 if (exitcode)
381 CString temp;
382 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
383 //ReportError(temp);
384 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
385 return ;
389 switch (m_ctrlPush.GetCurrentEntry())
391 case 1:
392 arg += _T(" --tags ");
393 break;
394 case 2:
395 arg += _T(" --all ");
396 break;
399 if(this->m_bForce)
400 arg += _T(" --force ");
402 if(m_Gitverion >= 0x01070203) //above 1.7.0.2
403 arg += _T("--progress ");
405 cmd.Format(_T("git.exe push -v %s \"%s\" %s"),
406 arg,
407 m_strURL,
408 m_strLocalBranch);
410 if (!m_strRemoteBranch.IsEmpty())
412 cmd += _T(":") + m_strRemoteBranch;
415 m_GitCmdList.push_back(cmd);
417 m_CurrentCmd = GIT_COMMAND_PUSH;
419 if(this->m_bAutoLoadPuttyKey)
421 CAppUtils::LaunchPAgent(NULL,&this->m_strURL);
424 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
425 if (m_pThread==NULL)
427 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
429 else
431 m_pThread->m_bAutoDelete = TRUE;
432 m_pThread->ResumeThread();
436 void CSyncDlg::OnBnClickedButtonApply()
438 CString oldhash;
439 oldhash=g_Git.GetHash(_T("HEAD"));
441 CImportPatchDlg dlg;
442 CString cmd,output;
444 if(dlg.DoModal() == IDOK)
446 int err=0;
447 for(int i=0;i<dlg.m_PathList.GetCount();i++)
449 cmd.Format(_T("git.exe am \"%s\""),dlg.m_PathList[i].GetGitPathString());
451 if(g_Git.Run(cmd,&output,CP_ACP))
453 CMessageBox::Show(NULL,output,_T("TortoiseGit"),MB_OK);
455 err=1;
456 break;
458 this->m_ctrlCmdOut.SetSel(-1,-1);
459 this->m_ctrlCmdOut.ReplaceSel(cmd+_T("\n"));
460 this->m_ctrlCmdOut.SetSel(-1,-1);
461 this->m_ctrlCmdOut.ReplaceSel(output);
464 CString newhash=g_Git.GetHash(_T("HEAD"));
466 this->m_InLogList.Clear();
467 this->m_InChangeFileList.Clear();
469 if(newhash == oldhash)
471 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
472 this->m_InLogList.ShowText(_T("No commits get from patch"));
473 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
475 }else
477 this->m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,true);
478 this->m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,true);
480 this->AddDiffFileList(&m_InChangeFileList,&m_arInChangeList,newhash,oldhash);
481 m_InLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
482 &oldhash,&newhash);
484 this->FetchOutList(true);
487 this->m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,true);
489 if(err)
491 this->ShowTab(IDC_CMD_LOG);
492 }else
494 this->ShowTab(IDC_IN_LOGLIST);
499 void CSyncDlg::OnBnClickedButtonEmail()
501 CString cmd,out;
503 this->m_strLocalBranch = this->m_ctrlLocalBranch.GetString();
504 this->m_ctrlRemoteBranch.GetWindowText(this->m_strRemoteBranch);
505 this->m_ctrlURL.GetWindowText(this->m_strURL);
506 m_strURL=m_strURL.Trim();
507 m_strRemoteBranch=m_strRemoteBranch.Trim();
509 cmd.Format(_T("git.exe format-patch -o \"%s\" %s..%s"),
510 g_Git.m_CurrentDir,
511 m_strURL+_T('/')+m_strRemoteBranch,m_strLocalBranch);
513 if(g_Git.Run(cmd,&out,CP_ACP))
515 CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
516 return ;
519 CAppUtils::SendPatchMail(cmd,out);
522 void CSyncDlg::ShowProgressCtrl(bool bShow)
524 int b=bShow?SW_NORMAL:SW_HIDE;
525 this->m_ctrlAnimate.ShowWindow(b);
526 this->m_ctrlProgress.ShowWindow(b);
527 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
528 if(b == SW_NORMAL)
529 this->m_ctrlAnimate.Play(0,-1,-1);
530 else
531 this->m_ctrlAnimate.Stop();
533 void CSyncDlg::ShowInputCtrl(bool bShow)
535 int b=bShow?SW_NORMAL:SW_HIDE;
536 this->m_ctrlURL.ShowWindow(b);
537 this->m_ctrlLocalBranch.ShowWindow(b);
538 this->m_ctrlRemoteBranch.ShowWindow(b);
539 this->GetDlgItem(IDC_BUTTON_LOCAL_BRANCH)->ShowWindow(b);
540 this->GetDlgItem(IDC_BUTTON_REMOTE_BRANCH)->ShowWindow(b);
541 this->GetDlgItem(IDC_STATIC_LOCAL_BRANCH)->ShowWindow(b);
542 this->GetDlgItem(IDC_STATIC_REMOTE_BRANCH)->ShowWindow(b);
543 this->GetDlgItem(IDC_BUTTON_MANAGE)->ShowWindow(b);
544 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->ShowWindow(b);
545 this->GetDlgItem(IDC_CHECK_FORCE)->ShowWindow(b);
546 this->GetDlgItem(IDC_STATIC_REMOTE_URL)->ShowWindow(b);
548 BOOL CSyncDlg::OnInitDialog()
550 CResizableStandAloneDialog::OnInitDialog();
553 this->GetDlgItem(IDC_CHECK_PUTTY_KEY)->EnableWindow(CAppUtils::IsSSHPutty());
556 this->m_ctrlAnimate.ShowWindow(SW_NORMAL);
557 this->m_ctrlAnimate.Open(IDR_DOWNLOAD);
558 this->m_ctrlAnimate.Play(0,-1,-1);
561 // ------------------ Create Tabctrl -----------
562 CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);
563 CRect rectDummy;
564 pwnd->GetWindowRect(&rectDummy);
565 this->ScreenToClient(rectDummy);
567 if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))
569 TRACE0("Failed to create output tab window\n");
570 return FALSE; // fail to create
572 m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
574 // -------------Create Command Log Ctrl ---------
575 DWORD dwStyle;
576 dwStyle= ES_MULTILINE | ES_READONLY | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL |WS_VSCROLL ;
578 if( !m_ctrlCmdOut.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_CMD_LOG))
580 TRACE0("Failed to create Log commits window\n");
581 return FALSE; // fail to create
584 CHARFORMAT m_Format;
585 memset(&m_Format, 0, sizeof(CHARFORMAT));
586 m_Format.cbSize = sizeof(CHARFORMAT);
587 m_Format.dwMask = CFM_FACE | CFM_BOLD;
588 wcsncpy(m_Format.szFaceName, L"Courier New", LF_FACESIZE - 1);
589 m_ctrlCmdOut.SetDefaultCharFormat(m_Format);
591 m_ctrlTabCtrl.InsertTab(&m_ctrlCmdOut,_T("Log"),-1);
593 //m_ctrlCmdOut.ReplaceSel(_T("Hello"));
595 //---------- Create in coming list ctrl -----------
596 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
598 if( !m_InLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_LOGLIST))
600 TRACE0("Failed to create output commits window\n");
601 return FALSE; // fail to create
604 m_ctrlTabCtrl.InsertTab(&m_InLogList,_T("In Commits"),-1);
606 m_InLogList.m_ColumnRegKey=_T("SyncIn");
607 m_InLogList.InsertGitColumn();
609 //----------- Create In Change file list -----------
610 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
612 if( !m_InChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CHANGELIST))
614 TRACE0("Failed to create output change files window\n");
615 return FALSE; // fail to create
617 m_ctrlTabCtrl.InsertTab(&m_InChangeFileList,_T("In ChangeList"),-1);
619 m_InChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
620 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
621 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);
624 //---------- Create Conflict List Ctrl -----------------
625 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
627 if( !m_ConflictFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_IN_CONFLICT))
629 TRACE0("Failed to create output change files window\n");
630 return FALSE; // fail to create
632 m_ctrlTabCtrl.InsertTab(&m_ConflictFileList,_T("Conflict"),-1);
634 m_ConflictFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
635 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
636 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)|
637 SVNSLC_POPCONFLICT|SVNSLC_POPRESOLVE),false);
640 //---------- Create Commit Out List Ctrl---------------
642 dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE;;
644 if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))
646 TRACE0("Failed to create output commits window\n");
647 return FALSE; // fail to create
651 m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),-1);
653 m_OutLogList.m_ColumnRegKey = _T("SyncOut");
654 m_OutLogList.InsertGitColumn();
656 //------------- Create Change File List Control ----------------
658 dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;
660 if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))
662 TRACE0("Failed to create output change files window\n");
663 return FALSE; // fail to create
665 m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),-1);
667 m_OutChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("OutSyncDlg"),
668 (CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_COMPARETWO)|
669 CGitStatusListCtrl::GetContextMenuBit(CGitStatusListCtrl::IDSVNLC_GNUDIFF2)),false);
671 this->m_tooltips.Create(this);
673 AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);
675 AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);
676 AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);
677 AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);
678 AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);
679 AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);
680 AddAnchor(IDC_BUTTON_SUBMODULE,BOTTOM_LEFT);
681 AddAnchor(IDC_BUTTON_APPLY,BOTTOM_RIGHT);
682 AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_RIGHT);
683 AddAnchor(IDC_PROGRESS_SYNC,TOP_LEFT,TOP_RIGHT);
684 AddAnchor(IDOK,BOTTOM_RIGHT);
685 AddAnchor(IDHELP,BOTTOM_RIGHT);
686 AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);
687 AddAnchor(IDC_ANIMATE_SYNC,TOP_LEFT);
688 AddAnchor(IDC_BUTTON_COMMIT,BOTTOM_LEFT);
690 BRANCH_COMBOX_ADD_ANCHOR();
692 this->GetDlgItem(IDC_BUTTON_COMMIT)->ShowWindow(SW_HIDE);
694 CString WorkingDir=g_Git.m_CurrentDir;
695 WorkingDir.Replace(_T(':'),_T('_'));
696 m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;
699 this->AddOthersToAnchor();
701 this->m_ctrlPush.AddEntry(CString(_T("Pus&h")));
702 this->m_ctrlPush.AddEntry(CString(_T("Push ta&gs")));
703 ///this->m_ctrlPush.AddEntry(CString(_T("Push All")));
705 this->m_ctrlPull.AddEntry(CString(_T("&Pull")));
706 this->m_ctrlPull.AddEntry(CString(_T("Fetc&h")));
707 this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Re&base"))); // TODO: what's this?
708 this->m_ctrlPull.AddEntry(CString(_T("Remote Update")));
710 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Update")));
711 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Init")));
712 this->m_ctrlSubmodule.AddEntry(CString(_T("Submodule Sync")));
714 WorkingDir.Replace(_T(':'),_T('_'));
716 CString regkey ;
717 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);
719 this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);
720 this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);
721 this->m_regSubmoduleButton = CRegDWORD(regkey+_T("\\Submodule"));
722 this->m_regAutoLoadPutty = CRegDWORD(regkey + _T("\\AutoLoadPutty"), CAppUtils::IsSSHPutty());
724 this->UpdateData();
725 this->m_bAutoLoadPuttyKey = m_regAutoLoadPutty;
726 if(!CAppUtils::IsSSHPutty())
727 m_bAutoLoadPuttyKey = false;
728 this->UpdateData(FALSE);
730 this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);
731 this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);
732 this->m_ctrlSubmodule.SetCurrentEntry(this->m_regSubmoduleButton);
734 CString str;
735 this->GetWindowText(str);
736 str += _T(" - ") + g_Git.m_CurrentDir;
737 this->SetWindowText(str);
739 EnableSaveRestore(_T("SyncDlg"));
741 this->m_ctrlURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\SyncURL\\"))+WorkingDir, _T("url"));
743 STRING_VECTOR list;
745 if(!g_Git.GetRemoteList(list))
747 for(unsigned int i=0;i<list.size();i++)
749 m_ctrlURL.AddString(list[i]);
752 m_ctrlURL.SetCurSel(0);
753 m_ctrlRemoteBranch.SetCurSel(0);
754 m_ctrlURL.SetURLHistory(true);
756 this->LoadBranchInfo();
758 this->m_bInited=true;
759 FetchOutList();
761 m_ctrlTabCtrl.ShowTab(IDC_CMD_LOG-1,false);
762 m_ctrlTabCtrl.ShowTab(IDC_IN_LOGLIST-1,false);
763 m_ctrlTabCtrl.ShowTab(IDC_IN_CHANGELIST-1,false);
764 m_ctrlTabCtrl.ShowTab(IDC_IN_CONFLICT-1,false);
766 m_ctrlRemoteBranch.m_bWantReturn = TRUE;
767 m_ctrlURL.m_bWantReturn = TRUE;
769 this->m_Gitverion = CAppUtils::GetMsysgitVersion();
771 return TRUE; // return TRUE unless you set the focus to a control
772 // EXCEPTION: OCX Property Pages should return FALSE
775 void CSyncDlg::OnBnClickedButtonManage()
777 CAppUtils::LaunchRemoteSetting();
778 Refresh();
781 void CSyncDlg::Refresh()
783 theApp.DoWaitCursor(1);
785 CString local;
786 CString remote;
787 CString url;
788 this->m_ctrlLocalBranch.GetWindowText(local);
789 this->m_ctrlRemoteBranch.GetWindowText(remote);
790 this->m_ctrlURL.GetWindowText(url);
792 this->LoadBranchInfo();
794 this->m_ctrlLocalBranch.AddString(local);
795 this->m_ctrlRemoteBranch.AddString(remote);
796 this->m_ctrlURL.AddString(url);
798 m_OutLogList.ShowText(_T("Refresh ..."));
799 this->FetchOutList(true);
800 theApp.DoWaitCursor(-1);
803 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)
805 if (pMsg->message == WM_KEYDOWN)
807 switch (pMsg->wParam)
810 case VK_F5:
812 if (m_bBlock)
813 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
814 Refresh();
816 break;
818 /* Avoid TAB control destroy but dialog exist*/
819 case VK_ESCAPE:
820 case VK_CANCEL:
822 TCHAR buff[128];
823 ::GetClassName(pMsg->hwnd,buff,128);
825 if(_tcsnicmp(buff,_T("RichEdit20W"),128)==0)
827 this->PostMessage(WM_KEYDOWN,VK_ESCAPE,0);
828 return TRUE;
833 m_tooltips.RelayEvent(pMsg);
834 return __super::PreTranslateMessage(pMsg);
836 void CSyncDlg::FetchOutList(bool force)
838 if(!m_bInited)
839 return;
840 m_OutChangeFileList.Clear();
841 this->m_OutLogList.Clear();
843 CString remote;
844 this->m_ctrlURL.GetWindowText(remote);
845 CString remotebranch;
846 this->m_ctrlRemoteBranch.GetWindowText(remotebranch);
847 remotebranch=remote+_T("/")+remotebranch;
849 if(IsURL())
851 CString str;
852 str=_T("Don't know what will push because you enter URL");
853 m_OutLogList.ShowText(str);
854 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
855 m_OutLocalBranch.Empty();
856 m_OutRemoteBranch.Empty();
858 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
859 return ;
862 else if(g_Git.GetHash(remotebranch).IsEmpty())
864 CString str;
865 str.Format(_T("Don't know what will push because unknown \"%s\""),remotebranch);
866 m_OutLogList.ShowText(str);
867 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
868 m_OutLocalBranch.Empty();
869 m_OutRemoteBranch.Empty();
871 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
872 return ;
874 else
876 CString localbranch;
877 localbranch=this->m_ctrlLocalBranch.GetString();
879 if(localbranch != m_OutLocalBranch || m_OutRemoteBranch != remotebranch || force)
881 m_OutLogList.ClearText();
882 m_OutLogList.FillGitLog(NULL,CGit:: LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,
883 &remotebranch,&localbranch);
885 CString str;
886 if(m_OutLogList.GetItemCount() == 0)
888 str.Format(_T("No commits ahead \"%s\""),remotebranch);
889 m_OutLogList.ShowText(str);
890 this->m_ctrlStatus.SetWindowText(str);
891 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);
892 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(FALSE);
894 else
896 str.Format(_T("%d commits ahead \"%s\""),m_OutLogList.GetItemCount(),remotebranch);
897 this->m_ctrlStatus.SetWindowText(str);
899 AddDiffFileList(&m_OutChangeFileList,&m_arOutChangeList,localbranch,remotebranch);
901 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,TRUE);
902 this->GetDlgItem(IDC_BUTTON_EMAIL)->EnableWindow(TRUE);
905 this->m_OutLocalBranch=localbranch;
906 this->m_OutRemoteBranch=remotebranch;
911 bool CSyncDlg::IsURL()
913 CString str;
914 this->m_ctrlURL.GetWindowText(str);
915 if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)
916 return true;
917 else
918 return false;
920 void CSyncDlg::OnCbnEditchangeComboboxex()
922 SetTimer(IDT_INPUT, 1000, NULL);
923 this->m_OutLogList.ShowText(_T("Wait for input"));
925 //this->FetchOutList();
928 UINT CSyncDlg::ProgressThread()
930 m_GitCmdStatus=CProgressDlg::RunCmdList(this,m_GitCmdList,true,NULL,&this->m_bAbort);
931 InterlockedExchange(&m_bBlock, FALSE);
932 return 0;
936 LRESULT CSyncDlg::OnProgressUpdateUI(WPARAM wParam,LPARAM lParam)
938 if(wParam == MSG_PROGRESSDLG_START)
940 m_ctrlAnimate.Play(0,-1,-1);
941 this->m_ctrlProgress.SetPos(0);
944 if(wParam == MSG_PROGRESSDLG_END || wParam == MSG_PROGRESSDLG_FAILED)
946 //m_bDone = true;
947 m_ctrlAnimate.Stop();
948 m_ctrlProgress.SetPos(100);
949 //this->DialogEnableWindow(IDOK,TRUE);
951 //if(wParam == MSG_PROGRESSDLG_END)
952 if(this->m_CurrentCmd == GIT_COMMAND_PUSH )
954 if(!m_GitCmdStatus)
956 CTGitPathList list;
957 list.AddPath(CTGitPath(g_Git.m_CurrentDir));
958 DWORD exitcode;
959 CString error;
960 if (CHooks::Instance().PostPush(list,exitcode, error))
962 if (exitcode)
964 CString temp;
965 temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error);
966 //ReportError(temp);
967 CMessageBox::Show(NULL,temp,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
968 return false;
973 EnableControlButton(true);
974 SwitchToInput();
975 this->FetchOutList(true);
977 if(this->m_CurrentCmd == GIT_COMMAND_PULL )
979 PullComplete();
981 if(this->m_CurrentCmd == GIT_COMMAND_FETCH || this->m_CurrentCmd == GIT_COMMAND_FETCHANDREBASE)
983 FetchComplete();
985 if(this->m_CurrentCmd == GIT_COMMAND_SUBMODULE)
987 //this->m_ctrlCmdOut.SetSel(-1,-1);
988 //this->m_ctrlCmdOut.ReplaceSel(_T("Done\r\n"));
989 //this->m_ctrlCmdOut.SetSel(-1,-1);
990 EnableControlButton(true);
991 SwitchToInput();
993 if(this->m_CurrentCmd == GIT_COMMAND_REMOTE)
995 this->FetchOutList(true);
996 EnableControlButton(true);
997 SwitchToInput();
1001 if(lParam != 0)
1002 ParserCmdOutput((TCHAR)lParam);
1004 return 0;
1008 void CSyncDlg::ParserCmdOutput(char ch)
1010 CProgressDlg::ParserCmdOutput(m_ctrlCmdOut,m_ctrlProgress,m_LogText,ch);
1012 void CSyncDlg::OnBnClickedButtonCommit()
1014 CString proc=CPathUtils::GetAppDirectory();
1015 proc += _T("TortoiseProc.exe /command:commit");
1016 proc += _T(" /path:\"");
1017 proc += g_Git.m_CurrentDir;
1019 CAppUtils::LaunchApplication(proc,IDS_ERROR_CANNON_FIND_TORTOISEPROC,false);
1022 void CSyncDlg::OnOK()
1024 UpdateCombox();
1025 this->UpdateData();
1026 m_ctrlURL.SaveHistory();
1027 SaveHistory();
1028 m_regAutoLoadPutty = this->m_bAutoLoadPuttyKey;
1029 __super::OnOK();
1032 void CSyncDlg::OnBnClickedButtonSubmodule()
1034 this->UpdateData();
1035 UpdateCombox();
1037 this->m_regSubmoduleButton = this->m_ctrlSubmodule.GetCurrentEntry();
1039 this->SwitchToRun();
1041 this->m_bAbort=false;
1042 this->m_GitCmdList.clear();
1044 ShowTab(IDC_CMD_LOG);
1046 CString cmd;
1048 switch (m_ctrlSubmodule.GetCurrentEntry())
1050 case 0:
1051 cmd=_T("git.exe submodule update --init");
1052 break;
1053 case 1:
1054 cmd=_T("git.exe submodule init");
1055 break;
1056 case 2:
1057 cmd=_T("git.exe submodule sync");
1058 break;
1061 m_GitCmdList.push_back(cmd);
1063 m_CurrentCmd = GIT_COMMAND_SUBMODULE;
1065 m_pThread = AfxBeginThread(ProgressThreadEntry, this, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
1066 if (m_pThread==NULL)
1068 // ReportError(CString(MAKEINTRESOURCE(IDS_ERR_THREADSTARTFAILED)));
1070 else
1072 m_pThread->m_bAutoDelete = TRUE;
1073 m_pThread->ResumeThread();
1077 void CSyncDlg::OnTimer(UINT_PTR nIDEvent)
1079 if( nIDEvent == IDT_INPUT)
1081 KillTimer(IDT_INPUT);
1082 this->FetchOutList(true);