Skip to content

Commit

Permalink
Merge pull request #245 from edgardmessias/improve_commit
Browse files Browse the repository at this point in the history
Improved commit (Close #235, #236, #240)
  • Loading branch information
JohnstonCode authored Apr 10, 2018
2 parents 66fea10 + 3305c68 commit 35522c3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
17 changes: 10 additions & 7 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ export class SvnCommands implements IDisposable {

@command("svn.commitWithMessage", { repository: true })
async commitWithMessage(repository: Repository) {
const message = repository.inputBox.value;
if (!message) {
const choice = await inputCommitChangelist(repository);
if (!choice) {
return;
}

const choice = await inputCommitChangelist(repository);
if (!choice) {
const message = await inputCommitMessage(repository.inputBox.value, false);
if (message === undefined) {
return;
}

Expand All @@ -183,7 +183,7 @@ export class SvnCommands implements IDisposable {
repository.inputBox.value = "";
} catch (error) {
console.error(error);
window.showErrorMessage("Unable to commit");
window.showErrorMessage(error.stderrFormated);
}
}

Expand Down Expand Up @@ -311,17 +311,20 @@ export class SvnCommands implements IDisposable {
const paths = resources.map(resource => resource.fsPath);

try {
const message = await inputCommitMessage();
const message = await inputCommitMessage(repository.inputBox.value);

if (message === undefined) {
return;
}

repository.inputBox.value = message;

const result = await repository.commitFiles(message, paths);
window.showInformationMessage(result);
repository.inputBox.value = "";
} catch (error) {
console.error(error);
window.showErrorMessage("Unable to commit");
window.showErrorMessage(error.stderrFormated);
}
});
}
Expand Down
41 changes: 26 additions & 15 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ export function noChangesToCommit() {
return window.showInformationMessage("There are no changes to commit.");
}

export function inputCommitMessage(message?: string) {
return new Promise<string>((resolve, reject) => {
if (message) {
resolve(message);
return;
}
export async function inputCommitMessage(
message?: string,
promptNew: boolean = true
): Promise<string | undefined> {
if (promptNew) {
message = await window.showInputBox({
value: message,
placeHolder: "Commit message",
prompt: "Please enter a commit message",
ignoreFocusOut: true
});
}

if (!message) {
const allowEmpty = await window.showWarningMessage(
"Do you really want to commit an empty message?",
{ modal: true },
"Yes"
);

window
.showInputBox({
value: "",
placeHolder: "Commit message",
prompt: "Please enter a commit message",
ignoreFocusOut: true
})
.then(input => resolve(input));
});
if (allowEmpty === "Yes") {
return "";
} else {
return undefined;
}
}
return message;
}
6 changes: 5 additions & 1 deletion src/svn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface ISvnErrorData {
message?: string;
stdout?: string;
stderr?: string;
stderrFormated?: string;
exitCode?: number;
svnErrorCode?: string;
svnCommand?: string;
Expand Down Expand Up @@ -110,6 +111,7 @@ export class SvnError {
message: string;
stdout?: string;
stderr?: string;
stderrFormated?: string;
exitCode?: number;
svnErrorCode?: string;
svnCommand?: string;
Expand All @@ -125,6 +127,7 @@ export class SvnError {
this.message = data.message || "SVN error";
this.stdout = data.stdout;
this.stderr = data.stderr;
this.stderrFormated = data.stderrFormated;
this.exitCode = data.exitCode;
this.svnErrorCode = data.svnErrorCode;
this.svnCommand = data.svnCommand;
Expand Down Expand Up @@ -184,7 +187,7 @@ export class Svn {
}

if (options.log !== false) {
const argsOut = args.map(arg => (/ /.test(arg) ? `'${arg}'` : arg));
const argsOut = args.map(arg => (/ |^$/.test(arg) ? `'${arg}'` : arg));
this.logOutput(
`[${this.lastCwd.split(/[\\\/]+/).pop()}]$ svn ${argsOut.join(" ")}\n`
);
Expand Down Expand Up @@ -281,6 +284,7 @@ export class Svn {
message: "Failed to execute svn",
stdout: stdout,
stderr: stderr,
stderrFormated: stderr.replace(/^svn: E\d+: +/gm, ""),
exitCode: exitCode,
svnErrorCode: getSvnErrorCode(stderr),
svnCommand: args[0]
Expand Down

0 comments on commit 35522c3

Please sign in to comment.