Skip to content

Commit

Permalink
feat: implement sapling source control provider
Browse files Browse the repository at this point in the history
Summary:

You can now use conventional tools in a sapling repo (maybe).

Test Plan:

This has not really been tested yet, but the code is there. This is very much a
WIP, the users will be using this at their own risk.
  • Loading branch information
AdeAttwood committed May 29, 2024
1 parent efce8f6 commit cb2ae2b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/source-control/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import git from './git';
import sapling from './sapling';

export interface SourceControlProvider {
/**
Expand All @@ -11,9 +12,13 @@ export interface SourceControlProvider {
* are not currently on one.
*/
getBranchName(): Promise<string | null>;
/**
* Get the current root directory of for the repository.
*/
root(): Promise<string>;
}

const PROVIDERS = [git];
const PROVIDERS = [git, sapling];

export async function getSourceControlProvider(): Promise<
SourceControlProvider | undefined
Expand Down
25 changes: 25 additions & 0 deletions src/lib/source-control/sapling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {run} from '../exec';
import type {SourceControlProvider} from '.';

const sapling: SourceControlProvider = {
isEnabled: async () => {
const isSapling = await run(`sl root`);
return isSapling.code === 0;
},

getBranchName: async () => {
const {stdout} = await run(`sl log -r '.' -T"{bookmarks}"`);
if (!stdout.trim()) {
return null;
}

return stdout.trim();
},

root: async () => {
const {stdout} = await run(`sl root`);
return stdout.trim();
},
};

export default sapling;
2 changes: 2 additions & 0 deletions tests/commands/commitgen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('command/commitgen', () => {
async () => ({
isEnabled: async () => true,
getBranchName: async () => `${type}/123`,
root: async () => '/',
}),
);

Expand Down Expand Up @@ -79,6 +80,7 @@ describe('command/commitgen', () => {
async () => ({
isEnabled: async () => true,
getBranchName: async () => `feat/123`,
root: async () => '/',
}),
);

Expand Down

0 comments on commit cb2ae2b

Please sign in to comment.