forked from JohnstonCode/svn-scm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommitWithMessage.ts
63 lines (55 loc) · 1.78 KB
/
commitWithMessage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as path from "path";
import { window } from "vscode";
import { inputCommitFiles } from "../changelistItems";
import { Status } from "../common/types";
import { inputCommitMessage } from "../messages";
import { Repository } from "../repository";
import { Resource } from "../resource";
import { Command } from "./command";
export class CommitWithMessage extends Command {
constructor() {
super("svn.commitWithMessage", { repository: true });
}
public async execute(repository: Repository) {
const resourceStates = await inputCommitFiles(repository);
if (!resourceStates || resourceStates.length === 0) {
return;
}
const filePaths = resourceStates.map(state => {
return state.resourceUri.fsPath;
});
const message = await inputCommitMessage(
repository.inputBox.value,
false,
filePaths
);
if (message === undefined) {
return;
}
// If files is renamed, the commit need previous file
resourceStates.forEach(state => {
if (state instanceof Resource) {
if (state.type === Status.ADDED && state.renameResourceUri) {
filePaths.push(state.renameResourceUri.fsPath);
}
let dir = path.dirname(state.resourceUri.fsPath);
let parent = repository.getResourceFromFile(dir);
while (parent) {
if (parent.type === Status.ADDED) {
filePaths.push(dir);
}
dir = path.dirname(dir);
parent = repository.getResourceFromFile(dir);
}
}
});
try {
const result = await repository.commitFiles(message, filePaths);
window.showInformationMessage(result);
repository.inputBox.value = "";
} catch (error) {
console.error(error);
window.showErrorMessage(error.stderrFormated);
}
}
}