File tree Expand file tree Collapse file tree 5 files changed +17
-16
lines changed
Expand file tree Collapse file tree 5 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ export function getDiagnostics(doc: vscode.TextDocument): vscode.Diagnostic[] {
3535 returnMe . push ( ...getSecondLineDiagnostic ( secondLine ) ) ;
3636 }
3737
38- if ( utils . basename ( doc . fileName ) === "COMMIT_EDITMSG" ) {
38+ if ( doc . fileName . endsWith ( "COMMIT_EDITMSG" ) ) {
3939 returnMe . push ( ...getNoDiffDiagnostic ( doc ) ) ;
4040 }
4141
Original file line number Diff line number Diff line change 11import * as vscode from "vscode" ;
22import * as verbosecommits from "./verbosecommits" ;
3- import * as utils from "./utils" ;
43
54/** Show informational toast about doing verbose Git commits */
65export async function displayVerboseDiffMessage ( doc : vscode . TextDocument ) {
7- if ( utils . basename ( doc . fileName ) !== "COMMIT_EDITMSG" ) {
6+ if ( ! doc . fileName . endsWith ( "COMMIT_EDITMSG" ) ) {
87 // We only like one kind of files
98 return ;
109 }
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export default class GitCommitCodeActionProvider
2424 returnMe . push ( ...createBranchIssueIdFix ( gitBranch , doc , range ) ) ;
2525 returnMe . push ( ...createUpcaseJiraIdFix ( doc , range ) ) ;
2626
27- if ( utils . basename ( doc . fileName ) === "COMMIT_EDITMSG" ) {
27+ if ( doc . fileName . endsWith ( "COMMIT_EDITMSG" ) ) {
2828 returnMe . push ( ...( await createEnableGitVerboseCommitFix ( doc , range ) ) ) ;
2929 }
3030
Original file line number Diff line number Diff line change @@ -50,4 +50,14 @@ suite("Utils", () => {
5050 undefined ,
5151 ) ;
5252 } ) ;
53+
54+ test ( "Our dirname works on Windows as well" , ( ) => {
55+ assert . strictEqual ( utils . dirname ( "/foo/bar/baz.txt" ) , "/foo/bar" ) ;
56+ assert . strictEqual ( utils . dirname ( "foo/bar/baz.txt" ) , "foo/bar" ) ;
57+ assert . strictEqual ( utils . dirname ( "baz.txt" ) , "" ) ;
58+ assert . strictEqual ( utils . dirname ( "/foo/bar/" ) , "/foo" ) ;
59+ assert . strictEqual ( utils . dirname ( "C:/foo/bar/baz.txt" ) , "C:/foo/bar" ) ;
60+ assert . strictEqual ( utils . dirname ( "C:/foo/bar/" ) , "C:/foo" ) ;
61+ assert . strictEqual ( utils . dirname ( "baz.txt" ) , "" ) ;
62+ } ) ;
5363} ) ;
Original file line number Diff line number Diff line change @@ -94,25 +94,17 @@ export function getJiraIssueIdFromBranchName(
9494 return undefined ;
9595}
9696
97- /**
98- * Returns the last portion of a path, handling both / and \ separators.
99- * Equivalent to Node's path.basename, but works in browser and cross-platform.
100- * @param filePath - The full file path.
101- * @returns The file name portion of the path.
102- */
103- export function basename ( filePath : string ) : string {
104- const parts = filePath . split ( / [ / ] + / ) ;
105- return parts . pop ( ) || "" ;
106- }
107-
10897/**
10998 * Returns the directory portion of a path, handling both / and \ separators.
11099 * Equivalent to Node's path.dirname, but works in browser and cross-platform.
111100 * @param filePath - The full file path.
112101 * @returns The directory portion of the path.
113102 */
114103export function dirname ( filePath : string ) : string {
115- const parts = filePath . split ( / [ / ] + / ) ;
104+ // First, remove any trailing / or \
105+ filePath = filePath . replace ( / [ \\ / ] + $ / , "" ) ;
106+
107+ const parts = filePath . split ( / [ \\ / ] + / ) ;
116108 parts . pop ( ) ;
117109 return parts . join ( "/" ) ;
118110}
You can’t perform that action at this time.
0 commit comments