From c6c8d224a7d3040e8e7aebd72e12216a040ab818 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Wed, 3 Jul 2013 13:17:45 +0200 Subject: [PATCH] RepoBrowser: Allow to open submodule This shows the revision of the submodule. Signed-off-by: Sven Strickroth --- src/TortoiseProc/RepositoryBrowser.cpp | 25 ++++++++++++++++--------- src/TortoiseProc/RepositoryBrowser.h | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/TortoiseProc/RepositoryBrowser.cpp b/src/TortoiseProc/RepositoryBrowser.cpp index 9a0891599..7165d04ff 100644 --- a/src/TortoiseProc/RepositoryBrowser.cpp +++ b/src/TortoiseProc/RepositoryBrowser.cpp @@ -261,7 +261,7 @@ void CRepositoryBrowser::OnOK() m_RepoTree.SelectItem(item->m_hTree); } else - OpenFile(item->GetFullName(), OPEN); + OpenFile(item->GetFullName(), OPEN, item->m_bSubmodule); } return; } @@ -290,7 +290,7 @@ void CRepositoryBrowser::OnNMDblclk_RepoList(NMHDR *pNMHDR, LRESULT *pResult) if (!pItem->m_bFolder) { - OpenFile(pItem->GetFullName(), OPEN); + OpenFile(pItem->GetFullName(), OPEN, pItem->m_bSubmodule); return; } else @@ -581,7 +581,7 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel { popupMenu.AppendMenuIcon(eCmd_Open, IDS_REPOBROWSE_OPEN, IDI_OPEN); popupMenu.SetDefaultItem(eCmd_Open, FALSE); - if (selType == ONLY_FILES) + if (selType == ONLY_FILESSUBMODULES) { popupMenu.AppendMenuIcon(eCmd_OpenWith, IDS_LOG_POPUP_OPENWITH, IDI_OPEN); popupMenu.AppendMenuIcon(eCmd_OpenWithAlternativeEditor, IDS_LOG_POPUP_VIEWREV); @@ -654,13 +654,13 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel m_RepoTree.SelectItem(selectedLeafs.at(0)->m_hTree); return; } - OpenFile(selectedLeafs.at(0)->GetFullName(), OPEN); + OpenFile(selectedLeafs.at(0)->GetFullName(), OPEN, selectedLeafs.at(0)->m_bSubmodule); break; case eCmd_OpenWith: - OpenFile(selectedLeafs.at(0)->GetFullName(), OPEN_WITH); + OpenFile(selectedLeafs.at(0)->GetFullName(), OPEN_WITH, selectedLeafs.at(0)->m_bSubmodule); break; case eCmd_OpenWithAlternativeEditor: - OpenFile(selectedLeafs.at(0)->GetFullName(), ALTERNATIVEEDITOR); + OpenFile(selectedLeafs.at(0)->GetFullName(), ALTERNATIVEEDITOR, selectedLeafs.at(0)->m_bSubmodule); break; case eCmd_CompareWC: { @@ -1021,7 +1021,7 @@ void CRepositoryBrowser::FileSaveAs(const CString path) } } -void CRepositoryBrowser::OpenFile(const CString path, eOpenType mode) +void CRepositoryBrowser::OpenFile(const CString path, eOpenType mode, bool isSubmodule) { CTGitPath gitPath(path); @@ -1037,9 +1037,16 @@ void CRepositoryBrowser::OpenFile(const CString path, eOpenType mode) file.Format(_T("%s%s_%s%s"), temppath, gitPath.GetBaseFilename(), hash.ToString().Left(g_Git.GetShortHASHLength()), gitPath.GetFileExtension()); - CString out; - if(g_Git.GetOneFile(m_sRevision, gitPath, file)) + if (isSubmodule) + { + file += _T(".txt"); + CFile submoduleCommit(file, CFile::modeCreate | CFile::modeWrite); + CStringA commitInfo = "Subproject commit " + CStringA(hash.ToString()); + submoduleCommit.Write(commitInfo, commitInfo.GetLength()); + } + else if (g_Git.GetOneFile(m_sRevision, gitPath, file)) { + CString out; out.Format(IDS_STATUSLIST_CHECKOUTFILEFAILED, gitPath.GetGitPathString(), m_sRevision, file); MessageBox(out, _T("TortoiseGit"), MB_OK); return; diff --git a/src/TortoiseProc/RepositoryBrowser.h b/src/TortoiseProc/RepositoryBrowser.h index 74adcde87..38f9ff608 100644 --- a/src/TortoiseProc/RepositoryBrowser.h +++ b/src/TortoiseProc/RepositoryBrowser.h @@ -151,7 +151,7 @@ private: void ShowContextMenu(CPoint point, TShadowFilesTreeList &selectedLeafs, eSelectionType selType); void FileSaveAs(const CString path); - void OpenFile(const CString path, eOpenType mode); + void OpenFile(const CString path, eOpenType mode, bool isSubmodule); bool RevertItemToVersion(const CString &path); afx_msg void OnBnClickedButtonRevision(); -- 2.11.4.GIT