Skip to content

Commit

Permalink
fix(svn): Trigger process from working directory (#501)
Browse files Browse the repository at this point in the history
Fixes #499 

Avoids issue with character names in path by executing the process from
the working directory. However, this won't resolve issues where the
filename is in Chinese
  • Loading branch information
metacurb authored Jan 8, 2025
1 parent 9463c31 commit 9fd22da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to the "blamer-vs" extension will be documented in this file.

## [0.7.2] - 2025-01-08

### Fixed

- Bug when trying to blame from directories with non-English characters

## [0.7.1] - 2024-05-15

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "blamer-vs",
"displayName": "SVN Blamer",
"description": "Visually blame SVN-stored code line-by-line",
"version": "0.7.1",
"version": "0.7.2",
"publisher": "beaugust",
"repository": {
"type": "git",
Expand Down
25 changes: 19 additions & 6 deletions src/svn.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { basename, dirname } from "path";
import { LogOutputChannel, workspace } from "vscode";

import { EXTENSION_CONFIGURATION } from "./const/extension";
Expand All @@ -11,7 +12,10 @@ import { spawnProcess } from "./util/spawn-process";
export class SVN {
constructor(private logger: LogOutputChannel) {}

private async command(command: string, fileName: string) {
private async command(
command: string,
{ cwd, fileName }: { cwd: string; fileName: string },
): Promise<string> {
try {
const { svnExecutablePath } = workspace.getConfiguration(EXTENSION_CONFIGURATION);

Expand All @@ -22,7 +26,7 @@ export class SVN {
);
}

return await spawnProcess(`${svnExecutablePath} ${command}`);
return await spawnProcess(`${svnExecutablePath} ${command}`, { cwd });
} catch (err: any) {
if (typeof err === "string") {
if (err.includes("E155007")) {
Expand All @@ -40,10 +44,13 @@ export class SVN {
async blameFile(fileName: string): Promise<Blame[]> {
this.logger.debug("Running blame child process");
try {
const data = await this.command(
`blame --xml -x "-w --ignore-eol-style" "${fileName}"`,
const dir = dirname(fileName);
const file = basename(fileName);

const data = await this.command(`blame --xml -x "-w --ignore-eol-style" "${file}"`, {
cwd: dir,
fileName,
);
});

this.logger.debug("Blame child process successful");

Expand All @@ -56,7 +63,13 @@ export class SVN {

async getLogForRevision(fileName: string, revision: string) {
try {
const data = await this.command(`log --xml -r ${revision} "${fileName}"`, fileName);
const dir = dirname(fileName);
const file = basename(fileName);

const data = await this.command(`log --xml -r ${revision} "${file}"`, {
cwd: dir,
fileName,
});
return mapLogOutputToMessage(data);
} catch (err: any) {
this.logger.error("Failed to get revision log", { err });
Expand Down
9 changes: 6 additions & 3 deletions src/util/spawn-process.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { spawn } from "node:child_process";
import { spawn, SpawnOptionsWithoutStdio } from "node:child_process";

export const spawnProcess = (script: string): Promise<string> => {
export const spawnProcess = (
script: string,
options?: SpawnOptionsWithoutStdio,
): Promise<string> => {
return new Promise((resolve, reject) => {
const child = spawn(script, { shell: true });
const child = spawn(script, { ...options, shell: true });

let data = "";
let err = "";
Expand Down

0 comments on commit 9fd22da

Please sign in to comment.