1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2018 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "GitRevLoglist.h"
22 #include "CommonAppUtils.h"
26 struct git_transfer_progress
;
28 class ProjectProperties
;
31 * \ingroup TortoiseProc
32 * An utility class with static functions.
34 class CAppUtils
: public CCommonAppUtils
38 * Flags for StartExtDiff function.
45 bool bAlternativeTool
; // If true, invert selection of TortoiseGitMerge vs. external diff tool
47 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
48 DiffFlags
& Wait(bool b
= true) { bWait
= b
; return *this; }
49 DiffFlags
& Blame(bool b
= true) { bBlame
= b
; return *this; }
50 DiffFlags
& ReadOnly(bool b
= true) { bReadOnly
= b
; return *this; }
51 DiffFlags
& AlternativeTool(bool b
= true) { bAlternativeTool
= b
; return *this; }
58 * Launches the external merge program if there is one.
59 * \return TRUE if the program could be started
61 static BOOL
StartExtMerge(bool bAlternativeTool
,
62 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
63 const CString
& basename
= CString(), const CString
& theirname
= CString(), const CString
& yourname
= CString(),
64 const CString
& mergedname
= CString(), bool bReadOnly
= false, HWND resolveMsgHwnd
= nullptr, bool bDeleteBaseTheirsMineOnClose
= false);
67 * Starts the external patch program (currently always TortoiseGitMerge)
69 static BOOL
StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
,
70 const CString
& sOriginalDescription
= CString(), const CString
& sPatchedDescription
= CString(),
71 BOOL bReversed
= FALSE
, BOOL bWait
= FALSE
);
74 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
75 * If no app is associated with those file types, the default text editor is used.
77 static BOOL
StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
= FALSE
, bool bAlternativeTool
= false);
80 * Sets up all the default diff and merge scripts.
81 * \param force if true, overwrite all existing entries
82 * \param either "Diff", "Merge" or an empty string
84 static bool SetupDiffScripts(bool force
, const CString
& type
);
87 * Starts the external diff application
89 static bool StartExtDiff(
90 const CString
& file1
, const CString
& file2
,
91 const CString
& sName1
, const CString
& sName2
,
92 const CString
& originalFile1
, const CString
& originalFile2
,
93 const CString
& hash1
, const CString
& hash2
, const DiffFlags
& flags
, int jumpToLine
= 0);
96 * Launches the standard text viewer/editor application which is associated
98 * \return TRUE if the program could be started.
100 static BOOL
StartTextViewer(CString file
);
103 * Checks if the given file has a size of less than four, which means
104 * an 'empty' file or just newlines, i.e. an empty diff.
106 static BOOL
CheckForEmptyDiff(const CTGitPath
& sDiffPath
);
109 * Returns font name which is used for log messages, etc.
111 static CString
GetLogFontName();
114 * Returns font size which is used for log messages, etc.
116 static DWORD
GetLogFontSize();
119 * Create a font which can is used for log messages, etc
121 static void CreateFontForLogs(CFont
& fontToCreate
);
124 * Launch the external blame viewer
126 static bool LaunchTortoiseBlame(
127 const CString
& sBlameFile
, const CString
& Rev
, const CString
& sParams
= CString());
130 * Launch alternative editor
132 static bool LaunchAlternativeEditor(const CString
& filename
, bool uac
= false);
135 * Sets the title of a dialog
137 static void SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
);
140 * Formats text in a rich edit control (version 2).
141 * text in between * chars is formatted bold
142 * text in between ^ chars is formatted italic
143 * text in between _ chars is underlined
145 static bool FormatTextInRichEditControl(CWnd
* pWnd
);
146 static bool FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
);
148 * implements URL searching with the same logic as CSciEdit::StyleURLs
150 static std::vector
<CHARRANGE
> FindURLMatches(const CString
& msg
);
151 static BOOL
StyleURLs(const CString
& msg
, CWnd
* pWnd
);
154 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
156 static bool StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const CString
& rev1
,
157 const CTGitPath
& url2
, const CString
& rev2
,
159 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
160 bool bAlternateDiff
= false,
161 bool bIgnoreAncestry
= false,
164 bool bCompact
= false,
165 bool bNoPrefix
= false);
167 static bool Export(HWND hWnd
, const CString
* BashHash
= nullptr, const CTGitPath
* orgPath
= nullptr);
168 static bool UpdateBranchDescription(const CString
& branch
, CString description
);
169 static bool CreateBranchTag(HWND hWnd
, bool isTag
= true, const CString
* commitHash
= nullptr, bool switchNewBranch
= false, LPCTSTR name
= nullptr);
170 static bool Switch(HWND hWnd
, const CString
& initialRefName
= CString());
171 static bool PerformSwitch(HWND hWnd
, const CString
& ref
, bool bForce
= false, const CString
& sNewBranch
= CString(), bool bBranchOverride
= false, BOOL bTrack
= 2, bool bMerge
= false);
173 static bool IgnoreFile(HWND hWnd
, const CTGitPathList
& filelist
, bool IsMask
);
174 static bool GitReset(HWND hWnd
, const CString
* CommitHash
, int type
= 1);
175 static bool ConflictEdit(HWND hWnd
, CTGitPath
& file
, bool bAlternativeTool
= false, bool revertTheirMy
= false, HWND resolveMsgHwnd
= nullptr);
176 static void GetConflictTitles(CString
* baseText
, CString
& mineText
, CString
& theirsText
, bool rebaseActive
);
178 static CString
GetMergeTempFile(const CString
& str
, const CTGitPath
& merge
);
179 static bool StashSave(HWND hWnd
, const CString
& msg
= CString(), bool showPull
= false, bool pullShowPush
= false, bool showMerge
= false, const CString
& mergeRev
= CString());
180 static bool StashApply(HWND hWnd
, CString ref
, bool showChanges
= true);
181 /** Execute "stash pop"
183 * 0: only show info on error (and allow to diff on error)
184 * 1: allow to open diff dialog on error or success
185 * 2: only show error or success message
187 static bool StashPop(HWND hWnd
, int showChanges
= 1);
189 static bool IsSSHPutty();
191 static bool LaunchRemoteSetting();
193 static bool LaunchPAgent(HWND hWnd
, const CString
* keyfile
= nullptr, const CString
* pRemote
= nullptr);
195 static bool ShellOpen(const CString
& file
, HWND hwnd
= nullptr);
196 static bool ShowOpenWithDialog(const CString
& file
, HWND hwnd
= nullptr);
198 static CString
GetClipboardLink(const CString
& skipGitPrefix
= L
"", int paramsCount
= 0);
199 static CString
ChooseRepository(HWND hWnd
, const CString
* path
);
201 static bool SendPatchMail(HWND hWnd
, CTGitPathList
& pathlist
);
202 static bool SendPatchMail(HWND hWnd
, const CString
& cmd
, const CString
& formatpatchoutput
);
204 static int SaveCommitUnicodeFile(const CString
& filename
, CString
& mesage
);
205 static bool MessageContainsConflictHints(HWND hWnd
, const CString
& message
);
207 static int GetLogOutputEncode(CGit
*pGit
=&g_Git
);
209 static bool Pull(HWND hWnd
, bool showPush
= false, bool showStashPop
= false);
210 // rebase = 1: ask user what to do, rebase = 2: run autorebase
211 static bool RebaseAfterFetch(HWND hWnd
, const CString
& upstream
= L
"", int rebase
= 0, bool preserveMerges
= false);
212 static bool Fetch(HWND hWnd
, const CString
& remoteName
= L
"", bool allRemotes
= false);
213 static bool DoPush(HWND hWnd
, bool autoloadKey
, bool pack
, bool tags
, bool allRemotes
, bool allBranches
, bool force
, bool forceWithLease
, const CString
& localBranch
, const CString
& remote
, const CString
& remoteBranch
, bool setUpstream
, int recurseSubmodules
);
214 static bool Push(HWND hWnd
, const CString
& selectLocalBranch
= CString());
215 static bool RequestPull(HWND hWnd
, const CString
& endrevision
= L
"", const CString
& repositoryUrl
= L
"");
217 static void RemoveTrailSlash(CString
&path
);
219 static bool CheckUserData(HWND hWnd
);
221 static BOOL
Commit(HWND hWnd
, const CString
& bugid
, BOOL bWholeProject
, CString
& sLogMsg
,
222 CTGitPathList
&pathList
,
223 bool bSelectFilesForCommit
);
225 static BOOL
SVNDCommit(HWND hWnd
);
226 static BOOL
Merge(HWND hWnd
, const CString
* commit
= nullptr, bool showStashPop
= false);
227 static BOOL
MergeAbort(HWND hWnd
);
228 static void RemoveTempMergeFile(const CTGitPath
& path
);
229 static void EditNote(HWND hWnd
, GitRevLoglist
* rev
, ProjectProperties
* projectProperties
);
230 static int GetMsysgitVersion(HWND hWnd
);
231 static bool IsGitVersionNewerOrEqual(HWND hWnd
, unsigned __int8 major
, unsigned __int8 minor
, unsigned __int8 patchlevel
= 0, unsigned __int8 build
= 0);
232 static void MarkWindowAsUnpinnable(HWND hWnd
);
234 static bool BisectStart(HWND hWnd
, const CString
& lastGood
, const CString
& firstBad
);
235 static bool BisectOperation(HWND hWnd
, const CString
& op
, const CString
& ref
= L
"");
237 static int Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int allowed_types
, void *payload
);
239 static int Git2CertificateCheck(git_cert
*cert
, int valid
, const char* host
, void *payload
);
241 static int ExploreTo(HWND hwnd
, CString path
);
243 static bool DeleteRef(CWnd
* parent
, const CString
& ref
);
246 RESOLVE_WITH_CURRENT
,
251 static int ResolveConflict(HWND hWnd
, CTGitPath
& path
, resolve_with resolveWith
);
253 static bool IsTGitRebaseActive(HWND hWnd
);
256 static CString
PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
);
258 static bool OpenIgnoreFile(HWND hWnd
, CIgnoreFile
& file
, const CString
& filename
);
260 static void DescribeConflictFile(bool mode
, bool base
,CString
&descript
);