bool CHooks::PostPush(const CString& workingTree, DWORD& exitcode, CString& error) { auto it = FindItem(post_push_hook, workingTree); if (it == end()) return false; CString sCmd = it->second.commandline; AddPathParam(sCmd, CTGitPathList(workingTree)); AddErrorParam(sCmd, error); AddCWDParam(sCmd, workingTree); exitcode = RunScript(sCmd, workingTree, error, it->second.bWait, it->second.bShow); return true; }
bool DiffCommand::Execute() { bool bRet = false; CString path2 = CPathUtils::GetLongPathname(parser.GetVal(_T("path2"))); bool bAlternativeTool = !!parser.HasKey(_T("alternative")); // bool bBlame = !!parser.HasKey(_T("blame")); if (path2.IsEmpty()) { if (this->orgCmdLinePath.IsDirectory()) { CChangedDlg dlg; dlg.m_pathList = CTGitPathList(cmdLinePath); dlg.DoModal(); bRet = true; } else { CGitDiff diff; //diff.SetAlternativeTool(bAlternativeTool); if ( parser.HasKey(_T("startrev")) && parser.HasKey(_T("endrev")) ) { bRet = !!diff.Diff(&cmdLinePath,&cmdLinePath,git_revnum_t(parser.GetVal(_T("startrev"))),git_revnum_t(parser.GetVal(_T("endrev")))); } else { // check if it is a newly added (but uncommitted) file git_wc_status_kind status = git_wc_status_none; CString topDir; if (orgCmdLinePath.HasAdminDir(&topDir)) GitStatus::GetFileStatus(topDir, cmdLinePath.GetWinPathString(), &status, true); if (status == git_wc_status_added) cmdLinePath.m_Action = cmdLinePath.LOGACTIONS_ADDED; bRet = !!diff.Diff(&cmdLinePath,&cmdLinePath,git_revnum_t(GIT_REV_ZERO),git_revnum_t(_T("HEAD"))); } } } else bRet = CAppUtils::StartExtDiff( path2, orgCmdLinePath.GetWinPathString(), CString(), CString(), CString(), CString(), git_revnum_t(GIT_REV_ZERO), git_revnum_t(GIT_REV_ZERO), CAppUtils::DiffFlags().AlternativeTool(bAlternativeTool)); return bRet; }
bool DiffCommand::Execute() { bool bRet = false; CString path2 = CPathUtils::GetLongPathname(parser.GetVal(_T("path2"))); bool bAlternativeTool = !!parser.HasKey(_T("alternative")); // bool bBlame = !!parser.HasKey(_T("blame")); if (path2.IsEmpty()) { if (cmdLinePath.IsDirectory()) { CChangedDlg dlg; dlg.m_pathList = CTGitPathList(cmdLinePath); dlg.DoModal(); bRet = true; } else { CGitDiff diff; //diff.SetAlternativeTool(bAlternativeTool); #if 0 if ( parser.HasKey(_T("startrev")) && parser.HasKey(_T("endrev")) ) { //SVNRev StartRevision = SVNRev(parser.GetLongVal(_T("startrev"))); //SVNRev EndRevision = SVNRev(parser.GetLongVal(_T("endrev"))); //bRet = diff.ShowCompare(cmdLinePath, StartRevision, cmdLinePath, EndRevision, SVNRev(), false, bBlame); } else #endif { //git_revnum_t baseRev = 0; bRet = diff.Diff(&cmdLinePath,&cmdLinePath,git_revnum_t(GIT_REV_ZERO),git_revnum_t(_T("HEAD"))); } } } else bRet = CAppUtils::StartExtDiff( path2, orgCmdLinePath.GetWinPathString(), CString(), CString(), CAppUtils::DiffFlags().AlternativeTool(bAlternativeTool)); return bRet; }
bool DiffCommand::Execute() { bool bRet = false; CString path2 = CPathUtils::GetLongPathname(parser.GetVal(_T("path2"))); bool bAlternativeTool = !!parser.HasKey(_T("alternative")); // bool bBlame = !!parser.HasKey(_T("blame")); if (path2.IsEmpty()) { if (this->orgCmdLinePath.IsDirectory()) { CChangedDlg dlg; dlg.m_pathList = CTGitPathList(cmdLinePath); dlg.DoModal(); bRet = true; } else { if (cmdLinePath.IsEmpty()) return false; CGitDiff diff; //diff.SetAlternativeTool(bAlternativeTool); if ( parser.HasKey(_T("startrev")) && parser.HasKey(_T("endrev")) ) { if (parser.HasKey(_T("unified"))) bRet = !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, git_revnum_t(parser.GetVal(_T("endrev"))), cmdLinePath, git_revnum_t(parser.GetVal(_T("startrev"))), bAlternativeTool); else bRet = !!diff.Diff(&cmdLinePath, &cmdLinePath, git_revnum_t(parser.GetVal(_T("startrev"))), git_revnum_t(parser.GetVal(_T("endrev"))), false, parser.HasKey(_T("unified")) == TRUE, parser.GetLongVal(_T("line")), bAlternativeTool); } else { // check if it is a newly added (but uncommitted) file git_wc_status_kind status = git_wc_status_none; CString topDir; if (orgCmdLinePath.HasAdminDir(&topDir)) { CBlockCacheForPath cacheBlock(topDir); CAutoIndex index; CString adminDir; GitAdminDir::GetAdminDirPath(topDir, adminDir); if (!git_index_open(index.GetPointer(), CUnicodeUtils::GetUTF8(adminDir + _T("index")))) g_Git.Run(_T("git.exe update-index -- \"") + cmdLinePath.GetGitPathString() + _T("\""), nullptr); // make sure we get the right status GitStatus::GetFileStatus(topDir, cmdLinePath.GetWinPathString(), &status, true); if (index) git_index_write(index); } if (status == git_wc_status_added) { if (!g_Git.IsInitRepos()) { // this might be a rename, try to find original name BYTE_VECTOR cmdout; g_Git.Run(_T("git.exe diff-index --raw HEAD -M -C -z --"), &cmdout); CTGitPathList changedFiles; changedFiles.ParserFromLog(cmdout); for (int i = 0; i < changedFiles.GetCount(); ++i) { if (changedFiles[i].GetGitPathString() == cmdLinePath.GetGitPathString()) { if (!changedFiles[i].GetGitOldPathString().IsEmpty()) { CTGitPath oldPath(changedFiles[i].GetGitOldPathString()); if (parser.HasKey(_T("unified"))) return !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, git_revnum_t(_T("HEAD")), cmdLinePath, git_revnum_t(GIT_REV_ZERO), bAlternativeTool); return !!diff.Diff(&cmdLinePath, &oldPath, git_revnum_t(GIT_REV_ZERO), git_revnum_t(_T("HEAD")), false, parser.HasKey(_T("unified")) == TRUE, parser.GetLongVal(_T("line")), bAlternativeTool); } break; } } } cmdLinePath.m_Action = cmdLinePath.LOGACTIONS_ADDED; } if (parser.HasKey(_T("unified"))) bRet = !!CAppUtils::StartShowUnifiedDiff(nullptr, cmdLinePath, git_revnum_t(_T("HEAD")), cmdLinePath, git_revnum_t(GIT_REV_ZERO), bAlternativeTool); else bRet = !!diff.Diff(&cmdLinePath, &cmdLinePath, git_revnum_t(GIT_REV_ZERO), git_revnum_t(_T("HEAD")), false, parser.HasKey(_T("unified")) == TRUE, parser.GetLongVal(_T("line")), bAlternativeTool); } } } else { CGitDiff diff; if ( parser.HasKey(_T("startrev")) && parser.HasKey(_T("endrev")) && path2.Left(g_Git.m_CurrentDir.GetLength() + 1) == g_Git.m_CurrentDir + _T("\\")) { CTGitPath tgitPath2 = path2.Mid(g_Git.m_CurrentDir.GetLength() + 1); bRet = !!diff.Diff(&tgitPath2, &cmdLinePath, git_revnum_t(parser.GetVal(_T("startrev"))), git_revnum_t(parser.GetVal(_T("endrev"))), false, parser.HasKey(_T("unified")) == TRUE, parser.GetLongVal(_T("line")), bAlternativeTool); } else { bRet = CAppUtils::StartExtDiff( path2, orgCmdLinePath.GetWinPathString(), CString(), CString(), CString(), CString(), git_revnum_t(GIT_REV_ZERO), git_revnum_t(GIT_REV_ZERO), CAppUtils::DiffFlags().AlternativeTool(bAlternativeTool), parser.GetLongVal(_T("line"))); } } return bRet; }
bool PasteMoveCommand::Execute() { CString sDroppath = parser.GetVal(_T("droptarget")); CTGitPath dropPath(sDroppath); if (dropPath.IsAdminDir()) return FALSE; if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir)) return FALSE; GitStatus status; unsigned long count = 0; orgPathList.RemoveAdminPaths(); CString sNewName; CSysProgressDlg progress; progress.SetTitle(IDS_PROC_MOVING); progress.SetAnimation(IDR_MOVEANI); progress.SetTime(true); progress.ShowModeless(CWnd::FromHandle(hwndExplorer)); for (int nPath = 0; nPath < orgPathList.GetCount(); ++nPath) { CTGitPath destPath; if (sNewName.IsEmpty()) destPath = CTGitPath(sDroppath+_T("\\")+orgPathList[nPath].GetFileOrDirectoryName()); else destPath = CTGitPath(sDroppath+_T("\\")+sNewName); if (destPath.Exists()) { CString name = orgPathList[nPath].GetFileOrDirectoryName(); if (!sNewName.IsEmpty()) name = sNewName; progress.Stop(); CRenameDlg dlg; dlg.m_name = name; dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name); if (dlg.DoModal() != IDOK) { return FALSE; } destPath.SetFromWin(sDroppath+_T("\\")+dlg.m_name); } CString top; top.Empty(); orgPathList[nPath].HasAdminDir(&top); git_wc_status_kind s = status.GetAllStatus(orgPathList[nPath]); if ((s == git_wc_status_none)||(s == git_wc_status_unversioned)||(s == git_wc_status_ignored)||top != g_Git.m_CurrentDir) { // source file is unversioned: move the file to the target, then add it MoveFile(orgPathList[nPath].GetWinPath(), destPath.GetWinPath()); CString cmd,output; cmd.Format(_T("git.exe add -- \"%s\""),destPath.GetWinPath()); if (g_Git.Run(cmd, &output, CP_UTF8)) //if (!Git.Add(CTGitorgPathList(destPath), &props, Git_depth_infinity, true, false, true)) { TRACE(_T("%s\n"), output); CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR); return FALSE; //get out of here } CShellUpdater::Instance().AddPathForUpdate(destPath); } else { CString cmd,output; cmd.Format(_T("git.exe mv \"%s\" \"%s\""),orgPathList[nPath].GetGitPathString(),destPath.GetGitPathString()); if (g_Git.Run(cmd, &output, CP_UTF8)) //if (!Git.Move(CTGitorgPathList(orgPathList[nPath]), destPath, FALSE)) { #if 0 if (Git.Err && (Git.Err->apr_err == Git_ERR_UNVERSIONED_RESOURCE || Git.Err->apr_err == Git_ERR_CLIENT_MODIFIED)) { // file/folder seems to have local modifications. Ask the user if // a force is requested. CString temp = Git.GetLastErrorMessage(); CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE)); temp += _T("\n") + sQuestion; if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_YESNO)==IDYES) { if (!Git.Move(CTGitPathList(pathList[nPath]), destPath, TRUE)) { CMessageBox::Show(hwndExplorer, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR); return FALSE; //get out of here } CShellUpdater::Instance().AddPathForUpdate(destPath); } } else #endif { TRACE(_T("%s\n"), (LPCTSTR)output); CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR); return FALSE; //get out of here } } else CShellUpdater::Instance().AddPathForUpdate(destPath); } ++count; if (progress.IsValid()) { progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, orgPathList[nPath].GetWinPath()); progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath()); progress.SetProgress(count, orgPathList.GetCount()); } if ((progress.IsValid())&&(progress.HasUserCancelled())) { CMessageBox::Show(hwndExplorer, IDS_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION); return FALSE; } } return true; }
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); }