1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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
;
30 * \ingroup TortoiseProc
31 * An utility class with static functions.
33 class CAppUtils
: public CCommonAppUtils
37 * Flags for StartExtDiff function.
44 bool bAlternativeTool
; // If true, invert selection of TortoiseGitMerge vs. external diff tool
46 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
47 DiffFlags
& Wait(bool b
= true) { bWait
= b
; return *this; }
48 DiffFlags
& Blame(bool b
= true) { bBlame
= b
; return *this; }
49 DiffFlags
& ReadOnly(bool b
= true) { bReadOnly
= b
; return *this; }
50 DiffFlags
& AlternativeTool(bool b
= true) { bAlternativeTool
= b
; return *this; }
59 * Launches the external merge program if there is one.
60 * \return TRUE if the program could be started
62 static BOOL
StartExtMerge(bool bAlternativeTool
,
63 const CTGitPath
& basefile
, const CTGitPath
& theirfile
, const CTGitPath
& yourfile
, const CTGitPath
& mergedfile
,
64 const CString
& basename
= CString(), const CString
& theirname
= CString(), const CString
& yourname
= CString(),
65 const CString
& mergedname
= CString(), bool bReadOnly
= false, HWND resolveMsgHwnd
= nullptr, bool bDeleteBaseTheirsMineOnClose
= false);
68 * Starts the external patch program (currently always TortoiseGitMerge)
70 static BOOL
StartExtPatch(const CTGitPath
& patchfile
, const CTGitPath
& dir
,
71 const CString
& sOriginalDescription
= CString(), const CString
& sPatchedDescription
= CString(),
72 BOOL bReversed
= FALSE
, BOOL bWait
= FALSE
);
75 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
76 * If no app is associated with those file types, the default text editor is used.
78 static BOOL
StartUnifiedDiffViewer(const CString
& patchfile
, const CString
& title
, BOOL bWait
= FALSE
, bool bAlternativeTool
= false);
81 * Sets up all the default diff and merge scripts.
82 * \param force if true, overwrite all existing entries
83 * \param either "Diff", "Merge" or an empty string
85 static bool SetupDiffScripts(bool force
, const CString
& type
);
88 * Starts the external diff application
90 static bool StartExtDiff(
91 const CString
& file1
, const CString
& file2
,
92 const CString
& sName1
, const CString
& sName2
,
93 const CString
& originalFile1
, const CString
& originalFile2
,
94 const git_revnum_t
& hash1
, const git_revnum_t
& hash2
, const DiffFlags
& flags
, int jumpToLine
= 0);
97 * Launches the standard text viewer/editor application which is associated
99 * \return TRUE if the program could be started.
101 static BOOL
StartTextViewer(CString file
);
104 * Checks if the given file has a size of less than four, which means
105 * an 'empty' file or just newlines, i.e. an empty diff.
107 static BOOL
CheckForEmptyDiff(const CTGitPath
& sDiffPath
);
110 * Create a font which can is used for log messages, etc
112 static void CreateFontForLogs(CFont
& fontToCreate
);
115 * Launch the external blame viewer
117 static bool LaunchTortoiseBlame(
118 const CString
& sBlameFile
, const CString
& Rev
, const CString
& sParams
= CString());
121 * Launch alternative editor
123 static bool LaunchAlternativeEditor(const CString
& filename
, bool uac
= false);
126 * Sets the title of a dialog
128 static void SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
);
131 * Formats text in a rich edit control (version 2).
132 * text in between * chars is formatted bold
133 * text in between ^ chars is formatted italic
134 * text in between _ chars is underlined
136 static bool FormatTextInRichEditControl(CWnd
* pWnd
);
137 static bool FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
);
139 * implements URL searching with the same logic as CSciEdit::StyleURLs
141 static std::vector
<CHARRANGE
> FindURLMatches(const CString
& msg
);
142 static BOOL
StyleURLs(const CString
& msg
, CWnd
* pWnd
);
145 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
147 static bool StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
148 const CTGitPath
& url2
, const git_revnum_t
& rev2
,
150 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
151 bool bAlternateDiff
= false,
152 bool bIgnoreAncestry
= false,
155 bool bCompact
= false,
156 bool bNoPrefix
= false);
158 static bool Export(const CString
* BashHash
= nullptr, const CTGitPath
* orgPath
= nullptr);
159 static bool UpdateBranchDescription(const CString
& branch
, CString description
);
160 static bool CreateBranchTag(bool isTag
= true, const CString
* commitHash
= nullptr, bool switchNewBranch
= false, LPCTSTR name
= nullptr);
161 static bool Switch(const CString
& initialRefName
= CString());
162 static bool PerformSwitch(const CString
& ref
, bool bForce
= false, const CString
& sNewBranch
= CString(), bool bBranchOverride
= false, BOOL bTrack
= 2, bool bMerge
= false);
164 static bool IgnoreFile(const CTGitPathList
& filelist
, bool IsMask
);
165 static bool GitReset(const CString
* CommitHash
, int type
= 1);
166 static bool ConflictEdit(const CTGitPath
& file
, bool bAlternativeTool
= false, bool revertTheirMy
= false, HWND resolveMsgHwnd
= nullptr);
168 static CString
GetMergeTempFile(const CString
& str
, const CTGitPath
& merge
);
169 static bool StashSave(const CString
& msg
= CString(), bool showPull
= false, bool pullShowPush
= false, bool showMerge
= false, const CString
& mergeRev
= CString());
170 static bool StashApply(CString ref
, bool showChanges
= true);
171 /** Execute "stash pop"
173 * 0: only show info on error (and allow to diff on error)
174 * 1: allow to open diff dialog on error or success
175 * 2: only show error or success message
177 static bool StashPop(int showChanges
= 1);
179 static bool IsSSHPutty();
181 static bool LaunchRemoteSetting();
183 static bool LaunchPAgent(const CString
* keyfile
= nullptr, const CString
* pRemote
= nullptr);
185 static bool ShellOpen(const CString
& file
, HWND hwnd
= nullptr);
186 static bool ShowOpenWithDialog(const CString
& file
, HWND hwnd
= nullptr);
188 static CString
GetClipboardLink(const CString
&skipGitPrefix
= _T(""), int paramsCount
= 0);
189 static CString
ChooseRepository(const CString
* path
);
191 static bool SendPatchMail(CTGitPathList
& pathlist
, bool bIsMainWnd
= false);
192 static bool SendPatchMail(const CString
& cmd
, const CString
& formatpatchoutput
, bool bIsMainWnd
= false);
194 static int SaveCommitUnicodeFile(const CString
& filename
, CString
& mesage
);
196 static int GetLogOutputEncode(CGit
*pGit
=&g_Git
);
198 static bool Pull(bool showPush
= false, bool showStashPop
= false);
199 // rebase = 1: ask user what to do, rebase = 2: run autorebase
200 static bool RebaseAfterFetch(const CString
& upstream
= _T(""), int rebase
= 0, bool preserveMerges
= false);
201 static bool Fetch(const CString
& remoteName
= _T(""), bool allRemotes
= false);
202 static bool DoPush(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
);
203 static bool Push(const CString
& selectLocalBranch
= CString());
204 static bool RequestPull(const CString
& endrevision
= _T(""), const CString
& repositoryUrl
= _T(""), bool bIsMainWnd
= false);
206 static void RemoveTrailSlash(CString
&path
);
208 static bool CheckUserData();
210 static BOOL
Commit(const CString
& bugid
, BOOL bWholeProject
, CString
&sLogMsg
,
211 CTGitPathList
&pathList
,
212 CTGitPathList
&selectedList
,
213 bool bSelectFilesForCommit
);
215 static BOOL
SVNDCommit();
216 static BOOL
Merge(const CString
* commit
= nullptr, bool showStashPop
= false);
217 static BOOL
MergeAbort();
218 static void RemoveTempMergeFile(const CTGitPath
& path
);
219 static void EditNote(GitRevLoglist
* hash
);
220 static int GetMsysgitVersion();
221 static void MarkWindowAsUnpinnable(HWND hWnd
);
223 static bool BisectStart(const CString
& lastGood
, const CString
& firstBad
, bool bIsMainWnd
= false);
224 static bool BisectOperation(const CString
& op
, const CString
& ref
= _T(""), bool bIsMainWnd
= false);
226 static int Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int allowed_types
, void *payload
);
228 static int Git2CertificateCheck(git_cert
*cert
, int valid
, const char* host
, void *payload
);
230 static int ExploreTo(HWND hwnd
, CString path
);
233 RESOLVE_WITH_CURRENT
,
238 static int ResolveConflict(CTGitPath
& path
, resolve_with resolveWith
);
240 static bool IsTGitRebaseActive();
243 static CString
PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
);
245 static bool OpenIgnoreFile(CIgnoreFile
&file
, const CString
& filename
);
247 static void DescribeConflictFile(bool mode
, bool base
,CString
&descript
);