[rush-lib] Add commit flag to the Change action
Summary
Adds an optional flag to commit the change files, it stages the files in rushConfiguration.changesFolder and commits them with the message Rush changes.
Fixes #2470
Details
I solved the problem by adding a new Flag parameter to the Change action with the long name --commit and short name -c. If this flag is set, Rush invokes git add ${rushConfiguration.changesFolder} and commits the changes with the message Rush changes.
An alternative I considered but was not sure about was extending the Git class to be able to do staging and committing, then just invoking those functions via the _git instance in the ChangeAction class, but since there were other functions invoking git via CLI directly, I figured this was fine.
~~The problem is solved, the only question is whether committing changes that were staged already before the rush change action was run should be done. It does so now.~~
The problem is solved, it commits only files from the changesFolder, has an optional custom commit message in rush.json under gitPolicy.changefilesCommitMessage.
The change does not break backwards compatibility.
The change should not impact performance.
How it was tested
Invoked rush change with both the --commit and -c flags and confirmed that the file was made and committed.
I tested with the custom commit message as well, and it works.
Also @a-mkljajic for you question in the PR description you can make use of _warnUnstagedChanges it already checks if when running rush change user has anything staged. I'd say if flag --commit is set then this check should just throw error, since I don't think this will be cool if we commit random things for the user.
Also @a-mkljajic for you question in the PR description you can make use of
_warnUnstagedChangesit already checks if when runningrush changeuser has anything staged. I'd say if flag--commitis set then this check should just throw error, since I don't think this will be cool if we commit random things for the user.
@ndobryanskyy My latest commit moves to just committing the staged change files, I forgot that you could do that 😄
@iclanton Would adding an optional --commit-message string parameter be useful, or would that make things too cluttered?
Or is there a way to add an optional string parameter to the --commit flag?
I.e. you could run rush change -c and it would commit with the default commit message or the one defined in rush.json and you could run rush change -c "Commit message" and it would commit the changefiles with the "Commit message" message.
I haven't noticed anything in the ts-command-line package that could be used for this 2nd version, but maybe there is.
I think a --commit-message parameter would be useful. Specifying that parameter would presumably imply --commit.
There isn't a way to have a parameter behave both as a flag and as a string parameter.