Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use -r to tell xargs not to run if empty input #27931

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions bin/plugin/commands/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const fs = require( 'fs' );
const semver = require( 'semver' );
const Octokit = require( '@octokit/rest' );
const { sprintf } = require( 'sprintf-js' );
const os = require( 'os' );

/**
* Internal dependencies
Expand Down Expand Up @@ -519,27 +518,13 @@ async function runUpdateTrunkContentStep(
newReadmeFileContent.replace( STABLE_TAG_PLACEHOLDER, stableTag )
);

let xargsOpts = '';
if ( os.platform === 'linux' ) {
// When xargs receives no arguments, it behaves differently in macOS and linux:
// - macOS: doesn't run
// - linux: run without arguments
//
// In linux, the -r option teaches xargs not to run if it receives no arguments.
xargsOpts = '-r';
}

// Commit the content changes
runShellScript(
"svn st | grep '^?' | awk '{print $2}' | xargs " +
xargsOpts +
' svn add',
"svn st | grep '^?' | awk '{print $2}' | xargs -r svn add",
svnWorkingDirectoryPath
);
runShellScript(
"svn st | grep '^!' | awk '{print $2}' | xargs " +
xargsOpts +
' svn rm',
"svn st | grep '^!' | awk '{print $2}' | xargs -r svn rm",
svnWorkingDirectoryPath
);
await askForConfirmation(
Expand Down
4 changes: 2 additions & 2 deletions docs/contributors/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ You'll need to use Subversion to publish the plugin to WordPress.org.
6. Add new files/remove deleted files from the repository:
```bash
# Add new files:
svn st | grep '^\?' | awk '{print $2}' | xargs svn add # add the -r option to xargs if you use a linux-based OS
svn st | grep '^\?' | awk '{print $2}' | xargs -r svn add
# Delete old files:
svn st | grep '^!' | awk '{print $2}' | xargs svn rm # add the -r option to xargs if you use a linux-based OS
svn st | grep '^!' | awk '{print $2}' | xargs -r svn rm
```
7. Commit the new version:
```bash
Expand Down