1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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 "HistoryCombo.h"
23 #include "CommonAppUtils.h"
27 struct git_transfer_progress
;
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(
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);
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
);
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 git_revnum_t
& hash1
, const git_revnum_t
& 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 * Create a font which can is used for log messages, etc
111 static void CreateFontForLogs(CFont
& fontToCreate
);
114 * Launch the external blame viewer
116 static bool LaunchTortoiseBlame(
117 const CString
& sBlameFile
, CString Rev
, const CString
& sParams
= CString());
120 * Launch alternative editor
122 static bool LaunchAlternativeEditor(const CString
& filename
, bool uac
= false);
125 * Sets the title of a dialog
127 static void SetWindowTitle(HWND hWnd
, const CString
& urlorpath
, const CString
& dialogname
);
130 * Formats text in a rich edit control (version 2).
131 * text in between * chars is formatted bold
132 * text in between ^ chars is formatted italic
133 * text in between _ chars is underlined
135 static bool FormatTextInRichEditControl(CWnd
* pWnd
);
136 static bool FindStyleChars(const CString
& sText
, TCHAR stylechar
, int& start
, int& end
);
139 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
141 static bool StartShowUnifiedDiff(HWND hWnd
, const CTGitPath
& url1
, const git_revnum_t
& rev1
,
142 const CTGitPath
& url2
, const git_revnum_t
& rev2
,
144 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
145 bool bAlternateDiff
= false,
146 bool bIgnoreAncestry
= false,
149 bool bCompact
= false);
151 static bool Export(CString
*BashHash
= nullptr, const CTGitPath
*orgPath
= nullptr);
152 static bool CreateBranchTag(bool IsTag
=TRUE
,CString
*CommitHash
=NULL
, bool switch_new_brach
=false);
153 static bool Switch(CString initialRefName
= CString());
154 static bool PerformSwitch(CString ref
, bool bForce
= false, CString sNewBranch
= CString(), bool bBranchOverride
= false, BOOL bTrack
= 2, bool bMerge
= false);
156 static bool IgnoreFile(CTGitPathList
&filelist
,bool IsMask
);
157 static bool GitReset(CString
*CommitHash
,int type
=1);
158 static bool ConflictEdit(CTGitPath
&file
,bool bAlternativeTool
=false,bool revertTheirMy
=false);
160 static CString
GetMergeTempFile(CString str
,CTGitPath
&merge
);
161 static bool StashSave();
162 static bool StashApply(CString ref
, bool showChanges
= true);
163 static bool StashPop(bool showChanges
= true);
165 static bool IsSSHPutty();
167 static bool LaunchRemoteSetting();
169 static bool LaunchPAgent(CString
*keyfile
=NULL
,CString
* pRemote
=NULL
);
171 static CString
GetClipboardLink(const CString
&skipGitPrefix
= _T(""), int paramsCount
= 0);
172 static CString
ChooseRepository(CString
*path
);
174 static bool SendPatchMail(CTGitPathList
&pathlist
);
175 static bool SendPatchMail(CString
&cmd
,CString
&formatpatchoutput
);
177 static int SaveCommitUnicodeFile(CString
&filename
, CString
&mesage
);
179 static int GetLogOutputEncode(CGit
*pGit
=&g_Git
);
181 static bool Pull(bool showPush
= false);
182 static bool Fetch(CString remoteName
= _T(""), bool allowRebase
= false, bool allRemotes
= false);
183 static bool Push(CString selectLocalBranch
= CString());
184 static bool RequestPull(CString endrevision
= _T(""), CString repositoryUrl
= _T(""));
186 static bool CreateMultipleDirectory(const CString
&dir
);
188 static void RemoveTrailSlash(CString
&path
);
190 static bool CheckUserData();
192 static BOOL
Commit(CString bugid
,BOOL bWholeProject
,CString
&sLogMsg
,
193 CTGitPathList
&pathList
,
194 CTGitPathList
&selectedList
,
195 bool bSelectFilesForCommit
);
197 static BOOL
SVNDCommit();
198 static BOOL
Merge(CString
*commit
=NULL
);
199 static BOOL
MergeAbort();
200 static void RemoveTempMergeFile(CTGitPath
&path
);
201 static void EditNote(GitRev
*hash
);
202 static int GetMsysgitVersion();
203 static void MarkWindowAsUnpinnable(HWND hWnd
);
205 static bool BisectStart(CString lastGood
, CString firstBad
);
207 static int Git2GetUserPassword(git_cred
**out
, const char *url
, const char *username_from_url
, unsigned int allowed_types
, void *payload
);
210 static CString
PickDiffTool(const CTGitPath
& file1
, const CTGitPath
& file2
);
212 static bool OpenIgnoreFile(CIgnoreFile
&file
, const CString
& filename
);
214 static void DescribeConflictFile(bool mode
, bool base
,CString
&descript
);