Skip to content

Commit 88898d7

Browse files
authored
fix(reset): default to all components when no pattern provided (#10109)
The `bit reset` command previously required either a component pattern or the `--all` flag. This was confusing because: - `--all` means "all components" (not "all versions") - But the default behavior already resets all local versions of each component This change aligns `bit reset` with `bit tag` behavior - running without arguments now defaults to all components, with a confirmation prompt for safety.
1 parent e00b706 commit 88898d7

File tree

4 files changed

+23
-56
lines changed

4 files changed

+23
-56
lines changed

components/legacy/e2e-helper/e2e-command-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export default class CommandHelper {
519519
return this.runCmd(`bit reset ${id} ${head ? '--head' : ''} ${flag}`);
520520
}
521521
resetAll(options = '') {
522-
return this.runCmd(`bit reset ${options} --all`);
522+
return this.runCmd(`bit reset ${options} --silent`);
523523
}
524524
resetSoft(id: string) {
525525
return this.runCmd(`bit reset ${id} --soft`);

gilad-import-fork.diff

Lines changed: 0 additions & 45 deletions
This file was deleted.

scopes/component/snapping/reset-cmd.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BitError } from '@teambit/bit-error';
22
import chalk from 'chalk';
3+
import yesno from 'yesno';
34
import type { Command, CommandOptions } from '@teambit/cli';
45
import { COMPONENT_PATTERN_HELP } from '@teambit/legacy.constants';
56
import type { SnappingMain } from './snapping.main.runtime';
@@ -15,11 +16,12 @@ export default class ResetCmd implements Command {
1516
];
1617
group = 'version-control';
1718
extendedDescription = `removes local component versions (tags/snaps) that haven't been exported yet.
18-
by default reverts all local versions. use --head to revert only the latest version.
19+
if no component-pattern is provided, resets all components (with confirmation prompt).
20+
by default reverts all local versions of each component. use --head to revert only the latest version.
1921
useful for undoing mistakes before exporting. exported versions cannot be reset.`;
2022
alias = '';
2123
options = [
22-
['a', 'all', 'revert all unexported tags/snaps for all components'],
24+
['a', 'all', 'DEPRECATED. this is now the default behavior when no component-pattern is provided'],
2325
['', 'head', 'revert the head tag/snap only (by default, all local tags/snaps are reverted)'],
2426
['', 'soft', 'revert only soft-tags (components tagged with --soft flag)'],
2527
[
@@ -28,6 +30,7 @@ useful for undoing mistakes before exporting. exported versions cannot be reset.
2830
"revert the tag even if it's used as a dependency. WARNING: components that depend on this tag will be corrupted",
2931
],
3032
['', 'never-exported', 'reset only components that were never exported'],
33+
['s', 'silent', 'skip confirmation when resetting all components'],
3134
] as CommandOptions;
3235
loader = true;
3336

@@ -40,22 +43,21 @@ useful for undoing mistakes before exporting. exported versions cannot be reset.
4043
head = false,
4144
force = false,
4245
soft = false,
46+
silent = false,
4347
neverExported = false,
44-
}: { all?: boolean; head?: boolean; force?: boolean; soft?: boolean; neverExported?: boolean }
48+
}: { all?: boolean; head?: boolean; force?: boolean; soft?: boolean; silent?: boolean; neverExported?: boolean }
4549
) {
4650
if (neverExported) {
4751
const compIds = await this.snapping.resetNeverExported();
4852
return chalk.green(`successfully reset the following never-exported components:\n${compIds.join('\n')}`);
4953
}
50-
if (!pattern && !all) {
51-
throw new BitError('please specify a component-pattern or use --all flag');
52-
}
53-
if (pattern && all) {
54-
throw new BitError('please specify either a component-pattern or --all flag, not both');
55-
}
5654
if (soft && head) {
5755
throw new BitError('please specify either --soft or --head flag, not both');
5856
}
57+
// if no pattern provided, reset all components (with confirmation unless --silent or --all)
58+
if (!pattern && !silent && !all) {
59+
await this.promptForResetAll();
60+
}
5961
const { results, isSoftUntag } = await this.snapping.reset(pattern, head, force, soft);
6062
const titleSuffix = isSoftUntag ? 'soft-untagged (are not candidates for tagging any more)' : 'reset';
6163
const title = chalk.green(`${results.length} component(s) were ${titleSuffix}:\n`);
@@ -64,4 +66,14 @@ useful for undoing mistakes before exporting. exported versions cannot be reset.
6466
});
6567
return title + components.join('\n');
6668
}
69+
70+
private async promptForResetAll() {
71+
this.snapping.logger.clearStatusLine();
72+
const ok = await yesno({
73+
question: `${chalk.bold('This will reset all local tags/snaps for all components. Would you like to proceed? [yes(y)/no(n)]')}`,
74+
});
75+
if (!ok) {
76+
throw new BitError('the operation has been canceled');
77+
}
78+
}
6779
}

scopes/component/snapping/snap-cmd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function snapResultOutput(results: SnapResults): string {
161161

162162
const warningsOutput = warnings && warnings.length ? `${chalk.yellow(warnings.join('\n'))}\n\n` : '';
163163
const snapExplanation = `\n(use "bit export" to push these components to a remote")
164-
(use "bit reset --all" to unstage all local versions, or "bit reset --head" to only unstage the latest local snap)`;
164+
(use "bit reset" to unstage all local versions, or "bit reset --head" to only unstage the latest local snap)`;
165165

166166
const compInBold = (id: ComponentID) => {
167167
const version = id.hasVersion() ? `@${id.version}` : '';

0 commit comments

Comments
 (0)