bool RevertCommand::Execute() { CRevertDlg dlg; dlg.m_pathList = pathList; if (dlg.DoModal() == IDOK) { // g_Git.Revert(dlg.m_selectedPathList,true); CGitProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; progDlg.SetCommand(CGitProgressList::GitProgress_Revert); progDlg.SetOptions(dlg.m_bRecursive ? ProgOptRecursive : ProgOptNonRecursive); progDlg.SetPathList(dlg.m_pathList); progDlg.SetItemCount(dlg.m_selectedPathList.GetCount()); progDlg.SetSelectedList(dlg.m_selectedPathList); progDlg.DoModal(); return true; } return false; }
bool CloneCommand::Execute() { CTGitPath cloneDirectory; if (!parser.HasKey(_T("hasurlhandler"))) { if (orgCmdLinePath.IsEmpty()) { cloneDirectory.SetFromWin(sOrigCWD, true); DWORD len = ::GetTempPath(0, NULL); std::unique_ptr<TCHAR[]> tszPath(new TCHAR[len]); ::GetTempPath(len, tszPath.get()); if (_tcsncicmp(cloneDirectory.GetWinPath(), tszPath.get(), len-2 /* \\ and \0 */) == 0) { // if the current directory is set to a temp directory, // we don't use that but leave it empty instead. cloneDirectory.Reset(); } } else cloneDirectory = orgCmdLinePath; } CCloneDlg dlg; dlg.m_Directory = cloneDirectory.GetWinPathString(); if (parser.HasKey(_T("url"))) dlg.m_URL = parser.GetVal(_T("url")); if (parser.HasKey(_T("exactpath"))) dlg.m_bExactPath = TRUE; if(dlg.DoModal()==IDOK) { CString recursiveStr; if(dlg.m_bRecursive) recursiveStr = _T("--recursive"); else recursiveStr = _T(""); CString bareStr; if(dlg.m_bBare) bareStr = _T("--bare"); else bareStr = _T(""); CString nocheckoutStr; if (dlg.m_bNoCheckout) nocheckoutStr = _T("--no-checkout"); CString branchStr; if (dlg.m_bBranch) branchStr = _T("--branch ") + dlg.m_strBranch; CString originStr; if (dlg.m_bOrigin) originStr = _T("--origin ") + dlg.m_strOrigin; if(dlg.m_bAutoloadPuttyKeyFile) { CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile); } CAppUtils::RemoveTrailSlash(dlg.m_Directory); if (!dlg.m_bSVN) CAppUtils::RemoveTrailSlash(dlg.m_URL); CString dir=dlg.m_Directory; CString url=dlg.m_URL; // is this a windows format UNC path, ie starts with \\? if (url.Find(_T("\\\\")) == 0) { // yes, change all \ to / // this should not be necessary but msysgit does not support the use \ here yet int atSign = url.Find(_T('@')); if (atSign > 0) { CString path = url.Mid(atSign); path.Replace(_T('\\'), _T('/')); url = url.Mid(0, atSign) + path; } else url.Replace( _T('\\'), _T('/')); } CString depth; if (dlg.m_bDepth) { depth.Format(_T(" --depth %d"),dlg.m_nDepth); } g_Git.m_CurrentDir = GetExistingDirectoryForClone(dlg.m_Directory); CString cmd; CString progressarg; int ver = CAppUtils::GetMsysgitVersion(); if(ver >= 0x01070002) //above 1.7.0.2 progressarg = _T("--progress"); cmd.Format(_T("git.exe clone %s %s %s %s %s %s -v %s \"%s\" \"%s\""), nocheckoutStr, recursiveStr, bareStr, branchStr, originStr, progressarg, depth, url, dir); // Handle Git SVN-clone if(dlg.m_bSVN) { //g_Git.m_CurrentDir=dlg.m_Directory; cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""), url,dlg.m_Directory); if(dlg.m_bSVNTrunk) cmd+=_T(" -T ")+dlg.m_strSVNTrunk; if(dlg.m_bSVNBranch) cmd+=_T(" -b ")+dlg.m_strSVNBranchs; if(dlg.m_bSVNTags) cmd+=_T(" -t ")+dlg.m_strSVNTags; if(dlg.m_bSVNFrom) { CString str; str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom); cmd+=_T(" -r ")+str; } if(dlg.m_bSVNUserName) { cmd+= _T(" --username "); cmd+=dlg.m_strUserName; } } else { if (g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE)) { CGitProgressDlg GitDlg; CTGitPathList list; g_Git.m_CurrentDir = dir; list.AddPath(CTGitPath(dir)); GitDlg.SetCommand(CGitProgressList::GitProgress_Clone); GitDlg.SetUrl(url); GitDlg.SetPathList(list); GitDlg.SetIsBare(!!dlg.m_bBare); GitDlg.SetRefSpec(dlg.m_bBranch ? dlg.m_strBranch : CString()); GitDlg.SetRemote(dlg.m_bOrigin ? dlg.m_strOrigin : CString()); GitDlg.SetNoCheckout(!!dlg.m_bNoCheckout); GitDlg.DoModal(); return !GitDlg.DidErrorsOccur(); } } CProgressDlg progress; progress.m_GitCmd=cmd; progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENULOG))); progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_EXPLORE))); INT_PTR ret = progress.DoModal(); if (dlg.m_bSVN) ::DeleteFile(g_Git.m_CurrentDir + _T("\\sys$command")); if( progress.m_GitStatus == 0) { if(dlg.m_bAutoloadPuttyKeyFile) { g_Git.m_CurrentDir = dlg.m_Directory; SetCurrentDirectory(g_Git.m_CurrentDir); if(g_Git.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg.m_strPuttyKeyFile, CONFIG_LOCAL, CP_UTF8)) { CMessageBox::Show(NULL,_T("Fail set config remote.origin.puttykeyfile"),_T("TortoiseGit"),MB_OK|MB_ICONERROR); return FALSE; } } if (ret == IDC_PROGRESS_BUTTON1) { CString cmd = _T("/command:log"); cmd += _T(" /path:\"") + dlg.m_Directory + _T("\""); CAppUtils::RunTortoiseGitProc(cmd); return TRUE; } if (ret == IDC_PROGRESS_BUTTON1 + 1) { ShellExecute(nullptr, _T("explore"), dlg.m_Directory, nullptr, nullptr, SW_SHOW); return TRUE; } } if(ret == IDOK) return TRUE; } return FALSE; }
bool AddCommand::Execute() { bool bRet = false; if (parser.HasKey(_T("noui"))) { #if 0 SVN svn; ProjectProperties props; props.ReadPropsPathList(pathList); bRet = !!svn.Add(pathList, &props, svn_depth_empty, FALSE, FALSE, TRUE); CShellUpdater::Instance().AddPathsForUpdate(pathList); #endif } else { #if 0 if (pathList.AreAllPathsFiles()) { SVN svn; ProjectProperties props; props.ReadPropsPathList(pathList); bRet = !!svn.Add(pathList, &props, svn_depth_empty, FALSE, FALSE, TRUE); CShellUpdater::Instance().AddPathsForUpdate(pathList); } else { #endif CAddDlg dlg; dlg.m_pathList = pathList; if (dlg.DoModal() == IDOK) { #if 0 CString cmd,out; int success=0; for(int i=0;i<dlg.m_pathList.GetCount();i++) { cmd.Format(_T("git.exe add -- \"%s\""),dlg.m_pathList[i].GetGitPathString()); if(g_Git.Run(cmd,&out,CP_ACP)) { CMessageBox::Show(NULL,out,_T("TortoiseGit"),MB_OK|MB_ICONERROR); } success++; } CString message; message.Format(_T("%d file added"),success); CMessageBox::Show(NULL,message,_T("TortoiseGit"),MB_OK); return TRUE; #endif if (dlg.m_pathList.GetCount() == 0) return FALSE; CGitProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; progDlg.SetCommand(CGitProgressDlg::GitProgress_Add); if (parser.HasVal(_T("closeonend"))) progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend"))); progDlg.SetPathList(dlg.m_pathList); //ProjectProperties props; //props.ReadPropsPathList(dlg.m_pathList); //progDlg.SetProjectProperties(props); progDlg.SetItemCount(dlg.m_pathList.GetCount()); progDlg.DoModal(); CShellUpdater::Instance().AddPathsForUpdate(dlg.m_pathList); bRet = !progDlg.DidErrorsOccur(); } // } } CShellUpdater::Instance().Flush(); return bRet; }
bool DropCopyAddCommand::Execute() { bool bRet = false; CString droppath = parser.GetVal(_T("droptarget")); if (CTGitPath(droppath).IsAdminDir()) return FALSE; if(!CTGitPath(droppath).HasAdminDir(&g_Git.m_CurrentDir)) return FALSE; orgPathList.RemoveAdminPaths(); CTGitPathList copiedFiles; for(int nPath = 0; nPath < orgPathList.GetCount(); nPath++) { if (!orgPathList[nPath].IsEquivalentTo(CTGitPath(droppath))) { //copy the file to the new location CString name = orgPathList[nPath].GetFileOrDirectoryName(); if (::PathFileExists(droppath+_T("\\")+name)) { CString strMessage; strMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, (LPCTSTR)(droppath+_T("\\")+name)); int ret = CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_YESNOCANCEL | MB_ICONQUESTION); if (ret == IDYES) { if (!::CopyFile(orgPathList[nPath].GetWinPath(), droppath+_T("\\")+name, FALSE)) { //the copy operation failed! Get out of here! ShowErrorMessage(); return FALSE; } } if (ret == IDCANCEL) { return FALSE; //cancel the whole operation } } else if (!CopyFile(orgPathList[nPath].GetWinPath(), droppath+_T("\\")+name, FALSE)) { //the copy operation failed! Get out of here! ShowErrorMessage(); return FALSE; } copiedFiles.AddPath(CTGitPath(droppath+_T("\\")+name)); //add the new filepath } } //now add all the newly copied files to the working copy CGitProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; progDlg.SetCommand(CGitProgressDlg::GitProgress_Add); if (parser.HasVal(_T("closeonend"))) progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend"))); progDlg.SetPathList(copiedFiles); ProjectProperties props; props.ReadPropsPathList(copiedFiles); progDlg.SetProjectProperties(props); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); return bRet; }
void CGitBlameLogList::ContextMenuAction(int cmd,int FirstSelect, int LastSelect,CMenu * menu) { POSITION pos = GetFirstSelectedItemPosition(); int indexNext = GetNextSelectedItem(pos); if (indexNext < 0) return; CString procCmd; GitRev* pSelLogEntry = reinterpret_cast<GitRev*>(m_arShownList.GetAt(indexNext)); bool bOpenWith = false; procCmd += _T("/path:\""); procCmd += ((CMainFrame*)::AfxGetApp()->GetMainWnd())->GetActiveView()->GetDocument()->GetPathName(); procCmd += _T("\" "); procCmd += _T(" /rev:")+this->m_logEntries.GetGitRevAt(indexNext).m_CommitHash.ToString(); procCmd += _T(" /command:"); switch (cmd) { case ID_GNUDIFF1: procCmd += _T("diff /udiff"); break; #if 0 case ID_GNUDIFF2: { CString tempfile=GetTempFile(); CString cmd; GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect)); GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect)); cmd.Format(_T("git.exe diff-tree -r -p --stat %s %s"),r1->m_CommitHash,r2->m_CommitHash); g_Git.RunLogFile(cmd,tempfile); CAppUtils::StartUnifiedDiffViewer(tempfile, r1->m_CommitHash.Left(g_Git.GetShortHASHLength()) + _T(":") + r2->m_CommitHash.Left(g_Git.GetShortHASHLength())); } break; #endif #if 0 case ID_COMPARETWO: { GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect)); GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect)); CFileDiffDlg dlg; dlg.SetDiff(NULL,*r1,*r2); dlg.DoModal(); } break; #endif #if 0 case ID_COMPARE: { GitRev * r1 = &m_wcRev; GitRev * r2 = pSelLogEntry; CFileDiffDlg dlg; dlg.SetDiff(NULL,*r1,*r2); dlg.DoModal(); //user clicked on the menu item "compare with working copy" //if (PromptShown()) //{ // GitDiff diff(this, m_hWnd, true); // diff.SetAlternativeTool(!!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); // diff.SetHEADPeg(m_LogRevision); // diff.ShowCompare(m_path, GitRev::REV_WC, m_path, revSelected); //} //else // CAppUtils::StartShowCompare(m_hWnd, m_path, GitRev::REV_WC, m_path, revSelected, GitRev(), m_LogRevision, !!(GetAsyncKeyState(VK_SHIFT) & 0x8000)); } break; case ID_COMPARE: procCmd+=CString(_T("diff \rev1:"))+CString(GIT_REV_ZERO)+CString(_T(" \rev2:"))+this->m_logEntries.GetGitRevAt(indexNext).m_CommitHash.ToString(); break; #endif case ID_COMPAREWITHPREVIOUS: if (indexNext + 1 < m_logEntries.size()) // cannot diff previous revision in first revision { procCmd+=CString(_T("diff /startrev:"))+this->m_logEntries.GetGitRevAt(indexNext).m_CommitHash.ToString()+CString(_T(" /endrev:"))+this->m_logEntries.GetGitRevAt(indexNext+1).m_CommitHash.ToString(); } else { return; } break; case ID_COPYCLIPBOARD: { CopySelectionToClipBoard(); } return; case ID_COPYHASH: { CopySelectionToClipBoard(TRUE); } return; case ID_EXPORT: procCmd += _T("export"); break; case ID_CREATE_BRANCH: procCmd += _T("branch"); break; case ID_CREATE_TAG: procCmd += _T("tag"); break; case ID_SWITCHTOREV: procCmd += _T("switch"); break; case ID_BLAME: procCmd += _T("blame"); procCmd += _T(" /endrev:") + this->m_logEntries.GetGitRevAt(indexNext).m_CommitHash.ToString(); break; case ID_LOG: procCmd += _T("log"); break; case ID_REPOBROWSE: procCmd.Format(_T("/command:repobrowser /path:\"%s\" /rev:%s"), g_Git.m_CurrentDir, this->m_logEntries.GetGitRevAt(indexNext).m_CommitHash.ToString()); break; default: //CMessageBox::Show(NULL,_T("Have not implemented"),_T("TortoiseGit"),MB_OK); return; #if 0 case ID_REVERTREV: { // we need an URL to complete this command, so error out if we can't get an URL if (pathURL.IsEmpty()) { CString strMessage; strMessage.Format(IDS_ERR_NOURLOFFILE, (LPCTSTR)(m_path.GetUIPathString())); CMessageBox::Show(this->m_hWnd, strMessage, _T("TortoiseGit"), MB_ICONERROR); TRACE(_T("could not retrieve the URL of the folder!\n")); break; //exit } CString msg; msg.Format(IDS_LOG_REVERT_CONFIRM, m_path.GetWinPath()); if (CMessageBox::Show(this->m_hWnd, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES) { CGitProgressDlg dlg; dlg.SetCommand(CGitProgressDlg::GitProgress_Merge); dlg.SetPathList(CTGitPathList(m_path)); dlg.SetUrl(pathURL); dlg.SetSecondUrl(pathURL); revisionRanges.AdjustForMerge(true); dlg.SetRevisionRanges(revisionRanges); dlg.SetPegRevision(m_LogRevision); dlg.DoModal(); } } break; case ID_FINDENTRY: { m_nSearchIndex = GetSelectionMark(); if (m_nSearchIndex < 0) m_nSearchIndex = 0; if (m_pFindDialog) { break; } else { m_pFindDialog = new CFindReplaceDialog(); m_pFindDialog->Create(TRUE, NULL, NULL, FR_HIDEUPDOWN | FR_HIDEWHOLEWORD, this); } } break; #endif } // switch (cmd) CCommonAppUtils::RunTortoiseProc(procCmd); }