Skip to content

Commit

Permalink
add continue command (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Opeyem1a authored Oct 27, 2024
1 parent 558f01e commit 8bdd31a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
8 changes: 4 additions & 4 deletions VISION.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ branches are stacked on which branches.

This is now v0.

5. Build `branch attach`
6. Build `continue`
5. Build `branch attach` (Scope creep) - `branch delete` & `branch switch`
6. Build `continue`

This is now v0.1.X

Expand All @@ -93,10 +93,10 @@ This is now v0.1.X
This is v0.2.X

11. Build GitHub integration to make/track PRs
12. Build `branch submit`
12. Build `branch submit`

This is v0.3.X

13. Build `sync`
13. Build `sync` 🟠

This is v1.
5 changes: 5 additions & 0 deletions src/command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ChangesAdd, { changesAddConfig } from './commands/changes/add.js';
import ChangesCommit, {
changesCommitConfig,
} from './commands/changes/commit.js';
import Continue, { continueConfig } from './commands/continue.js';
import Help, { helpConfig } from './commands/help.js';
import Hop, { hopConfig } from './commands/hop.js';
import Sync, { syncConfig } from './commands/sync.js';
Expand Down Expand Up @@ -31,6 +32,10 @@ export const REGISTERED_COMMANDS: CommandGroup = {
component: List,
config: listConfig,
},
continue: {
component: Continue,
config: continueConfig,
},
changes: {
_group: {
alias: 'c',
Expand Down
67 changes: 67 additions & 0 deletions src/commands/continue.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import ErrorDisplay from '../components/error-display.js';
import React, { useCallback, useState } from 'react';
import { Action, useAction } from '../hooks/use-action.js';
import { CommandConfig, CommandProps } from '../types.js';
import { Loading } from '../components/loading.js';
import { Text } from 'ink';
import { useGit } from '../hooks/use-git.js';

const Continue = (_: CommandProps) => {

Check warning on line 9 in src/commands/continue.tsx

View workflow job for this annotation

GitHub Actions / lint_test

'_' is defined but never used
const result = useRebaseContinue();

if (result.isError) {
return <ErrorDisplay error={result.error} />;
}

if (result.isLoading) {
return <Loading />;
}

if (!result.isRebaseInProgress) {
return <Text color="yellow">No ongoing rebase found.</Text>;
}

return null;
};

type UseRebaseContinueResult = Action & {
isRebaseInProgress: boolean;
};
const useRebaseContinue = (): UseRebaseContinueResult => {
const git = useGit();
// assume a rebase is in action when this is called until proven otherwise
const [isRebaseInProgress, setIsRebaseInProgress] = useState(true);

const performAction = useCallback(async () => {
const isRebasing = await git.isRebasing();
if (!isRebasing) {
setIsRebaseInProgress(false);
return;
}

await git.rebaseContinue();
}, [git]);

const action = useAction({
asyncAction: performAction,
});

return {
...action,
isRebaseInProgress,
} as UseRebaseContinueResult;
};

export const continueConfig: CommandConfig = {
description: 'Continues a rebase',
usage: 'continue',
key: 'continue',
getProps: () => {
return {
valid: true,
props: {},
};
},
};

export default Continue;
4 changes: 2 additions & 2 deletions src/components/rebase-conflict.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export const RebaseConflict = () => {
1. Please resolve the conflict before proceeding
</Text>
<Text color="yellow">
2. Add all files with <Text color="cyan">git add .</Text>
2. Add all files with <Text color="cyan">gum changes add</Text>
</Text>
<Text color="yellow">
3. Continue the rebase with{' '}
<Text color="cyan">git rebase --continue</Text>
<Text color="cyan">gum continue</Text>
</Text>
</Box>
);
Expand Down
4 changes: 4 additions & 0 deletions src/services/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface GitService {
ontoBranch: string;
}) => Promise<void>;
isRebasing: () => Promise<boolean>;
rebaseContinue: () => Promise<void>;
}

export const createGitService = ({
Expand Down Expand Up @@ -77,5 +78,8 @@ export const createGitService = ({
return false;
}
},
rebaseContinue: async () => {
await gitEngine.rebase(['--continue']);
},
};
};

0 comments on commit 8bdd31a

Please sign in to comment.