Skip to content

Commit

Permalink
Remove explicit git branch fallbacks for wp-env and update readme (#4…
Browse files Browse the repository at this point in the history
…1043)

* Instead of trying to name a fallback branch if none is passed, instead rely on the default git behavior of using the repos default branch.

Co-authored-by: Glen Davies <glen.davies@a8c.com>
  • Loading branch information
glendaviesnz and Glen Davies authored May 19, 2022
1 parent 5623107 commit cef2807
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Several types of strings can be passed into the `core`, `plugins`, `themes`, and
| ----------------- | -------------------------------------------- | -------------------------------------------------------- |
| Relative path | `.<path>\|~<path>` | `"./a/directory"`, `"../a/directory"`, `"~/a/directory"` |
| Absolute path | `/<path>\|<letter>:\<path>` | `"/a/directory"`, `"C:\\a\\directory"` |
| GitHub repository | `<owner>/<repo>[#<ref>]` | `"WordPress/WordPress"`, `"WordPress/gutenberg#trunk"` |
| GitHub repository | `<owner>/<repo>[#<ref>]` | `"WordPress/WordPress"`, `"WordPress/gutenberg#trunk"`, if no branch is provided wp-env will fall back to the repos default branch |
| SSH repository | `ssh://user@host/<owner>/<repo>.git[#<ref>]` | `"ssh://git@github.com/WordPress/WordPress.git"` |
| ZIP File | `http[s]://<host>/<path>.zip` | `"https://wordpress.org/wordpress-5.4-beta2.zip"` |
Expand Down
5 changes: 3 additions & 2 deletions packages/env/lib/config/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function parseSourceString( sourceString, { workDirectoryPath } ) {
return {
type: 'git',
url: sshUrl.href.split( '#' )[ 0 ],
ref: sshUrl.hash.slice( 1 ) || 'master',
ref: sshUrl.hash.slice( 1 ) || undefined,
path: workingPath,
clonePath: workingPath,
basename,
Expand All @@ -144,11 +144,12 @@ function parseSourceString( sourceString, { workDirectoryPath } ) {
const gitHubFields = sourceString.match(
/^([^\/]+)\/([^#\/]+)(\/([^#]+))?(?:#(.+))?$/
);

if ( gitHubFields ) {
return {
type: 'git',
url: `https://github.com/${ gitHubFields[ 1 ] }/${ gitHubFields[ 2 ] }.git`,
ref: gitHubFields[ 5 ] || 'master',
ref: gitHubFields[ 5 ],
path: path.resolve(
workDirectoryPath,
gitHubFields[ 2 ],
Expand Down
2 changes: 1 addition & 1 deletion packages/env/lib/config/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ describe( 'readConfig', () => {
{
type: 'git',
url: 'https://github.com/WordPress/gutenberg.git',
ref: 'master',
ref: undefined,
path: expect.stringMatching( /^(\/||\\).*gutenberg$/ ),
basename: 'gutenberg',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/env/test/parse-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const gitTests = [
{
sourceString: 'ssh://git@github.com/short.git',
url: 'ssh://git@github.com/short.git',
ref: 'master',
ref: undefined,
path: currentDirectory + '/short',
clonePath: currentDirectory + '/short',
basename: 'short',
},
{
sourceString: 'ssh://git@github.com/owner/long/path/repo.git',
url: 'ssh://git@github.com/owner/long/path/repo.git',
ref: 'master',
ref: undefined,
path: currentDirectory + '/owner/long/path/repo',
clonePath: currentDirectory + '/owner/long/path/repo',
basename: 'repo',
Expand Down

0 comments on commit cef2807

Please sign in to comment.