Skip to content

Commit

Permalink
#139: run hg move when files are renamed (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
incidentist authored Jan 3, 2022
1 parent bb3b2b8 commit 40365da
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
File renamed without changes.
14 changes: 13 additions & 1 deletion src/hg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
asciiOnly,
writeStringToTempFile,
} from "./util";
import { EventEmitter, Event, workspace, Disposable } from "vscode";
import { EventEmitter, Event, workspace, Disposable, Uri } from "vscode";
import { HgCommandServer } from "./hgserve";

const isWindows = os.platform() === "win32";
Expand Down Expand Up @@ -66,6 +66,10 @@ export interface UnshelveOptions {
keep?: boolean;
}

export interface MoveOptions {
after: boolean;
}

export interface PurgeOptions {
paths?: string[];
all?: boolean;
Expand Down Expand Up @@ -1158,6 +1162,14 @@ export class Repository {
]);
}

async move(src: Uri, dest: Uri, opts: MoveOptions): Promise<void> {
const args = ["move", src.path, dest.path];
if (opts.after) {
args.push("--after");
}
await this.run(args);
}

async tryGetLastCommitDetails(): Promise<ICommitDetails> {
try {
return {
Expand Down
25 changes: 25 additions & 0 deletions src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
workspace,
commands,
QuickDiffProvider,
FileRenameEvent,
} from "vscode";
import {
Repository as BaseRepository,
Expand All @@ -35,6 +36,7 @@ import {
UnshelveOptions,
GetRefsOptions,
RefType,
MoveOptions,
} from "./hg";
import {
anyEvent,
Expand Down Expand Up @@ -279,6 +281,7 @@ export const enum Operation {
Unresolve = "Unresolve",
Forget = "Forget",
Merge = "Merge",
Move = "Move",
AddRemove = "AddRemove",
SetBookmark = "SetBookmark",
RemoveBookmark = "RemoveBookmark",
Expand Down Expand Up @@ -592,6 +595,10 @@ export class Repository implements IDisposable, QuickDiffProvider {
);
onHgrcChange(this.onHgrcChange, this, this.disposables);

this.disposables.push(
workspace.onDidRenameFiles(this.onFileRename, this)
);

this._sourceControl = scm.createSourceControl(
"hg",
"Hg",
Expand Down Expand Up @@ -900,6 +907,7 @@ export class Repository implements IDisposable, QuickDiffProvider {
case Status.DELETED:
case Status.MISSING:
case Status.MODIFIED:
case Status.RENAMED:
default:
toRevert.push(this.mapResourceToRepoRelativePath(r));
break;
Expand Down Expand Up @@ -1391,6 +1399,19 @@ export class Repository implements IDisposable, QuickDiffProvider {
});
}

async move(
files: readonly { oldUri: Uri; newUri: Uri }[],
options: MoveOptions
): Promise<void> {
return await this.run(Operation.Move, async () => {
Promise.all(
files.map(({ oldUri, newUri }) => {
this.repository.move(oldUri, newUri, options);
})
);
});
}

async showAsStream(ref: string, filePath: string): Promise<Buffer> {
return this.run(Operation.Show, () => {
const relativePath = path
Expand Down Expand Up @@ -1472,6 +1493,10 @@ export class Repository implements IDisposable, QuickDiffProvider {
}
}

private async onFileRename(e: FileRenameEvent) {
return this.move(e.files, { after: true });
}

@throttle
public async getPaths(): Promise<Path[]> {
try {
Expand Down

0 comments on commit 40365da

Please sign in to comment.