libgit2: Enable fetch function
[TortoiseGit.git] / src / TortoiseProc / Commands / DiffCommand.cpp
blobf73e690b2e19c0c54d1e081c67ff0e03e2b5f95f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
4 // Copyright (C) 2007-2011 - TortoiseGit
5 // Copyright (C) 2011 Sven Strickroth <email@cs-ware.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "stdafx.h"
22 #include "DiffCommand.h"
23 #include "PathUtils.h"
24 #include "AppUtils.h"
25 #include "ChangedDlg.h"
26 #include "GitDiff.h"
27 #include "GitStatus.h"
29 bool DiffCommand::Execute()
31 bool bRet = false;
32 CString path2 = CPathUtils::GetLongPathname(parser.GetVal(_T("path2")));
33 bool bAlternativeTool = !!parser.HasKey(_T("alternative"));
34 // bool bBlame = !!parser.HasKey(_T("blame"));
35 if (path2.IsEmpty())
37 if (this->orgCmdLinePath.IsDirectory())
39 CChangedDlg dlg;
40 dlg.m_pathList = CTGitPathList(cmdLinePath);
41 dlg.DoModal();
42 bRet = true;
44 else
46 CGitDiff diff;
47 //diff.SetAlternativeTool(bAlternativeTool);
48 if ( parser.HasKey(_T("startrev")) && parser.HasKey(_T("endrev")) )
50 bRet = !!diff.Diff(&cmdLinePath,&cmdLinePath,git_revnum_t(parser.GetVal(_T("startrev"))),git_revnum_t(parser.GetVal(_T("endrev"))));
52 else
54 // check if it is a newly added (but uncommitted) file
55 git_wc_status_kind status = git_wc_status_none;
56 CString topDir;
57 if (orgCmdLinePath.HasAdminDir(&topDir))
58 GitStatus::GetFileStatus(topDir, cmdLinePath.GetWinPathString(), &status, true);
59 if (status == git_wc_status_added)
60 cmdLinePath.m_Action = cmdLinePath.LOGACTIONS_ADDED;
62 bRet = !!diff.Diff(&cmdLinePath,&cmdLinePath,git_revnum_t(GIT_REV_ZERO),git_revnum_t(_T("HEAD")));
66 else
67 bRet = CAppUtils::StartExtDiff(
68 path2, orgCmdLinePath.GetWinPathString(), CString(), CString(),
69 CString(), CString(), git_revnum_t(GIT_REV_ZERO), git_revnum_t(GIT_REV_ZERO),
70 CAppUtils::DiffFlags().AlternativeTool(bAlternativeTool));
72 return bRet;