Skip to content

Commit

Permalink
fix: use remote names to push and pull
Browse files Browse the repository at this point in the history
using uri caused fossil to not use saved authentication
  • Loading branch information
senyai committed Sep 26, 2023
1 parent 9c83560 commit 4bec61e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,9 @@ export class CommandCenter {
if (!remotes.length) {
return interaction.warnNoRemotes();
}
const uri = await interaction.pickRemote(remotes, 'pull from');
if (uri) {
await repository.pull(uri);
const name = await interaction.pickRemote(remotes, 'pull from');
if (name) {
await repository.pull(name);
}
}

Expand Down Expand Up @@ -1252,9 +1252,9 @@ export class CommandCenter {
if (!remotes.length) {
return interaction.warnNoRemotes();
}
const uri = await interaction.pickRemote(remotes, 'push to');
if (uri) {
await repository.push(uri);
const name = await interaction.pickRemote(remotes, 'push to');
if (name) {
await repository.push(name);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
RelativePath,
StashID,
FossilRemote,
FossilRemoteName,
} from './openedRepository';
import * as humanise from './humanise';
import { Repository, LogEntriesOptions } from './repository';
Expand Down Expand Up @@ -970,13 +971,14 @@ interface RemoteQuickPickItem extends QuickPickItem {
export async function pickRemote(
remotes: FossilRemote[],
what: 'push to' | 'pull from'
): Promise<FossilURI | undefined> {
): Promise<FossilRemoteName | undefined> {
if (remotes.length == 1) {
return remotes[0].uri;
return remotes[0].name;
}
const picks = remotes.map(
(remote): RemoteQuickPickItem => ({
(remote): RemoteQuickPickItem & { name: FossilRemoteName } => ({
label: `$(link) ${remote.name}`,
name: remote.name,
detail: remote.uri.toString(),
uri: remote.uri,
})
Expand All @@ -986,7 +988,7 @@ export async function pickRemote(
placeHolder,
matchOnDetail: true,
});
return choice?.uri;
return choice?.name;
}

export function warnUnsavedChanges(msg: string): void {
Expand Down
8 changes: 4 additions & 4 deletions src/openedRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,12 @@ export class OpenedRepository {
return match[2] as FossilUndoCommand;
}

async pull(uri: Uri): Promise<void> {
await this.exec(['pull', uri.toString()]);
async pull(name: FossilRemoteName): Promise<void> {
await this.exec(['pull', name]);
}

async push(uri: FossilURI | undefined): Promise<void> {
await this.exec(['push', ...(uri ? [uri.toString()] : [])]);
async push(name: FossilRemoteName | undefined): Promise<void> {
await this.exec(['push', ...(name ? [name] : [])]);
}

async merge(
Expand Down
10 changes: 5 additions & 5 deletions src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
MergeAction,
FossilHash,
FossilRemote,
FossilURI,
FossilUndoCommand,
FossilCommitMessage,
StashItem,
Expand All @@ -41,6 +40,7 @@ import {
AnyPath,
UserPath,
StashID,
FossilRemoteName,
} from './openedRepository';
import {
anyEvent,
Expand Down Expand Up @@ -827,16 +827,16 @@ export class Repository implements IDisposable, InteractionAPI {
}

@throttle
async pull(uri: FossilURI): Promise<void> {
async pull(name: FossilRemoteName): Promise<void> {
return this.runWithProgress(Operation.Pull, async () => {
await this.repository.pull(uri);
await this.repository.pull(name);
});
}

@throttle
async push(uri?: FossilURI): Promise<void> {
async push(name?: FossilRemoteName): Promise<void> {
return this.runWithProgress(Operation.Push, async () => {
await this.repository.push(uri);
await this.repository.push(name);
});
}

Expand Down
12 changes: 3 additions & 9 deletions src/test/suite/stateSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ function PullAndPushSuite(this: Suite): void {
await commands.executeCommand('fossil.pull');
sinon.assert.calledOnce(listCall);
sinon.assert.notCalled(sem);
sinon.assert.calledOnceWithExactly(pullCall, [
'pull',
'https://example.com/',
]);
sinon.assert.calledOnceWithExactly(pullCall, ['pull', 'default']);
});

test('Update', async () => {
Expand Down Expand Up @@ -95,10 +92,7 @@ function PullAndPushSuite(this: Suite): void {

test('PushTo (one remote)', async () => {
const pushCall = await oneRemote('fossil.pushTo');
sinon.assert.calledOnceWithExactly(pushCall, [
'push',
'https://example.com/',
]);
sinon.assert.calledOnceWithExactly(pushCall, ['push', 'default']);
});

test('PushTo (two remotes)', async () => {
Expand All @@ -123,7 +117,7 @@ function PullAndPushSuite(this: Suite): void {
await commands.executeCommand('fossil.pushTo');
sinon.assert.calledOnce(listCall);
sinon.assert.calledOnce(sqp);
sinon.assert.calledOnceWithExactly(pushCall, ['push', 'ssh://fossil']);
sinon.assert.calledOnceWithExactly(pushCall, ['push', 'origin']);
});

test('PushTo (two remotes, do not pick)', async () => {
Expand Down

0 comments on commit 4bec61e

Please sign in to comment.