Skip to content

hardis:work:resetselection

Description

Command Behavior

Resets the local Git repository to allow for a new selection of files to be included in a merge request.

This command is designed to be used when you need to re-evaluate which changes should be part of your next merge request. It performs a soft Git reset, effectively unstaging all committed changes since the last merge with the target branch, and then cleans up any generated files.

Key functionalities:

  • Target Branch Selection: Prompts you to select the target branch of your current or future merge request.
  • Soft Git Reset: Performs a git reset --soft operation to uncommit changes, moving the HEAD pointer back but keeping the changes in your working directory.
  • Generated File Cleanup: Resets and checks out manifest/package.xml and manifest/destructiveChanges.xml to their state before the reset, ensuring a clean slate for new selections.
  • Force Push Authorization: Sets a flag in your user configuration (canForcePush: true) to allow a force push in the subsequent hardis:work:save command, as the history will have been rewritten.
Technical explanations

The command's technical implementation involves:

  • Git Integration: Uses simple-git (git()) to interact with the Git repository:
    • git().branch(): Retrieves information about local and remote branches.
    • git().log(): Fetches the commit history to determine which commits to reset.
    • git().reset(): Performs the soft reset operation.
    • git().checkout(): Resets specific files (package.xml, destructiveChanges.xml) to their previous state.
    • git().status(): Displays the current status of the Git repository after the reset.
  • Interactive Prompts: Uses the prompts library to confirm the reset operation with the user and to select the target branch.
  • Configuration Management: Updates the user's configuration (.sfdx-hardis.yml) using setConfig to set the canForcePush flag.
  • Error Handling: Includes a check to prevent resetting protected branches.

Agent Mode

Supports non-interactive execution with --agent:

sf hardis:work:resetselection --agent --target-org myorg@example.com

In agent mode:

  • The confirmation prompt is skipped and the reset proceeds automatically.
  • The target branch is selected automatically from the project configuration.

Learn by doing

The free Salesforce DevOps with sfdx-hardis course runs this command, click by click, on an org of your own:

Screenshots

Confirm the soft reset of the User Story branch

Confirm the soft reset of the User Story branch

The three commits of the User Story reset softly, so the files can be selected and committed again

The three commits of the User Story reset softly, so the files can be selected and committed again

Parameters

Name Type Description Default Required Options
agent boolean Run in non-interactive mode for agents and automation
debug
-d
boolean Activate debug mode (more logs)
flags-dir option Import flag values from a directory.
json boolean Format output as json.
skipauth boolean Skip authentication check when a default username is required
target-org
-o
option Username or alias of the target org. Not required if the target-org configuration variable is already set. true
websocket option Websocket host:port for VsCode SFDX Hardis UI integration

Examples

$ sf hardis:work:resetsave
$ sf hardis:work:resetselection --agent

Comments