Fixed issue #1519: Quotes in notes break Merge command
[TortoiseGit.git] / src / TortoiseProc / AppUtils.h
blob3fa547046d2b8616a6782cc74fc9ea978981cc05
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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;
27 enum GIT_POST_CMD
29 GIT_POST_CMD_PUSH,
30 GIT_POST_CMD_DCOMMIT
32 /**
33 * \ingroup TortoiseProc
34 * An utility class with static functions.
36 class CAppUtils : public CCommonAppUtils
38 public:
39 /**
40 * Flags for StartExtDiff function.
42 struct DiffFlags
44 bool bWait;
45 bool bBlame;
46 bool bReadOnly;
47 bool bAlternativeTool; // If true, invert selection of TortoiseMerge vs. external diff tool
49 DiffFlags(): bWait(false), bBlame(false), bReadOnly(false), bAlternativeTool(false) {}
50 DiffFlags& Wait(bool b = true) { bWait = b; return *this; }
51 DiffFlags& Blame(bool b = true) { bBlame = b; return *this; }
52 DiffFlags& ReadOnly(bool b = true) { bReadOnly = b; return *this; }
53 DiffFlags& AlternativeTool(bool b = true) { bAlternativeTool = b; return *this; }
56 CAppUtils(void);
57 ~CAppUtils(void);
59 /**
60 * Launches the external merge program if there is one.
61 * \return TRUE if the program could be started
63 static BOOL StartExtMerge(
64 const CTGitPath& basefile, const CTGitPath& theirfile, const CTGitPath& yourfile, const CTGitPath& mergedfile,
65 const CString& basename = CString(), const CString& theirname = CString(), const CString& yourname = CString(),
66 const CString& mergedname = CString(), bool bReadOnly = false);
68 /**
69 * Starts the external patch program (currently always TortoiseMerge)
71 static BOOL StartExtPatch(const CTGitPath& patchfile, const CTGitPath& dir,
72 const CString& sOriginalDescription = CString(), const CString& sPatchedDescription = CString(),
73 BOOL bReversed = FALSE, BOOL bWait = FALSE);
75 /**
76 * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).
77 * If no app is associated with those file types, the default text editor is used.
79 static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);
81 /**
82 * Sets up all the default diff and merge scripts.
83 * \param force if true, overwrite all existing entries
84 * \param either "Diff", "Merge" or an empty string
86 static bool SetupDiffScripts(bool force, const CString& type);
88 /**
89 * Starts the external diff application
91 static bool StartExtDiff(
92 const CString& file1, const CString& file2,
93 const CString& sName1, const CString& sName2,
94 const CString& originalFile1, const CString& originalFile2,
95 const git_revnum_t& hash1, const git_revnum_t& hash2, const DiffFlags& flags);
97 /**
98 * Launches the standard text viewer/editor application which is associated
99 * with txt files.
100 * \return TRUE if the program could be started.
102 static BOOL StartTextViewer(CString file);
105 * Checks if the given file has a size of less than four, which means
106 * an 'empty' file or just newlines, i.e. an empty diff.
108 static BOOL CheckForEmptyDiff(const CTGitPath& sDiffPath);
111 * Create a font which can is used for log messages, etc
113 static void CreateFontForLogs(CFont& fontToCreate);
116 * Launch the external blame viewer
118 static bool LaunchTortoiseBlame(
119 const CString& sBlameFile, CString Rev, const CString& sParams = CString());
122 * Launch alternative editor
124 static bool LaunchAlternativeEditor(const CString& filename, bool uac = false);
127 * Sets the title of a dialog
129 static void SetWindowTitle(HWND hWnd, const CString& urlorpath, const CString& dialogname);
132 * Formats text in a rich edit control (version 2).
133 * text in between * chars is formatted bold
134 * text in between ^ chars is formatted italic
135 * text in between _ chars is underlined
137 static bool FormatTextInRichEditControl(CWnd * pWnd);
138 static bool FindStyleChars(const CString& sText, TCHAR stylechar, int& start, int& end);
141 * guesses a name of the project from a repository URL
143 static CString GetProjectNameFromURL(CString url);
146 * Replacement for GitDiff::ShowUnifiedDiff(), but started as a separate process.
148 static bool StartShowUnifiedDiff(HWND hWnd, const CTGitPath& url1, const git_revnum_t& rev1,
149 const CTGitPath & url2, const git_revnum_t& rev2,
151 //const GitRev& peg = GitRev(), const GitRev& headpeg = GitRev(),
152 bool bAlternateDiff = false,
153 bool bIgnoreAncestry = false,
154 bool blame = false,
155 bool bMerge = false);
157 static bool Export(CString *BashHash=NULL);
158 static bool CreateBranchTag(bool IsTag=TRUE,CString *CommitHash=NULL, bool switch_new_brach=false);
159 static bool Switch(CString initialRefName = CString(), bool autoClose = false);
160 static bool PerformSwitch(CString ref, bool bForce = false, CString sNewBranch = CString(), bool bBranchOverride = false, BOOL bTrack = 2, bool autoClose = false);
162 static bool IgnoreFile(CTGitPathList &filelist,bool IsMask);
163 static bool GitReset(CString *CommitHash,int type=1);
164 static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false,bool revertTheirMy=false);
166 static CString GetMergeTempFile(CString str,CTGitPath &merge);
167 static bool StashSave();
168 static bool StashApply(CString ref, bool showChanges = true);
169 static bool StashPop(bool showChanges = true);
171 static bool IsSSHPutty();
173 static bool LaunchRemoteSetting();
175 static bool LaunchPAgent(CString *keyfile=NULL,CString * pRemote=NULL);
177 static CString GetClipboardLink();
178 static CString ChooseRepository(CString *path);
180 static bool SendPatchMail(CTGitPathList &pathlist,bool autoclose=false);
181 static bool SendPatchMail(CString &cmd,CString &formatpatchoutput,bool autoclose=false);
183 static int SaveCommitUnicodeFile(CString &filename, CString &mesage);
185 static int GetLogOutputEncode(CGit *pGit=&g_Git);
187 static bool Fetch(CString remoteName = _T(""), bool allowRebase = false, bool autoClose = false);
188 static bool Push(CString selectLocalBranch = CString(), bool autoClose = false);
189 static bool RequestPull(CString endrevision = _T(""), CString repositoryUrl = _T(""));
191 static bool CreateMultipleDirectory(const CString &dir);
193 static void RemoveTrailSlash(CString &path);
195 static BOOL Commit(CString bugid,BOOL bWholeProject,CString &sLogMsg,
196 CTGitPathList &pathList,
197 CTGitPathList &selectedList,
198 bool bSelectFilesForCommit,
199 bool autoClose = false);
201 static int GetCommitTemplate(CString &temp);
203 static BOOL SVNDCommit();
204 static BOOL Merge(CString *commit =NULL);
205 static void RemoveTempMergeFile(CTGitPath &path);
206 static void EditNote(GitRev *hash);
207 static int GetMsysgitVersion(CString *versionstring=NULL);
208 static void MarkWindowAsUnpinnable(HWND hWnd);
210 static bool BisectStart(CString lastGood, CString firstBad, bool autoClose = false);
212 private:
213 static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2);
214 static bool GetMimeType(const CTGitPath& file, CString& mimetype);
216 static bool OpenIgnoreFile(CStdioFile &file, const CString& filename);
218 static void DescribeFile(bool mode, bool base,CString &descript);