Improve handling of splitting remote name and branch name in Reference Browser
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob0fb6ad3adaa297c3bd1af0273c739b35248263a8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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.
20 #pragma once
21 #include "HistoryCombo.h"
22 #include "GitRev.h"
23 #include "CommonAppUtils.h"
25 class CTGitPath;
26 struct git_cred;
27 struct git_transfer_progress;
29 enum GIT_POST_CMD
31 GIT_POST_CMD_PUSH,
32 GIT_POST_CMD_DCOMMIT
34 /**
35 * \ingroup TortoiseProc
36 * An utility class with static functions.
38 class CAppUtils : public CCommonAppUtils
40 public:
41 /**
42 * Flags for StartExtDiff function.
44 struct DiffFlags
46 bool bWait;
47 bool bBlame;
48 bool bReadOnly;
49 bool bAlternativeTool; // If true, invert selection of TortoiseGitMerge vs. external diff tool
51 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
52 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
53 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }
54 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
55 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
58 CAppUtils(void);
59 ~CAppUtils(void);
61 /**
62 * Launches the external merge program if there is one.
63 * \return TRUE if the program could be started
65 static BOOL StartExtMerge(
66 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
67 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
68 const CString& mergedname = CString(), bool bReadOnly = false);
70 /**
71 * Starts the external patch program (currently always TortoiseGitMerge)
73 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
74 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
75 BOOL bReversed = FALSE, BOOL bWait = FALSE);
77 /**
78 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
79 * If no app is associated with those file types, the default text editor is used.
81 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);
83 /**
84 * Sets up all the default diff and merge scripts.
85 * \param force if true, overwrite all existing entries
86 * \param either "Diff", "Merge" or an empty string
88 static bool SetupDiffScripts(bool force, const CString& type);
90 /**
91 * Starts the external diff application
93 static bool StartExtDiff(
94 const CString& file1, const CString& file2,
95 const CString& sName1, const CString& sName2,
96 const CString& originalFile1, const CString& originalFile2,
97 const git_revnum_t& hash1, const git_revnum_t& hash2, const DiffFlags& flags);
99 /**
100 * Launches the standard text viewer/editor application which is associated
101 * with txt files.
102 * \return TRUE if the program could be started.
104 static BOOL StartTextViewer(CString file);
107 * Checks if the given file has a size of less than four, which means
108 * an 'empty' file or just newlines, i.e. an empty diff.
110 static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);
113 * Create a font which can is used for log messages, etc
115 static void CreateFontForLogs(CFont& fontToCreate);
118 * Launch the external blame viewer
120 static bool LaunchTortoiseBlame(
121 const CString& sBlameFile, CString Rev, const CString& sParams = CString());
124 * Launch alternative editor
126 static bool LaunchAlternativeEditor(const CString& filename, bool uac = false);
129 * Sets the title of a dialog
131 static void SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname);
134 * Formats text in a rich edit control (version 2).
135 * text in between * chars is formatted bold
136 * text in between ^ chars is formatted italic
137 * text in between _ chars is underlined
139 static bool FormatTextInRichEditControl(CWnd * pWnd);
140 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
143 * guesses a name of the project from a repository URL
145 static CString GetProjectNameFromURL(CString url);
148 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
150 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
151 const CTGitPath & url2, const git_revnum_t& rev2,
153 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
154 bool bAlternateDiff = false,
155 bool bIgnoreAncestry = false,
156 bool blame = false,
157 bool bMerge = false);
159 static bool Export(CString *BashHash=NULL);
160 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL, bool switch_new_brach=false);
161 static bool Switch(CString initialRefName = CString(), bool autoClose = false);
162 static bool PerformSwitch(CString ref, bool bForce = false, CString sNewBranch = CString(), bool bBranchOverride = false, BOOL bTrack = 2, bool autoClose = false);
164 static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);
165 static bool GitReset(CString *CommitHash,int type=1);
166 static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false,bool revertTheirMy=false);
168 static CString GetMergeTempFile(CString str,CTGitPath &merge);
169 static bool StashSave();
170 static bool StashApply(CString ref, bool showChanges = true);
171 static bool StashPop(bool showChanges = true);
173 static bool IsSSHPutty();
175 static bool LaunchRemoteSetting();
177 static bool LaunchPAgent(CString *keyfile=NULL,CString * pRemote=NULL);
179 static CString GetClipboardLink();
180 static CString ChooseRepository(CString *path);
182 static bool SendPatchMail(CTGitPathList &pathlist,bool autoclose=false);
183 static bool SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose=false);
185 static int SaveCommitUnicodeFile(CString &filename, CString &mesage);
187 static int GetLogOutputEncode(CGit *pGit=&g_Git);
189 static bool Fetch(CString remoteName = _T(""), bool allowRebase = false, bool autoClose = false);
190 static bool Push(CString selectLocalBranch = CString(), bool autoClose = false);
191 static bool RequestPull(CString endrevision = _T(""), CString repositoryUrl = _T(""));
193 static bool CreateMultipleDirectory(const CString &dir);
195 static void RemoveTrailSlash(CString &path);
197 static bool CheckUserData();
199 static BOOL Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
200 CTGitPathList &pathList,
201 CTGitPathList &selectedList,
202 bool bSelectFilesForCommit,
203 bool autoClose = false);
205 static int GetCommitTemplate(CString &temp);
207 static BOOL SVNDCommit();
208 static BOOL Merge(CString *commit =NULL);
209 static void RemoveTempMergeFile(CTGitPath &path);
210 static void EditNote(GitRev *hash);
211 static int GetMsysgitVersion(CString *versionstring=NULL);
212 static void MarkWindowAsUnpinnable(HWND hWnd);
214 static bool BisectStart(CString lastGood, CString firstBad, bool autoClose = false);
216 static int Git2GetUserPassword(git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload);
218 private:
219 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
220 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
222 static bool OpenIgnoreFile(CStdioFile &file, const CString& filename);
224 static void DescribeFile(bool mode, bool base,CString &descript);