comparison src/mainwindow.cpp @ 537:a4e699d32a9a

gah! hg 2.1 changes push and pull so as to return failure codes on success, if there was nothing to push or pull
author Chris Cannam
date Fri, 10 Feb 2012 13:08:07 +0000
parents 2262f753b19e
children fc2df97920e8
comparison
equal deleted inserted replaced
536:5f04fa848f34 537:a4e699d32a9a
79 m_runner = new HgRunner(m_myDirPath, this); 79 m_runner = new HgRunner(m_myDirPath, this);
80 connect(m_runner, SIGNAL(commandStarting(HgAction)), 80 connect(m_runner, SIGNAL(commandStarting(HgAction)),
81 this, SLOT(commandStarting(HgAction))); 81 this, SLOT(commandStarting(HgAction)));
82 connect(m_runner, SIGNAL(commandCompleted(HgAction, QString)), 82 connect(m_runner, SIGNAL(commandCompleted(HgAction, QString)),
83 this, SLOT(commandCompleted(HgAction, QString))); 83 this, SLOT(commandCompleted(HgAction, QString)));
84 connect(m_runner, SIGNAL(commandFailed(HgAction, QString)), 84 connect(m_runner, SIGNAL(commandFailed(HgAction, QString, QString)),
85 this, SLOT(commandFailed(HgAction, QString))); 85 this, SLOT(commandFailed(HgAction, QString, QString)));
86 statusBar()->addPermanentWidget(m_runner); 86 statusBar()->addPermanentWidget(m_runner);
87 87
88 setWindowTitle(tr("EasyMercurial")); 88 setWindowTitle(tr("EasyMercurial"));
89 89
90 m_remoteRepoPath = ""; 90 m_remoteRepoPath = "";
2097 if (action.action == ACT_STAT) { 2097 if (action.action == ACT_STAT) {
2098 suspendFileSystemWatcher(); 2098 suspendFileSystemWatcher();
2099 } 2099 }
2100 } 2100 }
2101 2101
2102 void MainWindow::commandFailed(HgAction action, QString output) 2102 void MainWindow::commandFailed(HgAction action, QString stderr, QString stdout)
2103 { 2103 {
2104 DEBUG << "MainWindow::commandFailed" << endl; 2104 DEBUG << "MainWindow::commandFailed" << endl;
2105 restoreFileSystemWatcher(); 2105 restoreFileSystemWatcher();
2106 2106
2107 QString setstr; 2107 QString setstr;
2128 MoreInformationDialog::warning 2128 MoreInformationDialog::warning
2129 (this, 2129 (this,
2130 tr("Failed to run Mercurial"), 2130 tr("Failed to run Mercurial"),
2131 tr("Failed to run Mercurial"), 2131 tr("Failed to run Mercurial"),
2132 tr("The Mercurial program either could not be found or failed to run.<br><br>Check that the Mercurial program path is correct in %1.").arg(setstr), 2132 tr("The Mercurial program either could not be found or failed to run.<br><br>Check that the Mercurial program path is correct in %1.").arg(setstr),
2133 output); 2133 stderr);
2134 settings(SettingsDialog::PathsTab); 2134 settings(SettingsDialog::PathsTab);
2135 return; 2135 return;
2136 case ACT_TEST_HG_EXT: 2136 case ACT_TEST_HG_EXT:
2137 MoreInformationDialog::warning 2137 MoreInformationDialog::warning
2138 (this, 2138 (this,
2139 tr("Failed to run Mercurial"), 2139 tr("Failed to run Mercurial"),
2140 tr("Failed to run Mercurial with extension enabled"), 2140 tr("Failed to run Mercurial with extension enabled"),
2141 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem.<br><br>You may be able to continue working if you switch off &ldquo;Use EasyHg Mercurial Extension&rdquo; in %1. Note that remote repositories that require authentication might not work if you do this.").arg(setstr), 2141 tr("The Mercurial program failed to run with the EasyMercurial interaction extension enabled.<br>This may indicate an installation problem.<br><br>You may be able to continue working if you switch off &ldquo;Use EasyHg Mercurial Extension&rdquo; in %1. Note that remote repositories that require authentication might not work if you do this.").arg(setstr),
2142 output); 2142 stderr);
2143 settings(SettingsDialog::PathsTab); 2143 settings(SettingsDialog::PathsTab);
2144 return; 2144 return;
2145 case ACT_CLONEFROMREMOTE: 2145 case ACT_CLONEFROMREMOTE:
2146 // if clone fails, we have no repo 2146 // if clone fails, we have no repo
2147 m_workFolderPath = ""; 2147 m_workFolderPath = "";
2148 enableDisableActions(); 2148 enableDisableActions();
2149 break; // go on to default report 2149 break; // go on to default report
2150 case ACT_INCOMING: 2150 case ACT_INCOMING:
2151 if (output.contains("authorization failed")) { 2151 if (stderr.contains("authorization failed")) {
2152 reportAuthFailed(output); 2152 reportAuthFailed(stderr);
2153 return; 2153 return;
2154 } else if (output.contains("entry cancelled")) { 2154 } else if (stderr.contains("entry cancelled")) {
2155 // ignore this, user cancelled username or password dialog 2155 // ignore this, user cancelled username or password dialog
2156 return; 2156 return;
2157 } else { 2157 } else {
2158 // Incoming returns non-zero code and no output if the 2158 // Incoming returns non-zero code and no stderr if the
2159 // check was successful but there are no changes 2159 // check was successful but there are no changes
2160 // pending. This is the only case where we need to remove 2160 // pending. This is the only case where we need to remove
2161 // warning messages, because it's the only case where a 2161 // warning messages, because it's the only case where a
2162 // non-zero code can be returned even though the command 2162 // non-zero code can be returned even though the command
2163 // has for our purposes succeeded 2163 // has for our purposes succeeded
2164 QString replaced = output; 2164 QString replaced = stderr;
2165 while (1) { 2165 while (1) {
2166 QString r1 = replaced; 2166 QString r1 = replaced;
2167 r1.replace(QRegExp("warning: [^\\n]*"), ""); 2167 r1.replace(QRegExp("warning: [^\\n]*"), "");
2168 if (r1 == replaced) break; 2168 if (r1 == replaced) break;
2169 replaced = r1.trimmed(); 2169 replaced = r1.trimmed();
2173 return; 2173 return;
2174 } 2174 }
2175 } 2175 }
2176 break; // go on to default report 2176 break; // go on to default report
2177 case ACT_PULL: 2177 case ACT_PULL:
2178 if (output.contains("authorization failed")) { 2178 if (stderr.contains("authorization failed")) {
2179 reportAuthFailed(output); 2179 reportAuthFailed(stderr);
2180 return; 2180 return;
2181 } else if (output.contains("entry cancelled")) { 2181 } else if (stderr.contains("entry cancelled")) {
2182 // ignore this, user cancelled username or password dialog 2182 // ignore this, user cancelled username or password dialog
2183 return; 2183 return;
2184 } else if (stderr.contains("no changes found") || stdout.contains("no changes found")) {
2185 // success: hg 2.1 starts returning failure code for empty pull/push
2186 commandCompleted(action, stdout);
2187 return;
2184 } 2188 }
2185 break; // go on to default report 2189 break; // go on to default report
2186 case ACT_PUSH: 2190 case ACT_PUSH:
2187 if (output.contains("creates new remote head")) { 2191 if (stderr.contains("creates new remote head")) {
2188 reportNewRemoteHeads(output); 2192 reportNewRemoteHeads(stderr);
2189 return; 2193 return;
2190 } else if (output.contains("authorization failed")) { 2194 } else if (stderr.contains("authorization failed")) {
2191 reportAuthFailed(output); 2195 reportAuthFailed(stderr);
2192 return; 2196 return;
2193 } else if (output.contains("entry cancelled")) { 2197 } else if (stderr.contains("entry cancelled")) {
2194 // ignore this, user cancelled username or password dialog 2198 // ignore this, user cancelled username or password dialog
2199 return;
2200 } else if (stderr.contains("no changes found") || stdout.contains("no changes found")) {
2201 // success: hg 2.1 starts returning failure code for empty pull/push
2202 commandCompleted(action, stdout);
2195 return; 2203 return;
2196 } 2204 }
2197 break; // go on to default report 2205 break; // go on to default report
2198 case ACT_QUERY_HEADS_ACTIVE: 2206 case ACT_QUERY_HEADS_ACTIVE:
2199 case ACT_QUERY_HEADS: 2207 case ACT_QUERY_HEADS:
2208 // external program, unlikely to be anything useful in stderr 2216 // external program, unlikely to be anything useful in stderr
2209 // and some return with failure codes when something as basic 2217 // and some return with failure codes when something as basic
2210 // as the user closing the window via the wm happens 2218 // as the user closing the window via the wm happens
2211 return; 2219 return;
2212 case ACT_MERGE: 2220 case ACT_MERGE:
2213 if (output.contains("working directory ancestor")) { 2221 if (stderr.contains("working directory ancestor")) {
2214 // arguably we should prevent this upfront, but that's 2222 // arguably we should prevent this upfront, but that's
2215 // trickier! 2223 // trickier!
2216 MoreInformationDialog::information 2224 MoreInformationDialog::information
2217 (this, tr("Merge"), tr("Merge has no effect"), 2225 (this, tr("Merge"), tr("Merge has no effect"),
2218 tr("You asked to merge a revision with one of its ancestors.<p>This has no effect, because the ancestor's changes already exist in both revisions."), 2226 tr("You asked to merge a revision with one of its ancestors.<p>This has no effect, because the ancestor's changes already exist in both revisions."),
2219 output); 2227 stderr);
2220 return; 2228 return;
2221 } 2229 }
2222 // else fall through 2230 // else fall through
2223 case ACT_RETRY_MERGE: 2231 case ACT_RETRY_MERGE:
2224 MoreInformationDialog::information 2232 MoreInformationDialog::information
2225 (this, tr("Merge"), tr("Merge failed"), 2233 (this, tr("Merge"), tr("Merge failed"),
2226 tr("Some files were not merged successfully.<p>You can Merge again to repeat the interactive merge; use Revert to abandon the merge entirely; or edit the files that are in conflict in an editor and, when you are happy with them, choose Mark Resolved in each file's right-button menu."), 2234 tr("Some files were not merged successfully.<p>You can Merge again to repeat the interactive merge; use Revert to abandon the merge entirely; or edit the files that are in conflict in an editor and, when you are happy with them, choose Mark Resolved in each file's right-button menu."),
2227 output); 2235 stderr);
2228 m_mergeCommitComment = ""; 2236 m_mergeCommitComment = "";
2229 return; 2237 return;
2230 case ACT_STAT: 2238 case ACT_STAT:
2231 break; // go on to default report 2239 break; // go on to default report
2232 default: 2240 default:
2241 2249
2242 MoreInformationDialog::warning 2250 MoreInformationDialog::warning
2243 (this, 2251 (this,
2244 tr("Command failed"), 2252 tr("Command failed"),
2245 tr("Command failed"), 2253 tr("Command failed"),
2246 (output == "" ? 2254 (stderr == "" ?
2247 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.") : 2255 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.") :
2248 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.<br><br>See &ldquo;More Details&rdquo; for the command output.")), 2256 tr("A Mercurial command failed to run correctly. This may indicate an installation problem or some other problem with EasyMercurial.<br><br>See &ldquo;More Details&rdquo; for the command output.")),
2249 output); 2257 stderr);
2250 } 2258 }
2251 2259
2252 void MainWindow::commandCompleted(HgAction completedAction, QString output) 2260 void MainWindow::commandCompleted(HgAction completedAction, QString output)
2253 { 2261 {
2254 // std::cerr << "commandCompleted: " << completedAction.action << std::endl; 2262 // std::cerr << "commandCompleted: " << completedAction.action << std::endl;