This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Microsoft/users/jpricket/0202
Adding Checkin and hooking it up to the viewlet
- Loading branch information
Showing
14 changed files
with
497 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
"use strict"; | ||
|
||
import { TeamServerContext} from "../../contexts/servercontext"; | ||
import { IArgumentProvider, IExecutionResult, ITfvcCommand } from "../interfaces"; | ||
import { ArgumentBuilder } from "./argumentbuilder"; | ||
import { CommandHelper } from "./commandhelper"; | ||
|
||
/** | ||
* This command checks in files into TFVC | ||
* <p/> | ||
* checkin [/all] [/author:<value>] [/comment:<value>|@valuefile] [/notes:"note"="value"[;"note2"="value2"[;...]]|@notefile] | ||
* [/override:<value>|@valuefile] [/recursive] [/validate] [/bypass] [/force] [/noautoresolve] [/associate:<workItemID>[,<workItemID>...]] | ||
* [/resolve:<workItemID>[,<workItemID>...]] [/saved] [<itemSpec>...] | ||
*/ | ||
export class Checkin implements ITfvcCommand<string> { | ||
private _serverContext: TeamServerContext; | ||
private _files: string[]; | ||
private _comment: string; | ||
private _workItemIds: number[]; | ||
|
||
public constructor(serverContext: TeamServerContext, files: string[], comment?: string, workItemIds?: number[]) { | ||
CommandHelper.RequireStringArrayArgument(files, "files"); | ||
this._serverContext = serverContext; | ||
this._files = files; | ||
this._comment = comment; | ||
this._workItemIds = workItemIds; | ||
} | ||
|
||
public GetArguments(): IArgumentProvider { | ||
const builder: ArgumentBuilder = new ArgumentBuilder("checkin", this._serverContext) | ||
.AddAll(this._files); | ||
if (this._comment) { | ||
builder.AddSwitchWithValue("comment", this.getComment(), false); | ||
} | ||
if (this._workItemIds && this._workItemIds.length > 0) { | ||
builder.AddSwitchWithValue("associate", this.getAssociatedWorkItems(), false); | ||
} | ||
return builder; | ||
} | ||
|
||
public GetOptions(): any { | ||
return {}; | ||
} | ||
|
||
private getComment(): string { | ||
// replace newlines with spaces | ||
return this._comment.replace(/\r\n/g, " ").replace(/\n/g, " "); | ||
} | ||
|
||
private getAssociatedWorkItems(): string { | ||
return this._workItemIds.join(","); | ||
} | ||
|
||
/** | ||
* Returns the files that were checked in | ||
* <p/> | ||
* Output example for success: | ||
* /Users/leantk/tfvc-tfs/tfsTest_01/addFold: | ||
* Checking in edit: testHere.txt | ||
* <p/> | ||
* /Users/leantk/tfvc-tfs/tfsTest_01: | ||
* Checking in edit: test3.txt | ||
* Checking in edit: TestAdd.txt | ||
* <p/> | ||
* Changeset #20 checked in. | ||
* <p/> | ||
* Output example for failure: | ||
* <p/> | ||
* /Users/leantk/tfvc-tfs/tfsTest_01: | ||
* Checking in edit: test3.txt | ||
* Checking in edit: TestAdd.txt | ||
* Unable to perform operation on $/tfsTest_01/TestAdd.txt. The item $/tfsTest_01/TestAdd.txt is locked in workspace new;Leah Antkiewicz. | ||
* No files checked in. | ||
* <p/> | ||
* No files checked in. | ||
*/ | ||
public async ParseOutput(executionResult: IExecutionResult): Promise<string> { | ||
if (executionResult.exitCode === 100) { | ||
CommandHelper.ProcessErrors(this.GetArguments().GetCommand(), executionResult, true); | ||
} else { | ||
return CommandHelper.GetChangesetNumber(executionResult.stdout); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
"use strict"; | ||
|
||
import { workspace, window, languages, Disposable, Uri, HoverProvider, Hover, TextEditor, Position, TextDocument, Range, TextEditorDecorationType, WorkspaceEdit } from "vscode"; | ||
import { Model } from "./model"; | ||
import { filterEvent } from "../util"; | ||
|
||
const scmInputUri = Uri.parse("scm:input"); | ||
|
||
function isSCMInput(uri: Uri) { | ||
return uri.toString() === scmInputUri.toString(); | ||
} | ||
|
||
interface Diagnostic { | ||
range: Range; | ||
message: string; | ||
} | ||
|
||
export class CommitHoverProvider implements HoverProvider { | ||
|
||
private decorationType: TextEditorDecorationType; | ||
private diagnostics: Diagnostic[] = []; | ||
private disposables: Disposable[] = []; | ||
private editor: TextEditor; | ||
private visibleTextEditorsDisposable: Disposable; | ||
|
||
constructor(private model: Model) { | ||
this.visibleTextEditorsDisposable = window.onDidChangeVisibleTextEditors(this.onVisibleTextEditors, this); | ||
this.onVisibleTextEditors(window.visibleTextEditors); | ||
|
||
this.decorationType = window.createTextEditorDecorationType({ | ||
isWholeLine: true, | ||
color: "rgb(228, 157, 43)", | ||
dark: { | ||
color: "rgb(220, 211, 71)" | ||
} | ||
}); | ||
} | ||
|
||
public get message(): string | undefined { | ||
if (!this.editor) { | ||
return; | ||
} | ||
|
||
return this.editor.document.getText(); | ||
} | ||
|
||
public set message(message: string | undefined) { | ||
if (!this.editor || message === undefined) { | ||
return; | ||
} | ||
|
||
const document = this.editor.document; | ||
const start = document.lineAt(0).range.start; | ||
const end = document.lineAt(document.lineCount - 1).range.end; | ||
const range = new Range(start, end); | ||
const edit = new WorkspaceEdit(); | ||
edit.replace(scmInputUri, range, message); | ||
workspace.applyEdit(edit); | ||
} | ||
|
||
private onVisibleTextEditors(editors: TextEditor[]): void { | ||
const [editor] = editors.filter(e => isSCMInput(e.document.uri)); | ||
|
||
if (!editor) { | ||
return; | ||
} | ||
|
||
this.visibleTextEditorsDisposable.dispose(); | ||
this.editor = editor; | ||
|
||
const onDidChange = filterEvent(workspace.onDidChangeTextDocument, e => e.document && isSCMInput(e.document.uri)); | ||
onDidChange(this.update, this, this.disposables); | ||
|
||
workspace.onDidChangeConfiguration(this.update, this, this.disposables); | ||
languages.registerHoverProvider({ scheme: "scm" }, this); | ||
} | ||
|
||
private update(): void { | ||
this.diagnostics = []; | ||
//TODO provide any diagnostic info based on the message here (see git commitcontroller) | ||
this.editor.setDecorations(this.decorationType, this.diagnostics.map(d => d.range)); | ||
} | ||
|
||
/* Implement HoverProvider */ | ||
provideHover(document: TextDocument, position: Position): Hover | undefined { | ||
const [decoration] = this.diagnostics.filter(d => d.range.contains(position)); | ||
|
||
if (!decoration) { | ||
return; | ||
} | ||
|
||
return new Hover(decoration.message, decoration.range); | ||
} | ||
|
||
dispose(): void { | ||
this.disposables.forEach(d => d.dispose()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.