Skip to content

Commit

Permalink
Renamed standard branches to base branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jul 15, 2019
1 parent 1e21991 commit e5cd291
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mgit2 is designed to work with [yarn workspaces](https://yarnpkg.com/lang/en/doc
1. [The `dependencies` option](#the-dependencies-option)
1. [Recursive cloning](#recursive-cloning)
1. [Cloning repositories on CI servers](#cloning-repositories-on-ci-servers)
1. [Standard/core branches](#standardcore-branches)
1. [Base branches](#base-branches)
1. [Commands](#commands)
1. [`sync`](#sync)
1. [`pull`](#pull)
Expand Down Expand Up @@ -210,23 +210,25 @@ mgit --resolver-url-template="https://github.com/\${ path }.git"

You can also use full HTTPS URLs to configure `dependencies` in your `mgit.json`.

### Standard/core branches
### Base branches

When you call `mgit sync` or `mgit co` it uses the `master` branch in every repository, unless the repository's branch is defined in `mgit.json`.
When you call `mgit sync` or `mgit co`, mgit will use the following algorithm to determine the branch to which each repository should be checked out:

If you support only the one main/core branch in your projects, it isn't a problem. But if you have more than one, on every single branch you need modify branches for dependencies in `mgit.json`.
1. If a branch is defined in `mgit.json`, use it. A branch can be defined after `#` in a repository URL. For example: `"@cksource/foo": "cksource/foo#dev"`.
2. If the root repository (assuming, it is a repository) is on one of the "base branches", use that branch name.
3. Otherwise, use `master`.

In order to simplify the flow, we introduced the standard/core branches option. It uses the current branch of the main repository in all cases where the branch is not defined in `mgit.json`.
You can define the base branches as follows:

```json
{
...
"standardBranches": [ "master", "stable" ],
"baseBranches": [ "master", "stable" ],
...
}
```

[Read more about the feature.](https://github.com/cksource/mgit2/issues/103)
With this configuration, if the root repository is on `stable`, calling `mgit co` will check out all repositories to `stable`. If you change the branch of the root repository to `master` and call `mgit co`, all sub repositories will be checked out to `master`.

## Commands

Expand Down
2 changes: 1 addition & 1 deletion lib/default-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function resolver( packageName, options ) {
const repository = parseRepositoryUrl( repositoryUrl, {
urlTemplate: options.resolverUrlTemplate,
defaultBranch: options.resolverDefaultBranch,
standardBranches: options.standardBranches,
baseBranches: options.baseBranches,
cwdPackageBranch: options.cwdPackageBranch,
} );

Expand Down
6 changes: 3 additions & 3 deletions lib/utils/getoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function cwdResolver( callOptions, cwd ) {
scope: null,
packagesPrefix: [],
overrideDirectoryNames: {},
standardBranches: []
baseBranches: []
};

if ( fs.existsSync( mgitJsonPath ) ) {
Expand Down Expand Up @@ -95,9 +95,9 @@ module.exports = function cwdResolver( callOptions, cwd ) {
* @property {String|Array.<String>} [packagesPrefix=[]] Prefix or prefixes which will be removed from packages' names during
* printing the summary of the "status" command.
*
* @property {Array.<String>} [standardBranches=[]] Name of branches that are allowed to check out (based on a branch in main repository)
* @property {Array.<String>} [baseBranches=[]] Name of branches that are allowed to check out (based on a branch in main repository)
* if specified package does not have defined a branch.
*
* @property {String} [cwdPackageBranch] If the main repository is a git repository, this variable keeps
* a name of a current branch of the repository. The value is required for `standardBranches` option.
* a name of a current branch of the repository. The value is required for `baseBranches` option.
*/
8 changes: 4 additions & 4 deletions lib/utils/parserepositoryurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const url = require( 'url' );
* Used if `repositoryUrl` defines only `'<organization>/<repositoryName>'`.
* @param {String} [options.defaultBranch='master'] The default branch name to be used if the
* repository URL doesn't specify it.
* @param {Array.<String>>} [options.standardBranches=[]] Name of branches that are allowed to check out
* @param {Array.<String>>} [options.baseBranches=[]] Name of branches that are allowed to check out
* based on the value specified as `options.cwdPackageBranch`.
* @param {String} [options.cwdPackageBranch] A name of a branch that the main repository is checked out.
* @returns {Repository}
Expand All @@ -26,7 +26,7 @@ module.exports = function parseRepositoryUrl( repositoryUrl, options = {} ) {
const parsedUrl = url.parse( repositoryUrl );
const branch = getBranch( parsedUrl, {
defaultBranch: options.defaultBranch,
standardBranches: options.standardBranches || [],
baseBranches: options.baseBranches || [],
cwdPackageBranch: options.cwdPackageBranch,
} );

Expand Down Expand Up @@ -57,8 +57,8 @@ function getBranch( parsedUrl, options ) {
return parsedUrl.hash.slice( 1 );
}

// Check if the main repo is on one of standard branches. If yes, use that branch.
if ( options.cwdPackageBranch && options.standardBranches.includes( options.cwdPackageBranch ) ) {
// Check if the main repo is on one of base branches. If yes, use that branch.
if ( options.cwdPackageBranch && options.baseBranches.includes( options.cwdPackageBranch ) ) {
return options.cwdPackageBranch;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/utils/getoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe( 'utils', () => {
overrideDirectoryNames: {
'override-directory': 'custom-directory'
},
standardBranches: []
baseBranches: []
} );
} );

Expand All @@ -64,7 +64,7 @@ describe( 'utils', () => {
ignore: null,
packagesPrefix: [],
overrideDirectoryNames: {},
standardBranches: []
baseBranches: []
} );
} );

Expand All @@ -86,7 +86,7 @@ describe( 'utils', () => {
ignore: null,
packagesPrefix: [],
overrideDirectoryNames: {},
standardBranches: []
baseBranches: []
} );
} );

Expand All @@ -111,7 +111,7 @@ describe( 'utils', () => {
ignore: null,
packagesPrefix: [],
overrideDirectoryNames: {},
standardBranches: []
baseBranches: []
} );
} );

Expand Down Expand Up @@ -139,7 +139,7 @@ describe( 'utils', () => {
overrideDirectoryNames: {
'override-directory': 'custom-directory'
},
standardBranches: []
baseBranches: []
} );
} );

Expand Down Expand Up @@ -171,7 +171,7 @@ describe( 'utils', () => {
overrideDirectoryNames: {
'override-directory': 'custom-directory'
},
standardBranches: [],
baseBranches: [],
cwdPackageBranch: 'master'
} );

Expand Down
22 changes: 11 additions & 11 deletions tests/utils/parserepositoryurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ describe( 'utils', () => {
} );
} );

describe( 'standardBranches support (ticket: #103)', () => {
it( 'returns default branch name if standard branches is not specified', () => {
describe( 'baseBranches support (ticket: #103)', () => {
it( 'returns default branch name if base branches is not specified', () => {
const repository = parseRepositoryUrl( 'foo/bar', {
urlTemplate: 'https://github.com/${ path }.git',
defaultBranch: 'develop',
Expand All @@ -137,7 +137,7 @@ describe( 'utils', () => {
} );
} );

it( 'returns "master" as default branch if standard branches and default branch are not specified', () => {
it( 'returns "master" as default branch if base branches and default branch are not specified', () => {
const repository = parseRepositoryUrl( 'foo/bar', {
urlTemplate: 'https://github.com/${ path }.git',
cwdPackageBranch: 'master'
Expand All @@ -150,11 +150,11 @@ describe( 'utils', () => {
} );
} );

it( 'returns default branch name if standard branches is an empty array', () => {
it( 'returns default branch name if base branches is an empty array', () => {
const repository = parseRepositoryUrl( 'foo/bar', {
urlTemplate: 'https://github.com/${ path }.git',
defaultBranch: 'develop',
standardBranches: [],
baseBranches: [],
cwdPackageBranch: 'master'
} );

Expand All @@ -165,11 +165,11 @@ describe( 'utils', () => {
} );
} );

it( 'returns default branch name if the main repo is not whitelisted in "standardBranches" array', () => {
it( 'returns default branch name if the main repo is not whitelisted in "baseBranches" array', () => {
const repository = parseRepositoryUrl( 'foo/bar', {
urlTemplate: 'https://github.com/${ path }.git',
defaultBranch: 'develop',
standardBranches: [ 'stable' ],
baseBranches: [ 'stable' ],
cwdPackageBranch: 'master'
} );

Expand All @@ -184,7 +184,7 @@ describe( 'utils', () => {
const repository = parseRepositoryUrl( 'foo/bar', {
urlTemplate: 'https://github.com/${ path }.git',
defaultBranch: 'develop',
standardBranches: [ 'stable', 'master' ],
baseBranches: [ 'stable', 'master' ],
cwdPackageBranch: 'stable'
} );

Expand All @@ -199,7 +199,7 @@ describe( 'utils', () => {
const repository = parseRepositoryUrl( 'foo/bar#mgit', {
urlTemplate: 'https://github.com/${ path }.git',
defaultBranch: 'develop',
standardBranches: [ 'stable' ],
baseBranches: [ 'stable' ],
cwdPackageBranch: 'master'
} );

Expand All @@ -210,11 +210,11 @@ describe( 'utils', () => {
} );
} );

it( 'ignores options if a branch is specified in the repository URL ("standardBranches" contains "cwdPackageBranch")', () => {
it( 'ignores options if a branch is specified in the repository URL ("baseBranches" contains "cwdPackageBranch")', () => {
const repository = parseRepositoryUrl( 'foo/bar#mgit', {
urlTemplate: 'https://github.com/${ path }.git',
defaultBranch: 'develop',
standardBranches: [ 'master' ],
baseBranches: [ 'master' ],
cwdPackageBranch: 'master'
} );

Expand Down

0 comments on commit e5cd291

Please sign in to comment.