diff --git a/README.md b/README.md index 8e808ed..6afea61 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Git shortcuts for implementing the scalable git branching model +The Scalable Git Branching Model has recently been updated; see the new +terminology in [A scalable Git branching model, +Revisited](https://dekrey.net/articles/scalable-git-branching-model-revisited/). + ## Prerequisites - Powershell Core (7+) @@ -25,34 +29,34 @@ Note: if you have an older version installed, such as .NET 7, you can [install a Relative paths work, too. To clone and run, you may use the following commands: - git clone https://github.com/PrincipleStudios/scalable-git-branching-tools.git ../scalable-git-branching-tools + git clone https://github.com/DarkPatternsDigital/scalable-git-branching-tools.git ../scalable-git-branching-tools ../scalable-git-branching-tools/init.ps1 ## Commands -[`git tool-update`](./docs/tool-update.md) +[`git tool-update`](./docs/tool-update.md) - Attempts to update these tools -[`git tool-config`](./docs/tool-config.md) +[`git tool-config`](./docs/tool-config.md) - Configures these tools -[`git new`](./docs/new.md) +[`git new`](./docs/new.md) - Create a new branch with tracked dependencies -[`git pull-upstream`](./docs/pull-upstream.md) +[`git pull-deps`](./docs/pull-deps.md) - Pull dependencies into your current branch -[`git show-downstream`](./docs/show-downstream.md) +[`git show-dependants`](./docs/show-dependants.md) - Shows dependants of the current branch -[`git show-upstream`](./docs/show-upstream.md) +[`git show-deps`](./docs/show-deps.md) - Shows dependencies of the current branch -[`git add-upstream`](./docs/add-upstream.md) +[`git add-deps`](./docs/add-deps.md) - Adds one or more dependencies to the current branch -[`git rc`](./docs/rc.md) +[`git rc`](./docs/rc.md) - Creates a release candidate out of one or more dependencies -[`git rebuild-rc`](./docs/rebuild-rc.md) +[`git rebuild-rc`](./docs/rebuild-rc.md) - Recreates a release candidate, modifying its dependencies. -[`git verify-updated`](./docs/verify-updated.md) +[`git verify-updated`](./docs/verify-updated.md) - Verifies if the current branch is up-to-date wit its dependencies -[`git refactor-upstream`](./docs/refactor-upstream.md) +[`git refactor-deps`](./docs/refactor-deps.md) - Rewrites the dependencies tree as directed -[`git release`](./docs/release.md) +[`git release`](./docs/release.md) - Releases and cleans up branches ## Development diff --git a/adr/01-principles.md b/adr/01-principles.md index 94e74a6..93e822b 100644 --- a/adr/01-principles.md +++ b/adr/01-principles.md @@ -66,4 +66,4 @@ Tools should be written with the following in mind: [scalable-git]: https://dekrey.net/articles/scaled-git-flow/ [principle-scalable-git]: https://www.principlestudios.com/article/a-scalable-git-branching-model/ -[principle-tools-branching]: https://principle.tools/branching/ +[principle-tools-branching]: https://principle.tools/branching/ \ No newline at end of file diff --git a/adr/02-code-organization.md b/adr/02-code-organization.md index 4f6a479..b39b10a 100644 --- a/adr/02-code-organization.md +++ b/adr/02-code-organization.md @@ -121,4 +121,4 @@ Under this methodology, the `git new` command would have the basic outline: 5. Finalize actions - `Invoke-FinalizeAction` - A single `git push` would set `_upstream` and create the new branch - - Checkout the new branch + - Checkout the new branch \ No newline at end of file diff --git a/demos/_setup-existing.ps1 b/demos/_setup-existing.ps1 index 42c5399..1697316 100755 --- a/demos/_setup-existing.ps1 +++ b/demos/_setup-existing.ps1 @@ -8,11 +8,11 @@ try { /git-tools/init.ps1 - git add-upstream main -target feature/add-item-1 - git add-upstream main -target feature/add-item-2 - git add-upstream main -target feature/change-existing-item-A - git add-upstream main -target feature/change-existing-item-B - git add-upstream feature/add-item-1 -target feature/subfeature + git add-deps main -target feature/add-item-1 + git add-deps main -target feature/add-item-2 + git add-deps main -target feature/change-existing-item-A + git add-deps main -target feature/change-existing-item-B + git add-deps feature/add-item-1 -target feature/subfeature } finally { Pop-Location diff --git a/demos/demo-local-cd.ps1 b/demos/demo-local-cd.ps1 index 3ca6838..62413f4 100755 --- a/demos/demo-local-cd.ps1 +++ b/demos/demo-local-cd.ps1 @@ -22,7 +22,7 @@ if ((git branch --show-current) -ne 'feature/PS-1') { throw 'Branch name did not match expected'; } -git rc rc/test -u feature/add-item-1,feature/add-item-2 +git rc rc/test -d feature/add-item-1,feature/add-item-2 ThrowOnNativeFalure if ((git branch --show-current) -ne 'feature/PS-1') { diff --git a/demos/demo-local-with-space.ps1 b/demos/demo-local-with-space.ps1 index e23a057..569f604 100755 --- a/demos/demo-local-with-space.ps1 +++ b/demos/demo-local-with-space.ps1 @@ -25,7 +25,7 @@ if ((git branch --show-current) -ne 'feature/PS-1') { throw 'Branch name did not match expected'; } -git rc rc/test -u feature/add-item-1,feature/add-item-2 +git rc rc/test -d feature/add-item-1,feature/add-item-2 ThrowOnNativeFalure if ((git branch --show-current) -ne 'feature/PS-1') { diff --git a/demos/demo-local.ps1 b/demos/demo-local.ps1 index 0ab9843..a1be04f 100755 --- a/demos/demo-local.ps1 +++ b/demos/demo-local.ps1 @@ -22,7 +22,7 @@ if ((git branch --show-current) -ne 'feature/PS-1') { throw 'Branch name did not match expected'; } -git rc rc/test -u feature/add-item-1,feature/add-item-2 +git rc rc/test -d feature/add-item-1,feature/add-item-2 ThrowOnNativeFalure if ((git branch --show-current) -ne 'feature/PS-1') { diff --git a/demos/demo-remote-release.ps1 b/demos/demo-remote-release.ps1 index 3570b79..6d5e93d 100755 --- a/demos/demo-remote-release.ps1 +++ b/demos/demo-remote-release.ps1 @@ -13,10 +13,10 @@ git clone ./origin local cd local /git-tools/init.ps1 -git new feature/PS-1 -u feature/add-item-1 +git new feature/PS-1 -d feature/add-item-1 ThrowOnNativeFalure -git rc rc/test -u feature/subfeature,feature/add-item-2 +git rc rc/test -d feature/subfeature,feature/add-item-2 ThrowOnNativeFalure git verify-updated rc/test diff --git a/demos/demo-remote-without-config.ps1 b/demos/demo-remote-without-config.ps1 index 6f30526..999e3ef 100755 --- a/demos/demo-remote-without-config.ps1 +++ b/demos/demo-remote-without-config.ps1 @@ -24,12 +24,12 @@ if ((git branch --show-current) -ne 'feature/PS-1') { throw 'Branch name did not match expected'; } -$upstreamOfNewFeature = [string[]](git show-upstream) -if ($upstreamOfNewFeature -notcontains 'main') { - throw "Expected main to be upstream of the current branch; found: $(ConvertTo-Json $upstreamOfNewFeature)" +$dependencyOfNewFeature = [string[]](git show-deps) +if ($dependencyOfNewFeature -notcontains 'main') { + throw "Expected main to be dependency of the current branch; found: $(ConvertTo-Json $dependencyOfNewFeature)" } -git rc rc/test -u feature/add-item-1,feature/add-item-2 +git rc rc/test -d feature/add-item-1,feature/add-item-2 ThrowOnNativeFalure if ((git branch --show-current) -ne 'feature/PS-1') { diff --git a/demos/demo-remote.ps1 b/demos/demo-remote.ps1 index 74baadc..64dcf7b 100755 --- a/demos/demo-remote.ps1 +++ b/demos/demo-remote.ps1 @@ -13,7 +13,7 @@ git clone ./origin local cd local /git-tools/init.ps1 -git new feature/PS-1 -u feature/add-item-1 +git new feature/PS-1 -d feature/add-item-1 ThrowOnNativeFalure if ((git rev-parse origin/feature/add-item-1) -ne (git rev-parse HEAD)) { @@ -24,19 +24,19 @@ if ((git branch --show-current) -ne 'feature/PS-1') { throw 'Branch name did not match expected'; } -$upstreamOfNewFeature = [string[]](git show-upstream -recurse) -if ($upstreamOfNewFeature -notcontains 'main') { - throw "Expected main to be upstream of the current branch; found: $(ConvertTo-Json $upstreamOfNewFeature)" +$dependencyOfNewFeature = [string[]](git show-deps -recurse) +if ($dependencyOfNewFeature -notcontains 'main') { + throw "Expected main to be dependency of the current branch; found: $(ConvertTo-Json $dependencyOfNewFeature)" } -git rc rc/test -u feature/add-item-1,feature/add-item-2 +git rc rc/test -d feature/add-item-1,feature/add-item-2 ThrowOnNativeFalure if ((git branch --show-current) -ne 'feature/PS-1') { throw 'Branch name should not have changed'; } -git pull-upstream rc/test +git pull-deps rc/test ThrowOnNativeFalure git verify-updated rc/test diff --git a/docs/add-upstream.md b/docs/add-deps.md similarity index 52% rename from docs/add-upstream.md rename to docs/add-deps.md index 678e5a1..fba0694 100644 --- a/docs/add-upstream.md +++ b/docs/add-deps.md @@ -1,18 +1,18 @@ -# `git add-upstream` +# `git add-deps` -Adds one or more upstream branches to an existing branch. +Adds one or more dependency branches to an existing branch. Usage: - git-add-upstream.ps1 [-upstreamBranches] [-target ] [-comment ] [-dryRun] + git-add-deps.ps1 [-dependencyBranches] [-target ] [-comment ] [-dryRun] ## Parameters -### `[-upstreamBranches] ` +### `[-dependencyBranches] ` -_Aliases: -u, -upstream, -upstreams_ +_Aliases: -d, -dependency, -dependencies_ -A comma-delimited list of branches to add upstream of the existing branch. +A comma-delimited list of branches to add dependency of the existing branch. ### `-target ` (Optional) @@ -22,7 +22,7 @@ The existing branch to update. If not specified, use the current branch. _Aliases: -m, -message_ -If specified, include this comment in the commit message for the upstream +If specified, include this comment in the commit message for the dependency tracking branch when pushing changes. ### `-dryRun` (Optional) diff --git a/docs/new.md b/docs/new.md index 5238531..384799c 100644 --- a/docs/new.md +++ b/docs/new.md @@ -5,7 +5,7 @@ Creates a new branch and checks it out from the specified branches Usage: git-new.ps1 [-branchName] [-comment ] ` - [-upstreamBranches ] [-dryRun] + [-dependencyBranches ] [-dryRun] ## Parameters: @@ -17,11 +17,11 @@ Specifies the name of the branch. _Aliases: -m, -message_ -Specifies a comment as part of the commit message for the upstream branch. +Specifies a comment as part of the commit message for the dependency branch. -### `-upstreamBranches ` (Optional) +### `-dependencyBranches ` (Optional) -_Aliases: -u, -upstream, -upstreams_ +_Aliases: -d, -dependency, -dependencies_ A comma-delimited list of branches (without the remote, if applicable). If not specified, assumes the default service line (see [tool-config][tool-config].) diff --git a/docs/pull-upstream.md b/docs/pull-deps.md similarity index 64% rename from docs/pull-upstream.md rename to docs/pull-deps.md index 63a99b6..1e6a61a 100644 --- a/docs/pull-upstream.md +++ b/docs/pull-deps.md @@ -1,25 +1,25 @@ -# `git pull-upstream` +# `git pull-deps` -Merges all the "upstream" branches into the current branch, or the specified one +Merges all the "dependency" branches into the current branch, or the specified one if provided. Note that this doesn't ensure those branches are up-to-date, only merges them into the current branch. If working with a remote, pushes the merge to the remote. Usage: - git-pull-upstream.ps1 [-target ] [-recurse] [-dryRun] + git-pull-deps.ps1 [-target ] [-recurse] [-dryRun] ## Parameters ### `[-target] ` (Optional) If provided, the script will change branches to the named branch, and -pull-upstream for that branch. If it succeeds, `pull-upstream` will return to +pull-deps for that branch. If it succeeds, `pull-deps` will return to the original branch. Otherwise, conflicts will be left uncommitted. ### `-recurse` (Optional) -If specified, will first attempt to merge branches further upstream. If any +If specified, will first attempt to merge branches further dependency. If any merges fail, the propagation will be halted to prevent irrelevant conflicts from being reported. diff --git a/docs/rc.md b/docs/rc.md index 4f5b38b..66a6e0c 100644 --- a/docs/rc.md +++ b/docs/rc.md @@ -1,11 +1,11 @@ # `git rc` -Create a new branch from multiple upstream branches without changing the local +Create a new branch from multiple dependency branches without changing the local branch. Intended for creating release candidate branches. Usage: - git-rc.ps1 [-target] [-upstreamBranches ] [-comment ] [-force] [-dryRun] [-allowOutOfDate] [-allowNoUpstreams] + git-rc.ps1 [-target] [-dependencyBranches ] [-comment ] [-force] [-dryRun] [-allowOutOfDate] [-allowNoDependencies] ## Parameters @@ -13,9 +13,9 @@ Usage: The name of the new branch. -### `-upstreamBranches ` +### `-dependencyBranches ` -_Aliases: -u, -upstream, -upstreams_ +_Aliases: -d, -dependency, -dependencies_ Comma-delimited list of branches to merge into the new branch. @@ -23,7 +23,7 @@ Comma-delimited list of branches to merge into the new branch. _Aliases: -m, -message_ -If specified, adds to the commit message on the upstream tracking branch for +If specified, adds to the commit message on the dependency tracking branch for creating the RC branch. ### `-force` (Optional) @@ -33,12 +33,12 @@ branch. ### `-allowOutOfDate` (Optional) -Allows branches that are not up-to-date with their upstreams. (This is the old +Allows branches that are not up-to-date with their dependencies. (This is the old behavior.) -### `-allowNoUpstreams` (Optional) +### `-allowNoDependencies` (Optional) -Allows branches that do not have any upstreams. (This is the old behavior.) +Allows branches that do not have any dependencies. (This is the old behavior.) ### `-dryRun` (Optional) diff --git a/docs/rebuild-rc.md b/docs/rebuild-rc.md index 1e6e97d..1ed6a95 100644 --- a/docs/rebuild-rc.md +++ b/docs/rebuild-rc.md @@ -1,11 +1,11 @@ # `git rebuild-rc` -Recreate a branch from its upstream branches, possibly modifying the upstream +Recreate a branch from its dependency branches, possibly modifying the dependency branches. Intended for creating release candidate branches. Usage: - git-rc.ps1 [-target] [-with ] [-without ] [-comment ] [-dryRun] [-allowOutOfDate] [-allowNoUpstreams] + git-rc.ps1 [-target] [-with ] [-without ] [-comment ] [-dryRun] [-allowOutOfDate] [-allowNoDependencies] ## Parameters @@ -15,30 +15,30 @@ The name of the new branch. ### `-with ` -_Aliases: -add, -addUpstream, -upstreamBranches_ +_Aliases: -add, -addDependency, -dependencyBranches_ -Comma-delimited list of branches to add upstream of the rc when rebuilding +Comma-delimited list of branches to add dependency of the rc when rebuilding ### `-without ` -_Aliases: -remoce, -removeUpstream_ +_Aliases: -remoce, -removeDependency_ -Comma-delimited list of branches to remove upstream of the rc when rebuilding +Comma-delimited list of branches to remove dependency of the rc when rebuilding ### `-comment ` (Optional) _Aliases: -m, -message_ -If specified, adds to the commit message on the upstream tracking branch for +If specified, adds to the commit message on the dependency tracking branch for creating the RC branch. ### `-allowOutOfDate` (Optional) -Allows branches that are not up-to-date with their upstreams. +Allows branches that are not up-to-date with their dependencies. -### `-allowNoUpstreams` (Optional) +### `-allowNoDependencies` (Optional) -Allows branches that do not have any upstreams. +Allows branches that do not have any dependencies. ### `-dryRun` (Optional) diff --git a/docs/refactor-deps.md b/docs/refactor-deps.md new file mode 100644 index 0000000..03d0880 --- /dev/null +++ b/docs/refactor-deps.md @@ -0,0 +1,47 @@ +# `git refactor-deps` + +Refactor dependency branches to redirect dependencies from "source" to "target". +* _All_ branches that previously used "source" as an dependency will now use + "target" as an dependency instead. +* This command only alters the dependency configuration of branches. Put another + way, it does not merge any changes from new dependencies, etc. into affected + branches, nor does it actually delete a "removed" source. + +Usage: + + git-refactor-deps.ps1 [-source] [-target] + (-remove|-rename|-combine) [-comment ] [-dryRun] + +## Parameters + +### `[-source] ` + +The name of the old dependency branch. + +### `[-target] ` + +The name of the new dependency branch. + +### `(-remove|-rename|-combine)` + +One of -rename, -remove, or -combine must be specfied. + +* `-remove` indicates that the source branch should be removed and old dependency + branches can be ignored. +* `-rename` indicates that dependencies from the source branch should be + transferred to the target branch; any dependencies of the target should be + overwritten. +* `-combine` indicates that dependencies from both source and target should be + combined into dependencies of the target branch. + +### `-comment ` (Optional) + +_Aliases: -m, -message_ + +If specified, include this comment in the commit message for the dependency +tracking branch when pushing changes. + +### `-dryRun` (Optional) + +If specified, only test merging, do not push the updates. + diff --git a/docs/refactor-upstream.md b/docs/refactor-upstream.md deleted file mode 100644 index debb475..0000000 --- a/docs/refactor-upstream.md +++ /dev/null @@ -1,47 +0,0 @@ -# `git refactor-upstream` - -Refactor upstream branches to redirect upstreams from "source" to "target". -* _All_ branches that previously used "source" as an upstream will now use - "target" as an upstream instead. -* This command only alters the upstream configuration of branches. Put another - way, it does not merge any changes from new upstreams, etc. into affected - branches, nor does it actually delete a "removed" source. - -Usage: - - git-refactor-upstream.ps1 [-source] [-target] - (-remove|-rename|-combine) [-comment ] [-dryRun] - -## Parameters - -### `[-source] ` - -The name of the old upstream branch. - -### `[-target] ` - -The name of the new upstream branch. - -### `(-remove|-rename|-combine)` - -One of -rename, -remove, or -combine must be specfied. - -* `-remove` indicates that the source branch should be removed and old upstream - branches can be ignored. -* `-rename` indicates that upstreams from the source branch should be - transferred to the target branch; any upstreams of the target should be - overwritten. -* `-combine` indicates that upstreams from both source and target should be - combined into upstreams of the target branch. - -### `-comment ` (Optional) - -_Aliases: -m, -message_ - -If specified, include this comment in the commit message for the upstream -tracking branch when pushing changes. - -### `-dryRun` (Optional) - -If specified, only test merging, do not push the updates. - diff --git a/docs/release.md b/docs/release.md index 696231a..a03a3f7 100644 --- a/docs/release.md +++ b/docs/release.md @@ -20,12 +20,12 @@ The name of the branch that will be updated with the released branch. _Aliases: -m, -message_ -If specified, overrides the commit message added to the upstream tracking +If specified, overrides the commit message added to the dependency tracking branch. ### `-preserve ` (Optional) -A comma delimited list of branches to preserve in addition to those upstream +A comma delimited list of branches to preserve in addition to those dependency ### `-cleanupOnly` (Optional) diff --git a/docs/show-downstream.md b/docs/show-dependants.md similarity index 62% rename from docs/show-downstream.md rename to docs/show-dependants.md index 35d33bb..626df82 100644 --- a/docs/show-downstream.md +++ b/docs/show-dependants.md @@ -1,21 +1,21 @@ -# `git show-downstream` +# `git show-dependants` -Shows what the downstream branches are of the current (or specified) branch. +Shows what the dependants branches are of the current (or specified) branch. Usage: - git-show-downstream.ps1 [-target ] [-recurse] [-noFetch] [-quiet] + git-show-dependants.ps1 [-target ] [-recurse] [-noFetch] [-quiet] ## Parameters ### `[-target] ` (Optional) -The name of the branch to list downstream branches. If not specified, use the +The name of the branch to list dependants branches. If not specified, use the current branch. ### `-recurse` (Optional) -If specified, list all downstream branches recursively. +If specified, list all dependants branches recursively. ## `-noFetch` (Optional) diff --git a/docs/show-upstream.md b/docs/show-deps.md similarity index 68% rename from docs/show-upstream.md rename to docs/show-deps.md index f6c5079..030feda 100644 --- a/docs/show-upstream.md +++ b/docs/show-deps.md @@ -1,22 +1,22 @@ -# `git show-upstream` +# `git show-deps` -Shows what the upstream branches are of the current (or specified) branch. +Shows what the dependency branches are of the current (or specified) branch. Usage: - git-show-upstream.ps1 [-target ] [-recurse] [-includeRemote] + git-show-deps.ps1 [-target ] [-recurse] [-includeRemote] [-noFetch] [-quiet] ## Parameters ### `[-target] ` (Optional) -The name of the branch to list upstream branches. If not specified, use the +The name of the branch to list dependency branches. If not specified, use the current branch. ### `-recurse` (Optional) -If specified, list all upstream branches recursively. +If specified, list all dependency branches recursively. ### `-includeRemote` (Optional) diff --git a/docs/tool-audit-prune.md b/docs/tool-audit-prune.md index b89741b..273bc76 100644 --- a/docs/tool-audit-prune.md +++ b/docs/tool-audit-prune.md @@ -1,6 +1,6 @@ # `git tool-audit-prune` -Removes upstream branch configuration for branches that no longer exist. +Removes dependency branch configuration for branches that no longer exist. Usage: diff --git a/docs/tool-audit-simplify.md b/docs/tool-audit-simplify.md index ae46cb5..03347e6 100644 --- a/docs/tool-audit-simplify.md +++ b/docs/tool-audit-simplify.md @@ -1,6 +1,6 @@ # `git tool-audit-simplify` -Removes redundant upstream branches for every branch. +Removes redundant dependency branches for every branch. Usage: diff --git a/docs/tool-config.md b/docs/tool-config.md index d9ef3b4..73428b8 100644 --- a/docs/tool-config.md +++ b/docs/tool-config.md @@ -4,20 +4,20 @@ Sets configuration values used by git-tools. Usage: - git tool-config [-remote ] [-upstreamBranch ] ` + git tool-config [-remote ] [-dependencyBranch ] ` [-defaultServiceLine ] ## Parameters: ### `-remote ` (Optional) -Sets the remote used where the upstream branch is tracked. Most commands will +Sets the remote used where the dependency branch is tracked. Most commands will automatically fetch/push from this remote when set. If not set and the repository has a remote configured, the first remote will be used. -### `-upstreamBranch ` (Optional) +### `-dependencyBranch ` (Optional) -Sets the branch name used to track upstream branches. Defaults to `_upstream`. +Sets the branch name used to track dependency branches. Defaults to `$dependencies`. ### `-defaultServiceLine ` (Optional) diff --git a/docs/verify-updated.md b/docs/verify-updated.md index 6dec851..94eeed5 100644 --- a/docs/verify-updated.md +++ b/docs/verify-updated.md @@ -1,6 +1,6 @@ # `git verify-updated` -Verifies that a branch is up-to-date with its upstream branches. +Verifies that a branch is up-to-date with its dependency branches. Usage: @@ -14,8 +14,8 @@ The branch name to check. If not specified, use the current branch. ### `-recurse` (Optional) -If specified, recursively check upstream branches. If not specified, will only -check the first level of upstream branches. +If specified, recursively check dependency branches. If not specified, will only +check the first level of dependency branches. ## `-noFetch` (Optional) diff --git a/git-add-upstream.json b/git-add-deps.json similarity index 60% rename from git-add-upstream.json rename to git-add-deps.json index 4ff6c3f..207ced7 100644 --- a/git-add-upstream.json +++ b/git-add-deps.json @@ -9,7 +9,7 @@ { "type": "assert-existence", "parameters": { - "branches": ["$params.target", "$params.upstreamBranches"], + "branches": ["$params.target", "$params.dependencyBranches"], "shouldExist": true } }, @@ -20,42 +20,42 @@ } }, { - "id": "get-upstream", - "type": "get-upstream", + "id": "get-dependency", + "type": "get-dependency", "parameters": { "target": "$params.target" } }, { - "id": "simplify-upstream", - "type": "simplify-upstream", + "id": "simplify-dependency", + "type": "simplify-dependency", "parameters": { - "upstreamBranches": ["$actions['get-upstream'].outputs ?? @()", "$params.upstreamBranches"] + "dependencyBranches": ["$actions['get-dependency'].outputs ?? @()", "$params.dependencyBranches"] } }, { - "id": "filtered-upstream", + "id": "filtered-dependency", "type": "filter-branches", "parameters": { - "include": ["$actions['simplify-upstream'].outputs"], - "exclude": ["$actions['get-upstream'].outputs"] + "include": ["$actions['simplify-dependency'].outputs"], + "exclude": ["$actions['get-dependency'].outputs"] } }, - { + { "type": "add-diagnostic", - "condition": "$actions['filtered-upstream'].outputs ? $false : $true", + "condition": "$actions['filtered-dependency'].outputs ? $false : $true", "parameters": { "message": "No branches would be added." } }, { - "id": "set-upstream", - "type": "set-upstream", + "id": "set-dependency", + "type": "set-dependency", "parameters": { - "upstreamBranches": { - "$params.target": ["$actions['simplify-upstream'].outputs"] + "dependencyBranches": { + "$params.target": ["$actions['simplify-dependency'].outputs"] }, - "message": "Add branches $($actions['filtered-upstream'].outputs) to $($params.target)$($params.comment -eq '' ? '' : \" for $($params.comment)\")" + "message": "Add branches $($actions['filtered-dependency'].outputs) to $($params.target)$($params.comment -eq '' ? '' : \" for $($params.comment)\")" } }, { @@ -63,11 +63,11 @@ "type": "merge-branches", "parameters": { "source": "$($params.target)", - "upstreamBranches": ["$actions['filtered-upstream'].outputs"], + "dependencyBranches": ["$actions['filtered-dependency'].outputs"], "mergeMessageTemplate": "Merge '{}' to $($params.target)" } }, - { + { "type": "add-diagnostic", "condition": "$actions.mergeBranches.outputs.failed -ne $null", "parameters": { @@ -81,7 +81,7 @@ "type": "set-branches", "parameters": { "branches": { - "$config.upstreamBranch": "$actions['set-upstream'].outputs['commit']", + "$config.dependencyBranch": "$actions['set-dependency'].outputs['commit']", "$params.target": "$actions.mergeBranches.outputs['commit']" } } @@ -94,6 +94,6 @@ } ], "output": [ - "$($params.target) has the following branches added upstream: $($actions['filtered-upstream'].outputs)" + "$($params.target) has the following branches added dependency: $($actions['filtered-dependency'].outputs)" ] } diff --git a/git-add-upstream.ps1 b/git-add-deps.ps1 similarity index 63% rename from git-add-upstream.ps1 rename to git-add-deps.ps1 index f1e9c0c..43b84a1 100755 --- a/git-add-upstream.ps1 +++ b/git-add-deps.ps1 @@ -1,7 +1,7 @@ #!/usr/bin/env pwsh Param( - [Parameter(Mandatory, Position=0)][Alias('u')][Alias('upstream')][Alias('upstreams')][String[]] $upstreamBranches, + [Parameter(Mandatory, Position=0)][Alias('d')][Alias('dependency')][Alias('dependencies')][String[]] $dependencyBranches, [Parameter()][String] $target, [Parameter()][Alias('message')][Alias('m')][string] $comment, [switch] $dryRun @@ -11,8 +11,8 @@ Import-Module -Scope Local "$PSScriptRoot/utils/input.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/scripting.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/query-state.psm1" -Invoke-JsonScript -scriptPath "$PSScriptRoot/git-add-upstream.json" -params @{ +Invoke-JsonScript -scriptPath "$PSScriptRoot/git-add-deps.json" -params @{ target = ($target ? $target : (Get-CurrentBranch ?? '')); - upstreamBranches = Expand-StringArray $upstreamBranches; + dependencyBranches = Expand-StringArray $dependencyBranches; comment = $comment ?? ''; } -dryRun:$dryRun diff --git a/git-add-upstream.tests.ps1 b/git-add-deps.tests.ps1 similarity index 74% rename from git-add-upstream.tests.ps1 rename to git-add-deps.tests.ps1 index 3dcb6c5..a16f9c7 100755 --- a/git-add-upstream.tests.ps1 +++ b/git-add-deps.tests.ps1 @@ -1,4 +1,4 @@ -Describe 'git-add-upstream' { +Describe 'git-add-deps' { BeforeAll { . "$PSScriptRoot/utils/testing.ps1" Import-Module -Scope Local "$PSScriptRoot/utils/framework.mocks.psm1" @@ -23,7 +23,7 @@ Describe 'git-add-upstream' { Initialize-NoCurrentBranch ) - { & ./git-add-upstream.ps1 -upstream 'feature/FOO-76' } | Should -Throw + { & ./git-add-deps.ps1 -dependency 'feature/FOO-76' } | Should -Throw $fw.assertDiagnosticOutput | Should -Contain "ERR: No branch name was provided" Invoke-VerifyMock $mocks -Times 1 } @@ -33,53 +33,53 @@ Describe 'git-add-upstream' { Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'feature/FOO-76') -shouldExist $true Initialize-CurrentBranch 'rc/2022-07-14' Initialize-AssertValidBranchName 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") ` -to @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 'feature/FOO-76' + & ./git-add-deps.ps1 'feature/FOO-76' $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - It 'works if there are no upstream branches' { + It 'works if there are no dependency branches' { $mocks = @( Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'feature/FOO-76') -shouldExist $true Initialize-CurrentBranch 'rc/2022-07-14' Initialize-AssertValidBranchName 'rc/2022-07-14' - Initialize-UpstreamBranches @{ } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76") ` -to @("feature/FOO-76") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 'feature/FOO-76' + & ./git-add-deps.ps1 'feature/FOO-76' $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -89,25 +89,25 @@ Describe 'git-add-upstream' { Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'feature/FOO-76', 'feature/FOO-84') -shouldExist $true Initialize-CurrentBranch 'rc/2022-07-14' Initialize-AssertValidBranchName 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76", 'feature/FOO-84', "feature/FOO-123", "feature/XYZ-1-services") ` -to @("feature/FOO-76", 'feature/FOO-84', "feature/FOO-123", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76", 'feature/FOO-84', "feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76', 'feature/FOO-84') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76', 'feature/FOO-84') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 'feature/FOO-76','feature/FOO-84' -m "" + & ./git-add-deps.ps1 'feature/FOO-76','feature/FOO-84' -m "" $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -117,25 +117,25 @@ Describe 'git-add-upstream' { Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'feature/FOO-76') -shouldExist $true Initialize-NoCurrentBranch Initialize-AssertValidBranchName 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") ` -to @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 -upstream 'feature/FOO-76' -target 'rc/2022-07-14' -m "" + & ./git-add-deps.ps1 -dependency 'feature/FOO-76' -target 'rc/2022-07-14' -m "" $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -145,25 +145,25 @@ Describe 'git-add-upstream' { Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'feature/FOO-76', 'feature/FOO-84') -shouldExist $true Initialize-NoCurrentBranch Initialize-AssertValidBranchName 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76", 'feature/FOO-84', "feature/FOO-123", "feature/XYZ-1-services") ` -to @("feature/FOO-76", 'feature/FOO-84', "feature/FOO-123", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76", 'feature/FOO-84', "feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76', 'feature/FOO-84') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76', 'feature/FOO-84') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 'feature/FOO-76','feature/FOO-84' -target 'rc/2022-07-14' -m "" + & ./git-add-deps.ps1 'feature/FOO-76','feature/FOO-84' -target 'rc/2022-07-14' -m "" $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -181,54 +181,54 @@ Describe 'git-add-upstream' { Initialize-CurrentBranch 'rc/2022-07-14' Initialize-AssertValidBranchName 'rc/2022-07-14' Initialize-LocalActionAssertPushedSuccess 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") ` -to @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 @('feature/FOO-76') -m "" + & ./git-add-deps.ps1 @('feature/FOO-76') -m "" $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - It 'works if there are no upstream branches' { + It 'works if there are no dependency branches' { $mocks = @( Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'feature/FOO-76') -shouldExist $true Initialize-CurrentBranch 'rc/2022-07-14' Initialize-AssertValidBranchName 'rc/2022-07-14' Initialize-LocalActionAssertPushedSuccess 'rc/2022-07-14' - Initialize-UpstreamBranches @{ } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76") ` -to @("feature/FOO-76") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 'feature/FOO-76' + & ./git-add-deps.ps1 'feature/FOO-76' $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -238,13 +238,13 @@ Describe 'git-add-upstream' { Initialize-AssertValidBranchName 'rc/2022-07-14' Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'infra/shared') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services","infra/shared") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services","infra/shared") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("infra/shared", "infra/shared", "feature/FOO-123", "feature/XYZ-1-services") ` -to @("infra/shared", "feature/FOO-123", "feature/XYZ-1-services") ) - { & ./git-add-upstream.ps1 @('infra/shared') -target 'rc/2022-07-14' } | Should -Throw + { & ./git-add-deps.ps1 @('infra/shared') -target 'rc/2022-07-14' } | Should -Throw $fw.assertDiagnosticOutput | Should -Be @('ERR: No branches would be added.') Invoke-VerifyMock $mocks -Times 1 } @@ -255,30 +255,30 @@ Describe 'git-add-upstream' { Initialize-CurrentBranch 'my-branch' Initialize-AssertValidBranchName 'rc/2022-07-14' Initialize-LocalActionAssertPushedSuccess 'rc/2022-07-14' - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("infra/shared","feature/XYZ-1-services") 'feature/FOO-123' = @('infra/shared') 'infra/shared' = @('main') 'feature/XYZ-1-services' = @() 'main' = @() } - Initialize-LocalActionSimplifyUpstreamBranches ` + Initialize-LocalActionSimplifyDependencyBranches ` -from @("feature/FOO-123", "infra/shared", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-123') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-123') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 @('feature/FOO-123') -target 'rc/2022-07-14' -m "" + & ./git-add-deps.ps1 @('feature/FOO-123') -target 'rc/2022-07-14' -m "" $fw.assertDiagnosticOutput | Should -Be @("WARN: Removing 'infra/shared' from branches; it is redundant via the following: feature/FOO-123") Invoke-VerifyMock $mocks -Times 1 } @@ -289,25 +289,25 @@ Describe 'git-add-upstream' { Initialize-CurrentBranch 'rc/2022-07-14' Initialize-AssertValidBranchName 'rc/2022-07-14' Initialize-LocalActionAssertPushedNotTracked 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") ` -to @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` + -dependencyBranches @('feature/FOO-76') -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 @('feature/FOO-76') -target 'rc/2022-07-14' -m "" + & ./git-add-deps.ps1 @('feature/FOO-76') -target 'rc/2022-07-14' -m "" $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -317,27 +317,27 @@ Describe 'git-add-upstream' { Initialize-LocalActionAssertExistence -branches @('rc/2022-07-14', 'feature/FOO-76') -shouldExist $true Initialize-CurrentBranch 'rc/2022-07-14' Initialize-LocalActionAssertPushedSuccess 'rc/2022-07-14' - Initialize-UpstreamBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-DependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") } + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") ` -to @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-76", "feature/FOO-123", "feature/XYZ-1-services") } -commitish 'new-commit' Initialize-LocalActionMergeBranchesFailure ` - -upstreamBranches @('feature/FOO-76') ` + -dependencyBranches @('feature/FOO-76') ` -failures @('feature/FOO-76') ` -resultCommitish 'result-commitish' ` -source 'rc/2022-07-14' ` -mergeMessageTemplate "Merge '{}' to rc/2022-07-14" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = 'result-commitish' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-14') ) - & ./git-add-upstream.ps1 'feature/FOO-76' -m "" + & ./git-add-deps.ps1 'feature/FOO-76' -m "" $fw.assertDiagnosticOutput | Should -Be @('WARN: rc/2022-07-14 has incoming conflicts from feature/FOO-76. Be sure to manually merge.') Invoke-VerifyMock $mocks -Times 1 } @@ -349,7 +349,7 @@ Describe 'git-add-upstream' { Initialize-LocalActionAssertPushedAhead 'rc/2022-07-14' ) - { & ./git-add-upstream.ps1 @('feature/FOO-76') -target 'rc/2022-07-14' -m "" } | Should -Throw + { & ./git-add-deps.ps1 @('feature/FOO-76') -target 'rc/2022-07-14' -m "" } | Should -Throw $fw.assertDiagnosticOutput | Should -Be @('ERR: The local branch for rc/2022-07-14 has changes that are not pushed to the remote') Invoke-VerifyMock $mocks -Times 1 } diff --git a/git-new.json b/git-new.json index 4f7bf02..4e7fece 100644 --- a/git-new.json +++ b/git-new.json @@ -3,7 +3,7 @@ { "type": "validate-branch-names", "parameters": { - "branches": ["$params.branchName", "$params.upstreamBranches"] + "branches": ["$params.branchName", "$params.dependencyBranches"] } }, { @@ -16,23 +16,23 @@ { "type": "assert-existence", "parameters": { - "branches": ["$params.upstreamBranches"], + "branches": ["$params.dependencyBranches"], "shouldExist": true } }, { - "id": "simplify-upstream", - "type": "simplify-upstream", + "id": "simplify-dependency", + "type": "simplify-dependency", "parameters": { - "upstreamBranches": ["$params.upstreamBranches"] + "dependencyBranches": ["$params.dependencyBranches"] } }, { - "id": "set-upstream", - "type": "set-upstream", + "id": "set-dependency", + "type": "set-dependency", "parameters": { - "upstreamBranches": { - "$params.branchName": ["$actions['simplify-upstream'].outputs"] + "dependencyBranches": { + "$params.branchName": ["$actions['simplify-dependency'].outputs"] }, "message": "Add branch $($params.branchName)$($params.comment ? \" for $($params.comment)\" : '')" } @@ -41,11 +41,11 @@ "id": "createBranch", "type": "merge-branches", "parameters": { - "upstreamBranches": ["$actions['simplify-upstream'].outputs"], + "dependencyBranches": ["$actions['simplify-dependency'].outputs"], "mergeMessageTemplate": "Merge '{}' for creation of $($params.branchName)" } }, - { + { "type": "add-diagnostic", "condition": "$actions.createBranch.outputs.failed -ne $null", "parameters": { @@ -59,7 +59,7 @@ "type": "set-branches", "parameters": { "branches": { - "$config.upstreamBranch": "$actions['set-upstream'].outputs['commit']", + "$config.dependencyBranch": "$actions['set-dependency'].outputs['commit']", "$params.branchName": "$actions.createBranch.outputs['commit']" } } diff --git a/git-new.ps1 b/git-new.ps1 index 9bf115c..596a189 100755 --- a/git-new.ps1 +++ b/git-new.ps1 @@ -8,9 +8,9 @@ Specifies the name of the branch. .PARAMETER comment - Specifies a comment as part of the commit message for the upstream branch. + Specifies a comment as part of the commit message for the dependency branch. -.PARAMETER upstreamBranches +.PARAMETER dependencyBranches A comma-delimited list of branches (without the remote, if applicable). If not specified, assumes the default service line (see [tool-config](./tool-config.md).) .PARAMETER dryRun @@ -19,7 +19,7 @@ Param( [Parameter(Mandatory)][String] $branchName, [Parameter()][Alias('m')][Alias('message')][ValidateLength(1,25)][String] $comment, - [Parameter()][Alias('u')][Alias('upstream')][Alias('upstreams')][String[]] $upstreamBranches, + [Parameter()][Alias('d')][Alias('dependency')][Alias('dependencies')][String[]] $dependencyBranches, [switch] $dryRun ) @@ -28,6 +28,6 @@ Import-Module -Scope Local "$PSScriptRoot/utils/scripting.psm1" Invoke-JsonScript -scriptPath "$PSScriptRoot/git-new.json" -params @{ branchName = $branchName; - upstreamBranches = Expand-StringArray $upstreamBranches; + dependencyBranches = Expand-StringArray $dependencyBranches; comment = $comment ?? ''; } -dryRun:$dryRun diff --git a/git-new.tests.ps1 b/git-new.tests.ps1 index 07cd736..4f11a16 100755 --- a/git-new.tests.ps1 +++ b/git-new.tests.ps1 @@ -7,18 +7,18 @@ Describe 'git-new' { Import-Module -Scope Local "$PSScriptRoot/utils/git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/actions.mocks.psm1" } - + BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework -throwInsteadOfExit } - + Context 'without remote' { BeforeAll { Initialize-ToolConfiguration -noRemote - Lock-LocalActionSetUpstream + Lock-LocalActionSetDependency - Initialize-UpstreamBranches @{} + Initialize-DependencyBranches @{} Initialize-NoCurrentBranch } @@ -27,14 +27,14 @@ Describe 'git-new' { $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = 'main' } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('main') 'latest-main' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'latest-main' } Initialize-FinalizeActionCheckout 'feature/PS-100-some-work' @@ -48,17 +48,17 @@ Describe 'git-new' { It 'creates a local branch when no remotes are configured' { Initialize-AssertValidBranchName 'feature/PS-100-some-work' - + $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = 'main' } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('main') 'latest-main' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'latest-main' } Initialize-FinalizeActionCheckout 'feature/PS-100-some-work' @@ -77,40 +77,40 @@ Describe 'git-new' { $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-600-some-work') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('infra/foo') -shouldExist $true - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-600-some-work' = 'infra/foo' } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('infra/foo') 'latest-foo' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-600-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-600-some-work' = 'latest-foo' } Initialize-FinalizeActionCheckout 'feature/PS-600-some-work' Initialize-FinalizeActionTrackSuccess @('feature/PS-600-some-work') -untracked @('feature/PS-600-some-work') ) - & $PSScriptRoot/git-new.ps1 feature/PS-600-some-work -u 'infra/foo' -m 'some work' + & $PSScriptRoot/git-new.ps1 feature/PS-600-some-work -d 'infra/foo' -m 'some work' $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - + It 'does not check out if the working directory is not clean' { Initialize-DirtyWorkingDirectory Initialize-AssertValidBranchName 'feature/PS-100-some-work' - + $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = 'main' } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('main') 'latest-main' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'latest-main' } ) @@ -128,11 +128,11 @@ Describe 'git-new' { Initialize-CleanWorkingDirectory Initialize-NoCurrentBranch - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/homepage-redesign' = @('infra/foo') 'infra/foo' = @('main') } - Lock-LocalActionSetUpstream + Lock-LocalActionSetDependency } It 'detects an invalid branch name and prevents moving forward' { @@ -150,14 +150,14 @@ Describe 'git-new' { $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = 'main' } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('main') 'latest-main' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'latest-main' } -track @('feature/PS-100-some-work') Initialize-FinalizeActionCheckout 'feature/PS-100-some-work' @@ -169,56 +169,56 @@ Describe 'git-new' { $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } - It 'creates a remote branch when a remote is configured and an upstream branch is provided' { + It 'creates a remote branch when a remote is configured and an dependency branch is provided' { Initialize-AssertValidBranchName 'feature/PS-100-some-work' Initialize-AssertValidBranchName 'infra/foo' $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('infra/foo') -shouldExist $true - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = 'infra/foo' } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('infra/foo') 'latest-foo' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'latest-foo' } -track @('feature/PS-100-some-work') Initialize-FinalizeActionCheckout 'feature/PS-100-some-work' Initialize-FinalizeActionTrackSuccess @('feature/PS-100-some-work') -untracked @('feature/PS-100-some-work') ) - & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -u 'infra/foo' -m 'some work' + & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -d 'infra/foo' -m 'some work' Invoke-VerifyMock $mocks -Times 1 $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } - It 'creates a remote branch with simplified upstream dependencies' { + It 'creates a remote branch with simplified dependency dependencies' { Initialize-AssertValidBranchName 'feature/PS-100-some-work' Initialize-AssertValidBranchName 'infra/foo' Initialize-AssertValidBranchName 'main' Initialize-AssertValidBranchName 'feature/homepage-redesign' - + $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('infra/foo', 'main', 'feature/homepage-redesign') -shouldExist $true - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = @('feature/homepage-redesign') } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('feature/homepage-redesign') 'latest-redesign' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'latest-redesign' } -track @('feature/PS-100-some-work') Initialize-FinalizeActionCheckout 'feature/PS-100-some-work' Initialize-FinalizeActionTrackSuccess @('feature/PS-100-some-work') -untracked @('feature/PS-100-some-work') ) - & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -u 'infra/foo,main,feature/homepage-redesign' -m 'some work' + & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -d 'infra/foo,main,feature/homepage-redesign' -m 'some work' Invoke-VerifyMock $mocks -Times 1 $fw.assertDiagnosticOutput | Should -Be @( "WARN: Removing 'infra/foo' from branches; it is redundant via the following: feature/homepage-redesign" @@ -226,31 +226,31 @@ Describe 'git-new' { ) } - It 'creates a remote branch with simplified upstream dependencies but still multiple' { + It 'creates a remote branch with simplified dependency dependencies but still multiple' { Initialize-AssertValidBranchName 'feature/PS-100-some-work' Initialize-AssertValidBranchName 'infra/foo' Initialize-AssertValidBranchName 'main' Initialize-AssertValidBranchName 'feature/homepage-redesign' Initialize-AssertValidBranchName 'infra/update-dependencies' - + $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('infra/foo', 'main', 'feature/homepage-redesign', 'infra/update-dependencies') -shouldExist $true - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = @('feature/homepage-redesign', 'infra/update-dependencies') } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @('feature/homepage-redesign', 'infra/update-dependencies') 'merge-result' ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'merge-result' } -track @('feature/PS-100-some-work') Initialize-FinalizeActionCheckout 'feature/PS-100-some-work' Initialize-FinalizeActionTrackSuccess @('feature/PS-100-some-work') -untracked @('feature/PS-100-some-work') ) - & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -u 'infra/foo,main,feature/homepage-redesign,infra/update-dependencies' -m 'some work' + & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -d 'infra/foo,main,feature/homepage-redesign,infra/update-dependencies' -m 'some work' Invoke-VerifyMock $mocks -Times 1 $fw.assertDiagnosticOutput | Should -Be @( "WARN: Removing 'infra/foo' from branches; it is redundant via the following: feature/homepage-redesign" @@ -262,11 +262,11 @@ Describe 'git-new' { Initialize-AssertValidBranchName 'feature/PS-100-some-work' Initialize-AssertValidBranchName 'feature/homepage-redesign' Initialize-AssertValidBranchName 'infra/update-dependencies' - + $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('feature/homepage-redesign', 'infra/update-dependencies') -shouldExist $true - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = @('feature/homepage-redesign', 'infra/update-dependencies') } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @@ -275,7 +275,7 @@ Describe 'git-new' { -failAtMerge 0 ) - { & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -u 'feature/homepage-redesign,infra/update-dependencies' -m 'some work' } | Should -Throw + { & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -d 'feature/homepage-redesign,infra/update-dependencies' -m 'some work' } | Should -Throw $fw.assertDiagnosticOutput | Should -Contain 'ERR: No branches could be resolved to merge' Invoke-VerifyMock $mocks -Times 1 } @@ -284,11 +284,11 @@ Describe 'git-new' { Initialize-AssertValidBranchName 'feature/PS-100-some-work' Initialize-AssertValidBranchName 'feature/homepage-redesign' Initialize-AssertValidBranchName 'infra/update-dependencies' - + $mocks = @( Initialize-LocalActionAssertExistence -branches @('feature/PS-100-some-work') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('feature/homepage-redesign', 'infra/update-dependencies') -shouldExist $true - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/PS-100-some-work' = @('feature/homepage-redesign', 'infra/update-dependencies') } -commitish 'new-commit' Initialize-LocalActionMergeBranchesSuccess ` @@ -296,14 +296,14 @@ Describe 'git-new' { -failAtMerge 1 ` -mergeMessageTemplate "Merge '{}' for creation of feature/PS-100-some-work" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'feature/PS-100-some-work' = 'merge-result' } -track @('feature/PS-100-some-work') Initialize-FinalizeActionCheckout 'feature/PS-100-some-work' Initialize-FinalizeActionTrackSuccess @('feature/PS-100-some-work') -untracked @('feature/PS-100-some-work') ) - { & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -u 'feature/homepage-redesign,infra/update-dependencies' -m 'some work' } | Should -Not -Throw + { & $PSScriptRoot/git-new.ps1 feature/PS-100-some-work -d 'feature/homepage-redesign,infra/update-dependencies' -m 'some work' } | Should -Not -Throw $fw.assertDiagnosticOutput | Should -Contain 'WARN: feature/PS-100-some-work has incoming conflicts from infra/update-dependencies. Be sure to manually merge.' Invoke-VerifyMock $mocks -Times 1 } diff --git a/git-pull-upstream.json b/git-pull-deps.json similarity index 94% rename from git-pull-upstream.json rename to git-pull-deps.json index d9d87aa..fe63360 100644 --- a/git-pull-upstream.json +++ b/git-pull-deps.json @@ -21,7 +21,7 @@ "target": "$params.target", "recurse": "$params.recurse" }], - "path": "git-pull-upstream.recurse.json" + "path": "git-pull-deps.recurse.json" } }, { @@ -50,6 +50,6 @@ } ], "output": [ - "$($actions['merge-recurse'].outputs.hasFailures ? \"$($params.target) requires manual merges from $($actions['merge-recurse'].outputs.failures[$params.target])\" : \"$($params.target) has been updated with its upstream branches\")" + "$($actions['merge-recurse'].outputs.hasFailures ? \"$($params.target) requires manual merges from $($actions['merge-recurse'].outputs.failures[$params.target])\" : \"$($params.target) has been updated with its dependency branches\")" ] } diff --git a/git-pull-upstream.ps1 b/git-pull-deps.ps1 similarity index 83% rename from git-pull-upstream.ps1 rename to git-pull-deps.ps1 index b11333a..7d37b13 100755 --- a/git-pull-upstream.ps1 +++ b/git-pull-deps.ps1 @@ -10,7 +10,7 @@ Import-Module -Scope Local "$PSScriptRoot/utils/input.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/scripting.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/query-state.psm1" -Invoke-JsonScript -scriptPath "$PSScriptRoot/git-pull-upstream.json" -params @{ +Invoke-JsonScript -scriptPath "$PSScriptRoot/git-pull-deps.json" -params @{ target = ($target ? $target : (Get-CurrentBranch ?? '')) recurse = $recurse } -dryRun:$dryRun diff --git a/git-pull-upstream.recurse.json b/git-pull-deps.recurse.json similarity index 88% rename from git-pull-upstream.recurse.json rename to git-pull-deps.recurse.json index e22caf9..d869bca 100644 --- a/git-pull-upstream.recurse.json +++ b/git-pull-deps.recurse.json @@ -3,11 +3,11 @@ "mode": "depth-first", "paramScript": [ "if (-not $params.recurse) { return @() }", - "($actions['get-upstream'].outputs | Where-Object { $null -ne $_ -AND $_ -notin ($previous | ForEach-Object { $_.target }) } | ForEach-Object { @{ target = $_; recurse = $params.recurse } })" + "($actions['get-dependency'].outputs | Where-Object { $null -ne $_ -AND $_ -notin ($previous | ForEach-Object { $_.target }) } | ForEach-Object { @{ target = $_; recurse = $params.recurse } })" ], "init": "$recursionContext.result = @{ hasChanges = $false; hasFailures = $false; push = @{}; override = @{}; track = @(); failures = @{} }", "reduceToOutput": "$recursionContext.result", - "actCondition": "$null -ne $actions['get-upstream'].outputs" + "actCondition": "$null -ne $actions['get-dependency'].outputs" }, "prepare": [ { @@ -17,8 +17,8 @@ } }, { - "id": "get-upstream", - "type": "get-upstream", + "id": "get-dependency", + "type": "get-dependency", "parameters": { "target": "$params.target" } @@ -30,12 +30,12 @@ "type": "merge-branches", "parameters": { "source": "$params.target", - "upstreamBranches": ["$actions['get-upstream'].outputs"], + "dependencyBranches": ["$actions['get-dependency'].outputs"], "mergeMessageTemplate": "Merge '{}' to $($params.target)", "commitMappingOverride": "$recursionContext.result.override" } }, - { + { "type": "add-diagnostic", "condition": "$actions.mergeBranches.outputs.failed -ne $null", "parameters": { diff --git a/git-pull-upstream.tests.ps1 b/git-pull-deps.tests.ps1 similarity index 88% rename from git-pull-upstream.tests.ps1 rename to git-pull-deps.tests.ps1 index 51849b1..a3bca29 100755 --- a/git-pull-upstream.tests.ps1 +++ b/git-pull-deps.tests.ps1 @@ -6,7 +6,7 @@ BeforeAll { Import-Module -Scope Local "$PSScriptRoot/utils/actions.mocks.psm1" } -Describe 'git-pull-upstream' { +Describe 'git-pull-deps' { BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework @@ -18,7 +18,7 @@ Describe 'git-pull-upstream' { Initialize-NoCurrentBranch ) - { & ./git-pull-upstream.ps1 } | Should -Throw + { & ./git-pull-deps.ps1 } | Should -Throw $fw.assertDiagnosticOutput | Should -Contain "ERR: No branch name was provided" Invoke-VerifyMock $mocks -Times 1 } @@ -30,7 +30,7 @@ Describe 'git-pull-upstream' { Initialize-LocalActionAssertExistence -branches @('feature/FOO-123') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/FOO-123' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('infra/add-services') -resultCommitish 'result-commitish' ` + -dependencyBranches @('infra/add-services') -resultCommitish 'result-commitish' ` -source 'feature/FOO-123' ` -mergeMessageTemplate "Merge '{}' to feature/FOO-123" Initialize-FinalizeActionSetBranches @{ @@ -39,19 +39,19 @@ Describe 'git-pull-upstream' { Initialize-FinalizeActionTrackSuccess @('feature/FOO-123') -currentBranchDirty ) - { & $PSScriptRoot/git-pull-upstream.ps1 } | Should -Throw + { & $PSScriptRoot/git-pull-deps.ps1 } | Should -Throw $fw.assertDiagnosticOutput | Should -Be @('ERR: Git working directory is not clean.') Invoke-VerifyMock $mocks -Times 1 } - It 'merges all upstream branches for the current branch' { + It 'merges all dependency branches for the current branch' { $mocks = @( Initialize-AssertValidBranchName 'feature/FOO-456' Initialize-CurrentBranch 'feature/FOO-456' Initialize-LocalActionAssertExistence -branches @('feature/FOO-456') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/FOO-456' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('infra/add-services', 'infra/refactor-api') -resultCommitish 'result-commitish' ` + -dependencyBranches @('infra/add-services', 'infra/refactor-api') -resultCommitish 'result-commitish' ` -source 'feature/FOO-456' ` -mergeMessageTemplate "Merge '{}' to feature/FOO-456" Initialize-FinalizeActionSetBranches @{ @@ -60,19 +60,19 @@ Describe 'git-pull-upstream' { Initialize-FinalizeActionTrackSuccess @('feature/FOO-456') ) - & $PSScriptRoot/git-pull-upstream.ps1 + & $PSScriptRoot/git-pull-deps.ps1 $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - It "merges upstream branches for the specified branch when an upstream branch cannot be merged" { + It "merges dependency branches for the specified branch when an dependency branch cannot be merged" { $mocks = @( Initialize-AssertValidBranchName 'feature/FOO-456' Initialize-CurrentBranch 'feature/FOO-456' Initialize-LocalActionAssertExistence -branches @('feature/FOO-456') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/FOO-456' Initialize-LocalActionMergeBranchesSuccess ` - -upstreamBranches @('infra/add-services', 'infra/refactor-api') -resultCommitish 'result-commitish' ` + -dependencyBranches @('infra/add-services', 'infra/refactor-api') -resultCommitish 'result-commitish' ` -failedBranches 'infra/refactor-api' ` -source 'feature/FOO-456' ` -mergeMessageTemplate "Merge '{}' to feature/FOO-456" @@ -82,7 +82,7 @@ Describe 'git-pull-upstream' { Initialize-FinalizeActionTrackSuccess @('feature/FOO-456') ) - & $PSScriptRoot/git-pull-upstream.ps1 + & $PSScriptRoot/git-pull-deps.ps1 $fw.assertDiagnosticOutput | Should -Be @( "WARN: feature/FOO-456 has incoming conflicts from infra/refactor-api. Resolve them before continuing." ) @@ -104,7 +104,7 @@ Describe 'git-pull-upstream' { Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') 'feature/PS-1' = @('infra/ts-update') 'infra/build-improvements' = @('infra/ts-update') @@ -116,28 +116,28 @@ Describe 'git-pull-upstream' { Initialize-LocalActionAssertPushedSuccess 'main' Initialize-LocalActionMergeBranches ` - -upstreamBranches @('main') ` + -dependencyBranches @('main') ` -noChangeBranches @('main') ` -resultCommitish $initialCommits["$($remotePrefix)infra/ts-update"] ` -source 'infra/ts-update' ` -initialCommits $initialCommits ` -mergeMessageTemplate "Merge '{}' to infra/ts-update" Initialize-LocalActionMergeBranches ` - -upstreamBranches @('infra/ts-update') ` + -dependencyBranches @('infra/ts-update') ` -noChangeBranches @('infra/ts-update') ` -resultCommitish $initialCommits["$($remotePrefix)infra/build-improvements"] ` -source 'infra/build-improvements' ` -initialCommits $initialCommits ` -mergeMessageTemplate "Merge '{}' to infra/build-improvements" Initialize-LocalActionMergeBranches ` - -upstreamBranches @('infra/ts-update') ` + -dependencyBranches @('infra/ts-update') ` -noChangeBranches @('infra/ts-update') ` -resultCommitish $initialCommits["$($remotePrefix)feature/PS-1"] ` -source 'feature/PS-1' ` -initialCommits $initialCommits ` -mergeMessageTemplate "Merge '{}' to feature/PS-1" Initialize-LocalActionMergeBranches ` - -upstreamBranches @('feature/PS-1','infra/build-improvements') ` + -dependencyBranches @('feature/PS-1','infra/build-improvements') ` -noChangeBranches @('feature/PS-1','infra/build-improvements') ` -resultCommitish $initialCommits["$($remotePrefix)feature/PS-2"] ` -source 'feature/PS-2' ` @@ -145,7 +145,7 @@ Describe 'git-pull-upstream' { -mergeMessageTemplate "Merge '{}' to feature/PS-2" ) - & $PSScriptRoot/git-pull-upstream.ps1 -target feature/PS-2 -recurse + & $PSScriptRoot/git-pull-deps.ps1 -target feature/PS-2 -recurse Invoke-VerifyMock $mocks -Times 1 } @@ -167,7 +167,7 @@ Describe 'git-pull-upstream' { Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') 'feature/PS-1' = @('main') 'infra/build-improvements' = @('main') @@ -177,21 +177,21 @@ Describe 'git-pull-upstream' { Initialize-LocalActionAssertPushedSuccess 'main' Initialize-LocalActionMergeBranches ` - -upstreamBranches @('main') ` + -dependencyBranches @('main') ` -successfulBranches @('main') ` -resultCommitish $updatedCommits["$($remotePrefix)feature/PS-1"] ` -source 'feature/PS-1' ` -initialCommits $initialCommits ` -mergeMessageTemplate "Merge '{}' to feature/PS-1" Initialize-LocalActionMergeBranches ` - -upstreamBranches @('main') ` + -dependencyBranches @('main') ` -noChangeBranches @('main') ` -resultCommitish $initialCommits["$($remotePrefix)infra/build-improvements"] ` -source 'infra/build-improvements' ` -initialCommits $initialCommits ` -mergeMessageTemplate "Merge '{}' to infra/build-improvements" Initialize-LocalActionMergeBranches ` - -upstreamBranches @('feature/PS-1','infra/build-improvements') ` + -dependencyBranches @('feature/PS-1','infra/build-improvements') ` -successfulBranches @('feature/PS-1') ` -noChangeBranches @('infra/build-improvements') ` -resultCommitish $updatedCommits["$($remotePrefix)feature/PS-2"] ` @@ -206,7 +206,7 @@ Describe 'git-pull-upstream' { "$($remotePrefix)feature/PS-1" ) ` -mergeMessageTemplate "Merge '{}' to feature/PS-2" - + Initialize-CurrentBranch 'feature/FOO-456' Initialize-FinalizeActionSetBranches @{ 'feature/PS-1' = $updatedCommits["$($remotePrefix)feature/PS-1"] @@ -215,11 +215,11 @@ Describe 'git-pull-upstream' { Initialize-FinalizeActionTrackSuccess @('infra/build-improvements', 'feature/PS-1','feature/PS-2') ) - & $PSScriptRoot/git-pull-upstream.ps1 -target feature/PS-2 -recurse + & $PSScriptRoot/git-pull-deps.ps1 -target feature/PS-2 -recurse Invoke-VerifyMock $mocks -Times 1 } - - It 'uses the branch specified, recursively, and fails if an upstream merge fails' { + + It 'uses the branch specified, recursively, and fails if an dependency merge fails' { # Fails merging 'main' into 'infra/build-improvements' $remote = $(Get-Configuration).remote $remotePrefix = $remote ? "$remote/" : "" @@ -238,7 +238,7 @@ Describe 'git-pull-upstream' { Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') 'feature/PS-1' = @('main') 'infra/build-improvements' = @('main') @@ -248,21 +248,21 @@ Describe 'git-pull-upstream' { Initialize-LocalActionAssertPushedSuccess 'main' Initialize-LocalActionMergeBranches ` - -upstreamBranches @('main') ` + -dependencyBranches @('main') ` -successfulBranches @('main') ` -resultCommitish $updatedCommits["$($remotePrefix)feature/PS-1"] ` -source 'feature/PS-1' ` -initialCommits $initialCommits ` -mergeMessageTemplate "Merge '{}' to feature/PS-1" Initialize-LocalActionMergeBranches ` - -upstreamBranches @('main') ` + -dependencyBranches @('main') ` -resultCommitish $initialCommits["$($remotePrefix)infra/build-improvements"] ` -source 'infra/build-improvements' ` -initialCommits $initialCommits ` -mergeMessageTemplate "Merge '{}' to infra/build-improvements" ) - { & $PSScriptRoot/git-pull-upstream.ps1 -target feature/PS-2 -recurse } | Should -Throw + { & $PSScriptRoot/git-pull-deps.ps1 -target feature/PS-2 -recurse } | Should -Throw $fw.assertDiagnosticOutput | Should -Contain 'ERR: infra/build-improvements has incoming conflicts from main. Resolve them before continuing.' Invoke-VerifyMock $mocks -Times 1 } @@ -272,7 +272,7 @@ Describe 'git-pull-upstream' { BeforeEach { Initialize-ToolConfiguration Initialize-UpdateGitRemote - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-456' = @("infra/add-services", "infra/refactor-api") 'feature/FOO-123' = @("infra/add-services") 'infra/add-services' = @("main") @@ -290,7 +290,7 @@ Describe 'git-pull-upstream' { Initialize-LocalActionAssertPushedAhead 'feature/FOO-456' ) - { & $PSScriptRoot/git-pull-upstream.ps1 } | Should -Throw + { & $PSScriptRoot/git-pull-deps.ps1 } | Should -Throw $fw.assertDiagnosticOutput | Should -Be @('ERR: The local branch for feature/FOO-456 has changes that are not pushed to the remote') Invoke-VerifyMock $mocks -Times 1 } @@ -302,7 +302,7 @@ Describe 'git-pull-upstream' { Initialize-LocalActionAssertPushedAhead 'feature/FOO-456' ) - { & $PSScriptRoot/git-pull-upstream.ps1 'feature/FOO-456' } | Should -Throw + { & $PSScriptRoot/git-pull-deps.ps1 'feature/FOO-456' } | Should -Throw $fw.assertDiagnosticOutput | Should -Be @('ERR: The local branch for feature/FOO-456 has changes that are not pushed to the remote') Invoke-VerifyMock $mocks -Times 1 } @@ -311,7 +311,7 @@ Describe 'git-pull-upstream' { Context 'without a remote' { BeforeEach { Initialize-ToolConfiguration -noRemote - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-456' = @("infra/add-services", "infra/refactor-api") 'feature/FOO-123' = @("infra/add-services") 'infra/add-services' = @("main") diff --git a/git-rc.json b/git-rc.json index 08a8051..5da91e2 100644 --- a/git-rc.json +++ b/git-rc.json @@ -3,7 +3,7 @@ { "type": "validate-branch-names", "parameters": { - "branches": ["$params.branchName", "$params.upstreamBranches"] + "branches": ["$params.branchName", "$params.dependencyBranches"] } }, { @@ -17,31 +17,31 @@ { "type": "assert-existence", "parameters": { - "branches": ["$params.upstreamBranches"], + "branches": ["$params.dependencyBranches"], "shouldExist": true } }, { - "id": "simplify-upstream", - "type": "simplify-upstream", + "id": "simplify-dependency", + "type": "simplify-dependency", "parameters": { - "upstreamBranches": ["$params.upstreamBranches"] + "dependencyBranches": ["$params.dependencyBranches"] } }, { "id": "updated-status", - "type": "upstreams-updated", + "type": "dependencies-updated", "parameters": { "recurse": true, - "branches": ["$actions['simplify-upstream'].outputs"] + "branches": ["$actions['simplify-dependency'].outputs"] } }, { "type": "add-diagnostic", - "condition": "$actions['updated-status'].outputs['noUpstreams'].Count -gt 0", + "condition": "$actions['updated-status'].outputs['noDependencies'].Count -gt 0", "parameters": { - "isWarning": "$params.allowNoUpstreams ? $false : $true", - "message": "The following branches have no upstreams:\n$(($actions['updated-status'].outputs['noUpstreams'] | ForEach-Object { \"- $_\" }) -join \"\n\")" + "isWarning": "$params.allowNoDependencies ? $false : $true", + "message": "The following branches have no dependencies:\n$(($actions['updated-status'].outputs['noDependencies'] | ForEach-Object { \"- $_\" }) -join \"\n\")" } }, { @@ -49,15 +49,15 @@ "condition": "$actions['updated-status'].outputs['needsUpdate'].Keys.Count -gt 0", "parameters": { "isWarning": "$params.allowOutOfDate ? $false : $true", - "message": "The following branches are missing commits from their upstreams:\n$(($actions['updated-status'].outputs['needsUpdate'].Keys | ForEach-Object { \"- $_\" }) -join \"\n\")" + "message": "The following branches are missing commits from their dependencies:\n$(($actions['updated-status'].outputs['needsUpdate'].Keys | ForEach-Object { \"- $_\" }) -join \"\n\")" } }, { - "id": "set-upstream", - "type": "set-upstream", + "id": "set-dependency", + "type": "set-dependency", "parameters": { - "upstreamBranches": { - "$params.branchName": ["$actions['simplify-upstream'].outputs"] + "dependencyBranches": { + "$params.branchName": ["$actions['simplify-dependency'].outputs"] }, "message": "Add branch $($params.branchName)$($params.comment ? \" for $($params.comment)\" : '')" } @@ -66,7 +66,7 @@ "id": "create-branch", "type": "merge-branches", "parameters": { - "upstreamBranches": ["$actions['simplify-upstream'].outputs"], + "dependencyBranches": ["$actions['simplify-dependency'].outputs"], "mergeMessageTemplate": "Merge '{}' for creation of $($params.branchName)", "errorOnFailure": true } @@ -78,7 +78,7 @@ "parameters": { "force": "$params.force", "branches": { - "$config.upstreamBranch": "$actions['set-upstream'].outputs['commit']", + "$config.dependencyBranch": "$actions['set-dependency'].outputs['commit']", "$params.branchName": "$actions['create-branch'].outputs['commit']" } } diff --git a/git-rc.ps1 b/git-rc.ps1 index e59457d..dd6b301 100755 --- a/git-rc.ps1 +++ b/git-rc.ps1 @@ -2,11 +2,11 @@ Param( [Parameter(Mandatory)][string] $target, - [Parameter()][Alias('u')][Alias('upstream')][Alias('upstreams')][String[]] $upstreamBranches, + [Parameter()][Alias('d')][Alias('dependency')][Alias('dependencies')][String[]] $dependencyBranches, [Parameter()][Alias('message')][Alias('m')][string] $comment, [switch] $force, [switch] $allowOutOfDate, - [switch] $allowNoUpstreams, + [switch] $allowNoDependencies, [switch] $dryRun ) @@ -15,9 +15,9 @@ Import-Module -Scope Local "$PSScriptRoot/utils/scripting.psm1" Invoke-JsonScript -scriptPath "$PSScriptRoot/git-rc.json" -params @{ branchName = $target; - upstreamBranches = Expand-StringArray $upstreamBranches; + dependencyBranches = Expand-StringArray $dependencyBranches; force = [boolean]$force; allowOutOfDate = [boolean]$allowOutOfDate; - allowNoUpstreams = [boolean]$allowNoUpstreams; + allowNoDependencies = [boolean]$allowNoDependencies; comment = $comment ?? ''; } -dryRun:$dryRun diff --git a/git-rc.tests.ps1 b/git-rc.tests.ps1 index a2d262a..799709e 100755 --- a/git-rc.tests.ps1 +++ b/git-rc.tests.ps1 @@ -7,16 +7,16 @@ Describe 'git-rc' { Import-Module -Scope Local "$PSScriptRoot/utils/git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/actions.mocks.psm1" } - + BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework -throwInsteadOfExit } - + Context 'without remote' { BeforeAll { Initialize-ToolConfiguration -noRemote - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/FOO-124-comment' = @('main') 'integrate/FOO-125_XYZ-1' = @('feature/FOO-125', 'feature/XYZ-1') @@ -32,21 +32,21 @@ Describe 'git-rc' { Initialize-AssertValidBranchName 'integrate/FOO-125_XYZ-1' Initialize-LocalActionAssertExistence -branches @('rc/2022-07-28') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') - Initialize-LocalActionUpstreamsUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionDependenciesUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse + Initialize-LocalActionSetDependency @{ 'rc/2022-07-28' = @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') } -commitish 'new-commit' -message 'Add branch rc/2022-07-28 for New RC' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2022-07-28" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-28' = 'result-rc-commit' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-28') -untracked @('rc/2022-07-28') ) - & $PSScriptRoot/git-rc.ps1 -upstreamBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' + & $PSScriptRoot/git-rc.ps1 -dependencyBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -57,7 +57,7 @@ Describe 'git-rc' { Initialize-ToolConfiguration Initialize-UpdateGitRemote Initialize-NoCurrentBranch - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/FOO-124-comment' = @('main') 'feature/FOO-125' = @('main') @@ -74,21 +74,21 @@ Describe 'git-rc' { Initialize-AssertValidBranchName 'integrate/FOO-125_XYZ-1' Initialize-LocalActionAssertExistence -branches @('rc/2022-07-28') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') - Initialize-LocalActionUpstreamsUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionDependenciesUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse + Initialize-LocalActionSetDependency @{ 'rc/2022-07-28' = @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') } -commitish 'new-commit' -message 'Add branch rc/2022-07-28 for New RC' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2022-07-28" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-28' = 'result-rc-commit' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-28') -untracked @('rc/2022-07-28') ) - & $PSScriptRoot/git-rc.ps1 -upstreamBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' + & $PSScriptRoot/git-rc.ps1 -dependencyBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } @@ -101,26 +101,26 @@ Describe 'git-rc' { Initialize-AssertValidBranchName 'integrate/FOO-125_XYZ-1' Initialize-LocalActionAssertExistence -branches @('rc/2022-07-28') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') - Initialize-LocalActionUpstreamsUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionDependenciesUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse + Initialize-LocalActionSetDependency @{ 'rc/2022-07-28' = @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') } -commitish 'new-commit' -message 'Add branch rc/2022-07-28' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2022-07-28" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-28' = 'result-rc-commit' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-28') -untracked @('rc/2022-07-28') ) - & $PSScriptRoot/git-rc.ps1 -upstreamBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m $nil -target 'rc/2022-07-28' + & $PSScriptRoot/git-rc.ps1 -dependencyBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m $nil -target 'rc/2022-07-28' $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - It 'simplifies upstream before creating the rc' { + It 'simplifies dependency before creating the rc' { $mocks = @( Initialize-AssertValidBranchName 'rc/2022-07-28' Initialize-AssertValidBranchName 'feature/FOO-123' @@ -129,21 +129,21 @@ Describe 'git-rc' { Initialize-AssertValidBranchName 'integrate/FOO-125_XYZ-1' Initialize-LocalActionAssertExistence -branches @('rc/2022-07-28') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('feature/FOO-123','feature/FOO-125','feature/XYZ-1','integrate/FOO-125_XYZ-1') - Initialize-LocalActionUpstreamsUpdated @('feature/FOO-123','integrate/FOO-125_XYZ-1') -recurse - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionDependenciesUpdated @('feature/FOO-123','integrate/FOO-125_XYZ-1') -recurse + Initialize-LocalActionSetDependency @{ 'rc/2022-07-28' = @('feature/FOO-123','integrate/FOO-125_XYZ-1') } -commitish 'new-commit' -message 'Add branch rc/2022-07-28 for New RC' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-123','integrate/FOO-125_XYZ-1') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2022-07-28" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-28' = 'result-rc-commit' } Initialize-FinalizeActionTrackSuccess @('rc/2022-07-28') -untracked @('rc/2022-07-28') ) - & $PSScriptRoot/git-rc.ps1 -upstreamBranches feature/FOO-123,feature/FOO-125,feature/XYZ-1,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' + & $PSScriptRoot/git-rc.ps1 -dependencyBranches feature/FOO-123,feature/FOO-125,feature/XYZ-1,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' $fw.assertDiagnosticOutput | Should -Be @("WARN: Removing 'feature/FOO-125' from branches; it is redundant via the following: integrate/FOO-125_XYZ-1", "WARN: Removing 'feature/XYZ-1' from branches; it is redundant via the following: integrate/FOO-125_XYZ-1") Invoke-VerifyMock $mocks -Times 1 } @@ -156,8 +156,8 @@ Describe 'git-rc' { Initialize-AssertValidBranchName 'integrate/FOO-125_XYZ-1' Initialize-LocalActionAssertExistence -branches @('rc/2022-07-28') -shouldExist $false Initialize-LocalActionAssertExistence -branches @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') - Initialize-LocalActionUpstreamsUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionDependenciesUpdated @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') -recurse + Initialize-LocalActionSetDependency @{ 'rc/2022-07-28' = @('feature/FOO-123','feature/FOO-124-comment','integrate/FOO-125_XYZ-1') } -commitish 'new-commit' -message 'Add branch rc/2022-07-28 for new RC' Initialize-LocalActionMergeBranchesSuccess ` @@ -166,7 +166,7 @@ Describe 'git-rc' { -mergeMessageTemplate "Merge '{}' for creation of rc/2022-07-28" ) - { & $PSScriptRoot/git-rc.ps1 -upstreamBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' } | Should -Throw + { & $PSScriptRoot/git-rc.ps1 -dependencyBranches feature/FOO-123,feature/FOO-124-comment,integrate/FOO-125_XYZ-1 -m 'New RC' -target 'rc/2022-07-28' } | Should -Throw $fw.assertDiagnosticOutput | Should -Be @("ERR: Could not merge the following branches: origin/feature/FOO-124-comment") Invoke-VerifyMock $mocks -Times 1 } diff --git a/git-rebuild-rc.json b/git-rebuild-rc.json index e0b3f93..9ebdcf7 100644 --- a/git-rebuild-rc.json +++ b/git-rebuild-rc.json @@ -14,41 +14,41 @@ } }, { - "id": "get-upstream", - "type": "get-upstream", + "id": "get-dependency", + "type": "get-dependency", "parameters": { "target": "$params.target" } }, { - "id": "filtered-upstream", + "id": "filtered-dependency", "type": "filter-branches", "parameters": { - "include": ["$actions['get-upstream'].outputs", "$params.with"], + "include": ["$actions['get-dependency'].outputs", "$params.with"], "exclude": ["$params.without"] } }, { - "id": "simplify-upstream", - "type": "simplify-upstream", + "id": "simplify-dependency", + "type": "simplify-dependency", "parameters": { - "upstreamBranches": ["$actions['filtered-upstream'].outputs"] + "dependencyBranches": ["$actions['filtered-dependency'].outputs"] } }, { "id": "updated-status", - "type": "upstreams-updated", + "type": "dependencies-updated", "parameters": { "recurse": true, - "branches": ["$actions['simplify-upstream'].outputs"] + "branches": ["$actions['simplify-dependency'].outputs"] } }, { "type": "add-diagnostic", - "condition": "$actions['updated-status'].outputs['noUpstreams'].Count -gt 0", + "condition": "$actions['updated-status'].outputs['noDependencies'].Count -gt 0", "parameters": { - "isWarning": "$params.allowNoUpstreams ? $false : $true", - "message": "The following branches have no upstreams:\n$(($actions['updated-status'].outputs['noUpstreams'] | ForEach-Object { \"- $_\" }) -join \"\n\")" + "isWarning": "$params.allowNoDependencies ? $false : $true", + "message": "The following branches have no dependencies:\n$(($actions['updated-status'].outputs['noDependencies'] | ForEach-Object { \"- $_\" }) -join \"\n\")" } }, { @@ -56,15 +56,15 @@ "condition": "$actions['updated-status'].outputs['needsUpdate'].Keys.Count -gt 0", "parameters": { "isWarning": "$params.allowOutOfDate ? $false : $true", - "message": "The following branches are missing commits from their upstreams:\n$(($actions['updated-status'].outputs['needsUpdate'].Keys | ForEach-Object { \"- $_\" }) -join \"\n\")" + "message": "The following branches are missing commits from their dependencies:\n$(($actions['updated-status'].outputs['needsUpdate'].Keys | ForEach-Object { \"- $_\" }) -join \"\n\")" } }, { - "id": "set-upstream", - "type": "set-upstream", + "id": "set-dependency", + "type": "set-dependency", "parameters": { - "upstreamBranches": { - "$params.target": ["$actions['simplify-upstream'].outputs"] + "dependencyBranches": { + "$params.target": ["$actions['simplify-dependency'].outputs"] }, "message": "Revise branch $($params.target)$($params.comment ? \" for $($params.comment)\" : '')" } @@ -73,7 +73,7 @@ "id": "create-branch", "type": "merge-branches", "parameters": { - "upstreamBranches": ["$actions['simplify-upstream'].outputs"], + "dependencyBranches": ["$actions['simplify-dependency'].outputs"], "mergeMessageTemplate": "Merge '{}' for creation of $($params.target)", "errorOnFailure": true } @@ -85,7 +85,7 @@ "parameters": { "force": true, "branches": { - "$config.upstreamBranch": "$actions['set-upstream'].outputs['commit']", + "$config.dependencyBranch": "$actions['set-dependency'].outputs['commit']", "$params.target": "$actions['create-branch'].outputs['commit']" } } diff --git a/git-rebuild-rc.ps1 b/git-rebuild-rc.ps1 index d8aed98..deb6315 100755 --- a/git-rebuild-rc.ps1 +++ b/git-rebuild-rc.ps1 @@ -2,11 +2,11 @@ Param( [Parameter(Mandatory)][string] $target, - [Parameter()][Alias('add')][Alias('addUpstream')][Alias('upstreamBranches')][String[]] $with, - [Parameter()][Alias('remove')][Alias('removeUpstream')][String[]] $without, + [Parameter()][Alias('add')][Alias('addDependency')][Alias('dependencyBranches')][String[]] $with, + [Parameter()][Alias('remove')][Alias('removeDependency')][String[]] $without, [Parameter()][Alias('message')][Alias('m')][string] $comment, [switch] $allowOutOfDate, - [switch] $allowNoUpstreams, + [switch] $allowNoDependencies, [switch] $dryRun ) @@ -18,6 +18,6 @@ Invoke-JsonScript -scriptPath "$PSScriptRoot/git-rebuild-rc.json" -params @{ with = Expand-StringArray $with; without = Expand-StringArray $without; allowOutOfDate = [boolean]$allowOutOfDate; - allowNoUpstreams = [boolean]$allowNoUpstreams; + allowNoDependencies = [boolean]$allowNoDependencies; comment = $comment ?? ''; } -dryRun:$dryRun diff --git a/git-rebuild-rc.tests.ps1 b/git-rebuild-rc.tests.ps1 index 4683870..a569f2a 100755 --- a/git-rebuild-rc.tests.ps1 +++ b/git-rebuild-rc.tests.ps1 @@ -10,11 +10,11 @@ Describe 'git-rebuild-rc' { BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework - + Function Initialize-DefaultMocks { Initialize-UpdateGitRemote Initialize-NoCurrentBranch - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/FOO-124-comment' = @('main') 'integrate/FOO-125_XYZ-1' = @('feature/FOO-125', 'feature/XYZ-1') @@ -29,7 +29,7 @@ Describe 'git-rebuild-rc' { Initialize-AssertValidBranchName 'feature/XYZ-1' Initialize-AssertValidBranchName 'rc/2023-11-08' Initialize-AssertValidBranchName 'main' - Initialize-LocalActionUpstreamsUpdated @( + Initialize-LocalActionDependenciesUpdated @( 'feature/FOO-123' 'feature/FOO-124-comment' 'integrate/FOO-125_XYZ-1' @@ -54,14 +54,14 @@ Describe 'git-rebuild-rc' { Function Add-StandardTests { It 'can simply rebuild the branch' { $mocks = @( - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2023-11-08' = @('feature/FOO-123', 'feature/FOO-125') } -commitish 'new-commit' -message 'Revise branch rc/2023-11-08' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-123', 'feature/FOO-125') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2023-11-08" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2023-11-08' = 'result-rc-commit' } -force Initialize-FinalizeActionTrackSuccess @('rc/2023-11-08') -untracked @('rc/2023-11-08') @@ -71,17 +71,17 @@ Describe 'git-rebuild-rc' { $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - - It 'can add an upstream' { + + It 'can add an dependency' { $mocks = @( - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2023-11-08' = @('feature/FOO-123', 'feature/FOO-125', 'feature/FOO-124-comment') } -commitish 'new-commit' -message 'Revise branch rc/2023-11-08' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-123', 'feature/FOO-125', 'feature/FOO-124-comment') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2023-11-08" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2023-11-08' = 'result-rc-commit' } -force Initialize-FinalizeActionTrackSuccess @('rc/2023-11-08') -untracked @('rc/2023-11-08') @@ -91,17 +91,17 @@ Describe 'git-rebuild-rc' { $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - + It 'can add an integration branch and simplify' { $mocks = @( - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2023-11-08' = @('feature/FOO-123', 'integrate/FOO-125_XYZ-1') } -commitish 'new-commit' -message 'Revise branch rc/2023-11-08' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-123', 'integrate/FOO-125_XYZ-1') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2023-11-08" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2023-11-08' = 'result-rc-commit' } -force Initialize-FinalizeActionTrackSuccess @('rc/2023-11-08') -untracked @('rc/2023-11-08') @@ -114,14 +114,14 @@ Describe 'git-rebuild-rc' { It 'can remove a branch' { $mocks = @( - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'rc/2023-11-08' = @('feature/FOO-125') } -commitish 'new-commit' -message 'Revise branch rc/2023-11-08' Initialize-LocalActionMergeBranchesSuccess ` @('feature/FOO-125') 'result-rc-commit' ` -mergeMessageTemplate "Merge '{}' for creation of rc/2023-11-08" Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2023-11-08' = 'result-rc-commit' } -force Initialize-FinalizeActionTrackSuccess @('rc/2023-11-08') -untracked @('rc/2023-11-08') diff --git a/git-refactor-upstream.json b/git-refactor-deps.json similarity index 67% rename from git-refactor-upstream.json rename to git-refactor-deps.json index f5eb413..8ad9ed6 100644 --- a/git-refactor-upstream.json +++ b/git-refactor-deps.json @@ -21,21 +21,21 @@ } }, { - "type": "get-all-upstreams", - "id": "originalUpstreams", + "type": "get-all-dependencies", + "id": "originalDependencies", "parameters": {} }, { - "type": "get-downstream", - "id": "sourceDownstreams", + "type": "get-dependants", + "id": "sourceDependants", "parameters": { "target": "$params.source", "recurse": true } }, { - "type": "get-downstream", - "id": "targetDownstreams", + "type": "get-dependants", + "id": "targetDependants", "parameters": { "target": "$params.target", "recurse": true @@ -46,15 +46,15 @@ "type": "filter-branches", "condition": "$params.rename -OR $params.combine", "parameters": { - "include": ["$params.combine ? $actions.originalUpstreams.outputs[$params.target] : @()", "$actions.originalUpstreams.outputs[$params.source]"], + "include": ["$params.combine ? $actions.originalDependencies.outputs[$params.target] : @()", "$actions.originalDependencies.outputs[$params.source]"], "exclude": ["$params.source", "$params.target"] } }, { - "id": "alteredUpstreams", + "id": "alteredDependencies", "type": "evaluate", "parameters": { - "result": "$actions.originalUpstreams.outputs + @{}" + "result": "$actions.originalDependencies.outputs + @{}" } }, { @@ -62,18 +62,18 @@ "type": "evaluate", "condition": "$params.rename -OR $params.combine", "parameters": { - "result": "$actions.alteredUpstreams.outputs[$params.target] = [string[]]$actions.filterRename.outputs" + "result": "$actions.alteredDependencies.outputs[$params.target] = [string[]]$actions.filterRename.outputs" } }, { - "id": "upstreamResult", - // This is not truly a recursive script, but a loop to compute the upstream branches that should change + "id": "dependencyResult", + // This is not truly a recursive script, but a loop to compute the dependency branches that should change "type": "recurse", "parameters": { "inputParameters": [ - "$actions.alteredUpstreams.outputs.Keys | ForEach-Object { @{ target = $params.target; source = $params.source; current = $_; upstream = $actions.alteredUpstreams.outputs[$_] } }" + "$actions.alteredDependencies.outputs.Keys | ForEach-Object { @{ target = $params.target; source = $params.source; current = $_; dependency = $actions.alteredDependencies.outputs[$_] } }" ], - "path": "git-refactor-upstream.loop.1.json" + "path": "git-refactor-deps.loop.1.json" } }, { @@ -82,26 +82,26 @@ "parameters": { "result": [ "$params.target", - "$actions.sourceDownstreams.outputs", - "$params.rename -OR $params.combine ? $actions.targetDownstreams.outputs : @()" + "$actions.sourceDependants.outputs", + "$params.rename -OR $params.combine ? $actions.targetDependants.outputs : @()" ] } }, { "id": "simplifyAll", - // This is not truly a recursive script, but a loop to compute the upstream branches that should change + // This is not truly a recursive script, but a loop to compute the dependency branches that should change "type": "recurse", "parameters": { "inputParameters": [ - "$actions.affected.outputs | Where-Object { $_ } | ForEach-Object { @{ current = $_; original = $actions.originalUpstreams.outputs[$_]; upstream = $actions.upstreamResult.outputs[$_] ?? $actions.alteredUpstreams.outputs[$_]; override = $actions.upstreamResult.outputs } }" + "$actions.affected.outputs | Where-Object { $_ } | ForEach-Object { @{ current = $_; original = $actions.originalDependencies.outputs[$_]; dependency = $actions.dependencyResult.outputs[$_] ?? $actions.alteredDependencies.outputs[$_]; override = $actions.dependencyResult.outputs } }" ], - "path": "git-refactor-upstream.loop.2.json" + "path": "git-refactor-deps.loop.2.json" } }, { "id": "remove", "type": "evaluate", - "condition": "$actions.simplifyAll.outputs[$params.source] -OR $actions.upstreamResult.outputs[$params.source]", + "condition": "$actions.simplifyAll.outputs[$params.source] -OR $actions.dependencyResult.outputs[$params.source]", "parameters": { "result": "$actions.simplifyAll.outputs[$params.source] = $null" } @@ -114,10 +114,10 @@ } }, { - "id": "upstreamHash", - "type": "set-upstream", + "id": "dependencyHash", + "type": "set-dependency", "parameters": { - "upstreamBranches": "$actions.simplifyAll.outputs", + "dependencyBranches": "$actions.simplifyAll.outputs", "message": "Rewrite $($params.source) to $($params.target)$($params.comment -eq '' ? '' : \" for $($params.comment)\")" } } @@ -127,12 +127,12 @@ "type": "set-branches", "parameters": { "branches": { - "$config.upstreamBranch": "$actions.upstreamHash.outputs.commit" + "$config.dependencyBranch": "$actions.dependencyHash.outputs.commit" } } } ], "output": [ - "$($params.source) has been replaced with $(params.target) in the following branches: $($actions.upstreamResult.outputs.Keys)" + "$($params.source) has been replaced with $(params.target) in the following branches: $($actions.dependencyResult.outputs.Keys)" ] } \ No newline at end of file diff --git a/git-refactor-upstream.loop.1.json b/git-refactor-deps.loop.1.json similarity index 76% rename from git-refactor-upstream.loop.1.json rename to git-refactor-deps.loop.1.json index ba28fc0..ce4c895 100644 --- a/git-refactor-upstream.loop.1.json +++ b/git-refactor-deps.loop.1.json @@ -11,14 +11,14 @@ "id": "filter", "type": "filter-branches", "parameters": { - "include": ["$params.upstream", "$params.target"], + "include": ["$params.dependency", "$params.target"], "exclude": ["$params.source", "$params.current"] } }, { "type": "evaluate", "parameters": { - "result": "$recursionContext.result.changes[$params.current] = ([string[]]($params.upstream) -contains $params.source) ? $actions.filter.outputs : $params.upstream" + "result": "$recursionContext.result.changes[$params.current] = ([string[]]($params.dependency) -contains $params.source) ? $actions.filter.outputs : $params.dependency" } } ] diff --git a/git-refactor-upstream.loop.2.json b/git-refactor-deps.loop.2.json similarity index 66% rename from git-refactor-upstream.loop.2.json rename to git-refactor-deps.loop.2.json index 809fb39..f838316 100644 --- a/git-refactor-upstream.loop.2.json +++ b/git-refactor-deps.loop.2.json @@ -9,16 +9,16 @@ "act": [ { "id": "simplify", - "type": "simplify-upstream", + "type": "simplify-dependency", "parameters": { - "upstreamBranches": ["$params.upstream"], - "overrideUpstreams": "$params.override", + "dependencyBranches": ["$params.dependency"], + "overrideDependencies": "$params.override", "branchName": "$params.current" } }, { "type": "evaluate", - "condition": "$params.upstream -AND ([string[]]$params.original -join ',') -ne ([string[]]$actions.simplify.outputs -join ',')", + "condition": "$params.dependency -AND ([string[]]$params.original -join ',') -ne ([string[]]$actions.simplify.outputs -join ',')", "parameters": { "result": "$recursionContext.result.changes[$params.current] = $actions.simplify.outputs" } diff --git a/git-refactor-upstream.ps1 b/git-refactor-deps.ps1 similarity index 86% rename from git-refactor-upstream.ps1 rename to git-refactor-deps.ps1 index 6160645..aad3e23 100755 --- a/git-refactor-upstream.ps1 +++ b/git-refactor-deps.ps1 @@ -13,7 +13,7 @@ Param( Import-Module -Scope Local "$PSScriptRoot/utils/input.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/scripting.psm1" -Invoke-JsonScript -scriptPath "$PSScriptRoot/git-refactor-upstream.json" -params @{ +Invoke-JsonScript -scriptPath "$PSScriptRoot/git-refactor-deps.json" -params @{ source = $source; target = $target; rename = $rename; diff --git a/git-refactor-upstream.tests.ps1 b/git-refactor-deps.tests.ps1 similarity index 71% rename from git-refactor-upstream.tests.ps1 rename to git-refactor-deps.tests.ps1 index d756289..ca40874 100755 --- a/git-refactor-upstream.tests.ps1 +++ b/git-refactor-deps.tests.ps1 @@ -1,4 +1,4 @@ -Describe 'git-refactor-upstream' { +Describe 'git-refactor-deps' { BeforeAll { . "$PSScriptRoot/utils/testing.ps1" Import-Module -Scope Local "$PSScriptRoot/utils/framework.mocks.psm1" @@ -13,7 +13,7 @@ Describe 'git-refactor-upstream' { Initialize-ToolConfiguration Initialize-UpdateGitRemote - + # These are all valid branch names; tehy don't need to be defined each time: Initialize-AssertValidBranchName 'integrate/FOO-100_XYZ-1' Initialize-AssertValidBranchName 'integrate/FOO-123_XYZ-1' @@ -30,14 +30,14 @@ Describe 'git-refactor-upstream' { } It 'prevents running if neither remove nor rename are provided' { - { & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-123' -target 'main' } | Should -Throw + { & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-123' -target 'main' } | Should -Throw $fw.assertDiagnosticOutput | Should -Contain 'ERR: One of -rename, -remove, or -combine must be specfied.' Invoke-VerifyMock $mocks -Times 1 } It 'prevents running if both remove and rename are provided' { - { & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-123' -target 'main' -remove -rename } | Should -Throw + { & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-123' -target 'main' -remove -rename } | Should -Throw $fw.assertDiagnosticOutput | Should -Contain 'ERR: Only one of -rename, -remove, and -combine may be specified.' Invoke-VerifyMock $mocks -Times 1 @@ -45,109 +45,109 @@ Describe 'git-refactor-upstream' { It 'can consolidate a released branch (feature/FOO-123) into main' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("integrate/FOO-123_XYZ-1") 'feature/FOO-123' = @("main") 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null 'integrate/FOO-123_XYZ-1' = @("feature/XYZ-1-services") } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-123' -target 'main' -remove + & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-123' -target 'main' -remove - $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from upstream branches of 'integrate/FOO-123_XYZ-1'; it is redundant via the following: feature/XYZ-1-services" + $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from dependency branches of 'integrate/FOO-123_XYZ-1'; it is redundant via the following: feature/XYZ-1-services" Invoke-VerifyMock $mocks -Times 1 } - It 'can consolidate an integration branch (integrate/FOO-123_XYZ-1) into its remaining upstream' { + It 'can consolidate an integration branch (integrate/FOO-123_XYZ-1) into its remaining dependency' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/XYZ-1-services") 'feature/FOO-124' = @("integrate/FOO-123_XYZ-1") 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-124' = @("feature/XYZ-1-services") 'rc/1.1.0' = @("feature/XYZ-1-services") 'integrate/FOO-123_XYZ-1' = @() } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'integrate/FOO-123_XYZ-1' -target 'feature/XYZ-1-services' -remove - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'integrate/FOO-123_XYZ-1' -target 'feature/XYZ-1-services' -remove + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } It 'can rename an incorrectly named branch' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-100_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("integrate/FOO-100_XYZ-1") 'feature/FOO-123' = @("main") 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-100_XYZ-1") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'integrate/FOO-100_XYZ-1' = @() 'feature/FOO-124' = @("integrate/FOO-123_XYZ-1") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'integrate/FOO-100_XYZ-1' -target 'integrate/FOO-123_XYZ-1' -rename - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'integrate/FOO-100_XYZ-1' -target 'integrate/FOO-123_XYZ-1' -rename + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } It 'can rename an incorrectly named branch already used correctly sometimes' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-100", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123", "main") 'feature/FOO-100' = @("main") 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-100' = @() 'feature/FOO-123' = @('main') 'feature/FOO-124' = @("feature/FOO-123") } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-100' -target 'feature/FOO-123' -rename - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-100' -target 'feature/FOO-123' -rename + $fw.assertDiagnosticOutput | Should -Be @( - "WARN: Removing 'main' from upstream branches of 'feature/FOO-124'; it is redundant via the following: feature/FOO-123" + "WARN: Removing 'main' from dependency branches of 'feature/FOO-124'; it is redundant via the following: feature/FOO-123" ) Invoke-VerifyMock $mocks -Times 1 } It 'can replace an incorrectly named branch that already has configurations' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-100", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123", "infra/shared") 'feature/FOO-123' = @("main", 'infra/other') @@ -156,27 +156,27 @@ Describe 'git-refactor-upstream' { 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-100' = @() 'feature/FOO-123' = @('infra/shared') 'feature/FOO-124' = @("feature/FOO-123") } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-100' -target 'feature/FOO-123' -rename - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-100' -target 'feature/FOO-123' -rename + $fw.assertDiagnosticOutput | Should -Be @( - "WARN: Removing 'infra/shared' from upstream branches of 'feature/FOO-124'; it is redundant via the following: feature/FOO-123" + "WARN: Removing 'infra/shared' from dependency branches of 'feature/FOO-124'; it is redundant via the following: feature/FOO-123" ) Invoke-VerifyMock $mocks -Times 1 } It 'can combine an incorrectly named branch that already has configurations' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-100", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123", "infra/shared") 'feature/FOO-123' = @("main", 'infra/other') @@ -185,29 +185,29 @@ Describe 'git-refactor-upstream' { 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-100' = @() 'feature/FOO-123' = @('infra/other', 'infra/shared') 'feature/FOO-124' = @("feature/FOO-123") } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-100' -target 'feature/FOO-123' -combine - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-100' -target 'feature/FOO-123' -combine + $fw.assertDiagnosticOutput | Should -Be @( - "WARN: Removing 'main' from upstream branches of 'feature/FOO-123'; it is redundant via the following: infra/shared" - "WARN: Removing 'infra/shared' from upstream branches of 'feature/FOO-124'; it is redundant via the following: feature/FOO-123" + "WARN: Removing 'main' from dependency branches of 'feature/FOO-123'; it is redundant via the following: infra/shared" + "WARN: Removing 'infra/shared' from dependency branches of 'feature/FOO-124'; it is redundant via the following: feature/FOO-123" ) Invoke-VerifyMock $mocks -Times 1 } It 'errors if no changes are made' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/XYZ-1-services") 'feature/FOO-124' = @("integrate/FOO-123_XYZ-1") 'feature/XYZ-1-services' = @("main") @@ -215,93 +215,93 @@ Describe 'git-refactor-upstream' { } ) - { & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-123' -target 'main' -remove } | Should -Throw + { & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-123' -target 'main' -remove } | Should -Throw $fw.assertDiagnosticOutput | Should -Contain "ERR: No changes were found." Invoke-VerifyMock $mocks -Times 1 } Describe 'Advanced use-cases' { - It 'simplifies other downstream branches' { + It 'simplifies other dependants branches' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-125' = @("feature/FOO-124", "main") 'feature/FOO-124' = @("feature/FOO-123") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-124' = @("main") 'feature/FOO-125' = @("feature/FOO-124") } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-123' -target 'main' -remove - - $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from upstream branches of 'feature/FOO-125'; it is redundant via the following: feature/FOO-124" + & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-123' -target 'main' -remove + + $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from dependency branches of 'feature/FOO-125'; it is redundant via the following: feature/FOO-124" Invoke-VerifyMock $mocks -Times 1 } It 'can be used to fix recursive branches' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'bad-recursive-branch-1' = @('bad-recursive-branch-2', 'main') 'bad-recursive-branch-2' = @('bad-recursive-branch-1') } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'bad-recursive-branch-1' = @("main") 'bad-recursive-branch-2' = @() } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'bad-recursive-branch-2' -target 'bad-recursive-branch-1' -remove - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'bad-recursive-branch-2' -target 'bad-recursive-branch-1' -remove + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } It 'can be used to fix recursive branches via combine' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'bad-recursive-branch-1' = @('bad-recursive-branch-2', 'main') 'bad-recursive-branch-2' = @('bad-recursive-branch-1') } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'bad-recursive-branch-1' = @("main") 'bad-recursive-branch-2' = @() } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'bad-recursive-branch-2' -target 'bad-recursive-branch-1' -combine - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'bad-recursive-branch-2' -target 'bad-recursive-branch-1' -combine + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - It 'does not create repeat upstreams' { + It 'does not create repeat dependencies' { $mocks = @( - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @("main") 'feature/FOO-124' = @("feature/FOO-123", "main") } - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null 'feature/FOO-124' = @("main") } -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - _upstream = 'new-commit' + '$dependencies' = 'new-commit' } ) - & $PSScriptRoot/git-refactor-upstream.ps1 -source 'feature/FOO-123' -target 'main' -remove - + & $PSScriptRoot/git-refactor-deps.ps1 -source 'feature/FOO-123' -target 'main' -remove + $fw.assertDiagnosticOutput | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } diff --git a/git-release.ps1 b/git-release.ps1 index f47d04c..99a2778 100755 --- a/git-release.ps1 +++ b/git-release.ps1 @@ -33,27 +33,27 @@ if (-not $force) { Invoke-LocalAction @commonParams @{ type = 'assert-updated' parameters = $cleanupOnly ` - ? @{ downstream = $target; upstream = $source } - : @{ downstream = $source; upstream = $target } + ? @{ dependants = $target; dependency = $source } + : @{ dependants = $source; dependency = $target } } Assert-Diagnostics $diagnostics } -# $toRemove = (git show-upstream $source -recurse) without ($target, git show-upstream $target -recurse, $preserve) -$sourceUpstream = Invoke-LocalAction @commonParams @{ - type = 'get-upstream' +# $toRemove = (git show-deps $source -recurse) without ($target, git show-deps $target -recurse, $preserve) +$sourceDependency = Invoke-LocalAction @commonParams @{ + type = 'get-dependency' parameters = @{ target = $source; recurse = $true } } Assert-Diagnostics $diagnostics -$targetUpstream = Invoke-LocalAction @commonParams @{ - type = 'get-upstream' +$targetDependency = Invoke-LocalAction @commonParams @{ + type = 'get-dependency' parameters = @{ target = $target; recurse = $true } } Assert-Diagnostics $diagnostics -[string[]]$keep = @($target) + $targetUpstream + $preserve -[string[]]$toRemove = (@($source) + $sourceUpstream) | Where-Object { $_ -notin $keep } +[string[]]$keep = @($target) + $targetDependency + $preserve +[string[]]$toRemove = (@($source) + $sourceDependency) | Where-Object { $_ -notin $keep } # Assert all branches removed are up-to-date, unless $force is set if (-not $force) { @@ -61,7 +61,7 @@ if (-not $force) { if ($branch -eq $source) { continue } Invoke-LocalAction @commonParams @{ type = 'assert-updated' - parameters = @{ downstream = $cleanupOnly ? $target : $source; upstream = $branch } + parameters = @{ dependants = $cleanupOnly ? $target : $source; dependency = $branch } } } Assert-Diagnostics $diagnostics @@ -71,24 +71,24 @@ if (-not $force) { # 1. Replace $toRemove branches with $target # 2. Simplify -$originalUpstreams = Invoke-LocalAction @commonParams @{ - type = 'get-all-upstreams' +$originalDependencies = Invoke-LocalAction @commonParams @{ + type = 'get-all-dependencies' parameters= @{} } Assert-Diagnostics $diagnostics -$resultUpstreams = @{} -foreach ($branch in $originalUpstreams.Keys) { +$resultDependencies = @{} +foreach ($branch in $originalDependencies.Keys) { if ($branch -in $toRemove) { - $resultUpstreams[$branch] = $null + $resultDependencies[$branch] = $null continue } - - if ($originalUpstreams[$branch] | Where-Object { $_ -in $toRemove }) { - $resultUpstreams[$branch] = Invoke-LocalAction @commonParams @{ + + if ($originalDependencies[$branch] | Where-Object { $_ -in $toRemove }) { + $resultDependencies[$branch] = Invoke-LocalAction @commonParams @{ type = 'filter-branches' parameters = @{ - include = @($target) + $originalUpstreams[$branch] + include = @($target) + $originalDependencies[$branch] exclude = $toRemove } } @@ -96,24 +96,24 @@ foreach ($branch in $originalUpstreams.Keys) { } } -$keys = @() + $resultUpstreams.Keys +$keys = @() + $resultDependencies.Keys foreach ($branch in $keys) { - if (-not $resultUpstreams[$branch]) { continue } - $resultUpstreams[$branch] = Invoke-LocalAction @commonParams @{ - type = 'simplify-upstream' + if (-not $resultDependencies[$branch]) { continue } + $resultDependencies[$branch] = Invoke-LocalAction @commonParams @{ + type = 'simplify-dependency' parameters = @{ - upstreamBranches = $resultUpstreams[$branch] - overrideUpstreams = $resultUpstreams + dependencyBranches = $resultDependencies[$branch] + overrideDependencies = $resultDependencies branchName = $branch } } Assert-Diagnostics $diagnostics } -$upstreamHash = Invoke-LocalAction @commonParams @{ - type = 'set-upstream' +$dependencyHash = Invoke-LocalAction @commonParams @{ + type = 'set-dependency' parameters = @{ - upstreamBranches = $resultUpstreams + dependencyBranches = $resultDependencies message = "Release $($source) to $($target)$($comment -eq '' ? '' : " for $($params.comment)")" } } @@ -123,7 +123,7 @@ $sourceHash = Get-BranchCommit (Get-RemoteBranchRef $source) # Finalize: # 1. Push the following: -# - Update _upstream +# - Update $dependencies # - Delete $toRemove branches # - If not $cleanupOnly, push $source commitish to $target @@ -133,7 +133,7 @@ $commonParams = @{ } $resultBranches = @{ - "$($config.upstreamBranch)" = $upstreamHash.commit + "$($config.dependencyBranch)" = $dependencyHash.commit } foreach ($branch in $toRemove) { $resultBranches[$branch] = $null diff --git a/git-release.tests.ps1 b/git-release.tests.ps1 index 26af4ad..ca2a9b7 100755 --- a/git-release.tests.ps1 +++ b/git-release.tests.ps1 @@ -7,7 +7,7 @@ Describe 'git-release' { Import-Module -Scope Local "$PSScriptRoot/utils/git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/actions.mocks.psm1" } - + BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework @@ -27,7 +27,7 @@ Describe 'git-release' { function Add-StandardTests { It 'handles standard functionality' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') @@ -40,17 +40,17 @@ Describe 'git-release' { Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'main' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/XYZ-1-services' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/FOO-123' -initialCommits $initialCommits - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-124_FOO-125", "main") ` -to @("feature/FOO-124_FOO-125") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null; 'integrate/FOO-125_XYZ-1' = @("feature/FOO-124_FOO-125"); 'rc/2022-07-14' = $null; 'feature/XYZ-1-services' = $null; } 'Release rc/2022-07-14 to main' 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' 'main' = $initialCommits['rc/2022-07-14'] 'feature/FOO-123' = $null 'feature/XYZ-1-services' = $null @@ -60,9 +60,9 @@ Describe 'git-release' { & $PSScriptRoot/git-release.ps1 rc/2022-07-14 main $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } - + It 'fails if an intermediate branch was not fully released' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') @@ -81,9 +81,9 @@ Describe 'git-release' { $fw.assertDiagnosticOutput | Should -Contain 'ERR: The branch feature/XYZ-1-services has changes that are not in rc/2022-07-14' $fw.assertDiagnosticOutput | Should -Contain 'ERR: The branch feature/FOO-123 has changes that are not in rc/2022-07-14' } - + It 'allows forced removal even if a intermediate branches were not fully released' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') @@ -96,17 +96,17 @@ Describe 'git-release' { Initialize-LocalActionAssertUpdated -withChanges 'rc/2022-07-14' 'main' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated -withChanges 'rc/2022-07-14' 'feature/XYZ-1-services' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated -withChanges 'rc/2022-07-14' 'feature/FOO-123' -initialCommits $initialCommits - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-124_FOO-125", "main") ` -to @("feature/FOO-124_FOO-125") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null; 'integrate/FOO-125_XYZ-1' = @("feature/FOO-124_FOO-125"); 'rc/2022-07-14' = $null; 'feature/XYZ-1-services' = $null; } 'Release rc/2022-07-14 to main' 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' 'main' = $initialCommits['rc/2022-07-14'] 'feature/FOO-123' = $null 'feature/XYZ-1-services' = $null @@ -116,9 +116,9 @@ Describe 'git-release' { & $PSScriptRoot/git-release.ps1 rc/2022-07-14 main -force $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } - + It 'can issue a dry run' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') @@ -131,16 +131,16 @@ Describe 'git-release' { Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'main' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/XYZ-1-services' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/FOO-123' -initialCommits $initialCommits - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-124_FOO-125", "main") ` -to @("feature/FOO-124_FOO-125") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null; 'integrate/FOO-125_XYZ-1' = @("feature/FOO-124_FOO-125"); 'rc/2022-07-14' = $null; 'feature/XYZ-1-services' = $null; } 'Release rc/2022-07-14 to main' 'new-commit' - Initialize-AssertValidBranchName '_upstream' + Initialize-AssertValidBranchName '$dependencies' Initialize-AssertValidBranchName 'feature/FOO-123' Initialize-AssertValidBranchName 'feature/XYZ-1-services' Initialize-AssertValidBranchName 'rc/2022-07-14' @@ -150,7 +150,7 @@ Describe 'git-release' { } It 'handles integration branches recursively' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') 'feature/FOO-124-comment' = @('main') @@ -166,7 +166,7 @@ Describe 'git-release' { Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/FOO-124_FOO-125' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'integrate/FOO-125_XYZ-1' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/FOO-123' -initialCommits $initialCommits - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null 'integrate/FOO-125_XYZ-1' = $null 'rc/2022-07-14' = $null @@ -175,7 +175,7 @@ Describe 'git-release' { 'feature/FOO-124-comment' = $null } -commitMessage 'Release rc/2022-07-14 to main' -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' 'main' = $initialCommits['rc/2022-07-14'] 'feature/FOO-123' = $null 'integrate/FOO-125_XYZ-1' = $null @@ -190,7 +190,7 @@ Describe 'git-release' { } It 'can preserve some branches' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') 'feature/FOO-124-comment' = @('main') @@ -204,13 +204,13 @@ Describe 'git-release' { Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/FOO-124-comment' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/XYZ-1-services' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'rc/2022-07-14' 'feature/FOO-123' -initialCommits $initialCommits - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("feature/FOO-124_FOO-125", "main") ` -to @("feature/FOO-124_FOO-125") - Initialize-LocalActionSimplifyUpstreamBranchesSuccess ` + Initialize-LocalActionSimplifyDependencyBranchesSuccess ` -from @("main") ` -to @("main") - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null 'rc/2022-07-14' = $null 'integrate/FOO-125_XYZ-1' = @("feature/FOO-124_FOO-125") @@ -219,7 +219,7 @@ Describe 'git-release' { 'feature/XYZ-1-services' = $null } -commitMessage 'Release rc/2022-07-14 to main' -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' 'main' = $initialCommits['rc/2022-07-14'] 'feature/FOO-123' = $null 'rc/2022-07-14' = $null @@ -231,8 +231,8 @@ Describe 'git-release' { $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } - It 'handles a single upstream branch' { - Initialize-AllUpstreamBranches @{ + It 'handles a single dependency branch' { + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') 'feature/FOO-124-comment' = @('main') @@ -243,11 +243,11 @@ Describe 'git-release' { 'rc/2022-07-14' = @("feature/XYZ-1-services") } -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'feature/FOO-123' 'main' -initialCommits $initialCommits - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/FOO-123' = $null } -commitMessage 'Release feature/FOO-123 to main' -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' 'main' = $initialCommits['feature/FOO-123'] 'feature/FOO-123' = $null } @@ -264,7 +264,7 @@ Describe 'git-release' { } It 'can clean up if already released' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') 'feature/FOO-124-comment' = @('main') @@ -276,13 +276,13 @@ Describe 'git-release' { } -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'main' 'rc/2022-07-14' -initialCommits $initialCommits Initialize-LocalActionAssertUpdated 'main' 'feature/XYZ-1-services' -initialCommits $initialCommits - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'integrate/FOO-125_XYZ-1' = @("feature/FOO-124_FOO-125") 'rc/2022-07-14' = $null 'feature/XYZ-1-services' = $null } -commitMessage 'Release rc/2022-07-14 to main' -commitish 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' 'rc/2022-07-14' = $null 'feature/XYZ-1-services' = $null } @@ -290,7 +290,7 @@ Describe 'git-release' { Initialize-AssertValidBranchName 'feature/FOO-124_FOO-125' & $PSScriptRoot/git-release.ps1 rc/2022-07-14 main -cleanupOnly - $fw.assertDiagnosticOutput | Should -Be "WARN: Removing 'main' from upstream branches of 'integrate/FOO-125_XYZ-1'; it is redundant via the following: feature/FOO-124_FOO-125" + $fw.assertDiagnosticOutput | Should -Be "WARN: Removing 'main' from dependency branches of 'integrate/FOO-125_XYZ-1'; it is redundant via the following: feature/FOO-124_FOO-125" } It 'aborts clean up if not already released' { @@ -300,7 +300,7 @@ Describe 'git-release' { $fw.assertDiagnosticOutput | Should -Be 'ERR: The branch rc/2022-07-14 has changes that are not in main' } } - + Context 'without a remote' { BeforeEach { Initialize-ToolConfiguration -noRemote diff --git a/git-show-downstream.json b/git-show-dependants.json similarity index 61% rename from git-show-downstream.json rename to git-show-dependants.json index 590db0b..b64d0d6 100644 --- a/git-show-downstream.json +++ b/git-show-dependants.json @@ -1,8 +1,8 @@ { "local": [ { - "id": "get-downstream", - "type": "get-downstream", + "id": "get-dependants", + "type": "get-dependants", "parameters": { "recurse": "$params.recurse", "target": "$params.target" @@ -10,5 +10,5 @@ } ], "finalize": [], - "output": "$actions['get-downstream'].outputs" + "output": "$actions['get-dependants'].outputs" } diff --git a/git-show-downstream.ps1 b/git-show-dependants.ps1 similarity index 88% rename from git-show-downstream.ps1 rename to git-show-dependants.ps1 index ca0db38..136ecd9 100755 --- a/git-show-downstream.ps1 +++ b/git-show-dependants.ps1 @@ -11,7 +11,7 @@ Import-Module -Scope Local "$PSScriptRoot/utils/input.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/scripting.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/query-state.psm1" -Invoke-JsonScript -scriptPath "$PSScriptRoot/git-show-downstream.json" -params @{ +Invoke-JsonScript -scriptPath "$PSScriptRoot/git-show-dependants.json" -params @{ target = ($target ? $target : (Get-CurrentBranch ?? '')); recurse = $recurse; includeRemote = $includeRemote; diff --git a/git-show-downstream.tests.ps1 b/git-show-dependants.tests.ps1 similarity index 86% rename from git-show-downstream.tests.ps1 rename to git-show-dependants.tests.ps1 index cdb81fd..fb3f80d 100755 --- a/git-show-downstream.tests.ps1 +++ b/git-show-dependants.tests.ps1 @@ -6,11 +6,11 @@ BeforeAll { # Mock -CommandName Write-Host {} } -Describe 'git-show-downstream' { +Describe 'git-show-dependants' { Describe 'with a remote' { # Scenario: # - remote configured - # - upstreams include: + # - dependencies include: # feature/FOO-123 = main & infra/add-services # main = none # infra/add-services = infra/build-infrastructure @@ -18,20 +18,20 @@ Describe 'git-show-downstream' { # - no current branch BeforeEach { Initialize-ToolConfiguration - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123") 'feature/FOO-123' = @("main") 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") - + 'bad-recursive-branch-1' = @('bad-recursive-branch-2') 'bad-recursive-branch-2' = @('bad-recursive-branch-1') } } - It 'shows the results of an downstream branch' { - $result = & ./git-show-downstream.ps1 -noFetch -target 'feature/FOO-123' + It 'shows the results of an dependants branch' { + $result = & ./git-show-dependants.ps1 -noFetch -target 'feature/FOO-123' Should -ActualValue $result.Length -Be 2 Should -ActualValue $result -BeLike 'feature/FOO-124' @@ -46,7 +46,7 @@ Describe 'git-show-downstream' { } It 'shows the results of the current branch if none is specified' { - $result = & ./git-show-downstream.ps1 -noFetch + $result = & ./git-show-dependants.ps1 -noFetch Should -ActualValue $result.Length -Be 2 Should -ActualValue $result -BeLike 'feature/FOO-124' @@ -54,7 +54,7 @@ Describe 'git-show-downstream' { } It 'allows specifying the branch with arguments and including remote in the response' { - $result = & ./git-show-downstream.ps1 -noFetch -target 'main' + $result = & ./git-show-dependants.ps1 -noFetch -target 'main' Should -ActualValue $result.Length -Be 2 Should -ActualValue $result -BeLike 'feature/FOO-123' @@ -62,7 +62,7 @@ Describe 'git-show-downstream' { } It 'shows recursive the results of the current branch if none is specified' { - $result = & ./git-show-downstream.ps1 -noFetch -recurse + $result = & ./git-show-dependants.ps1 -noFetch -recurse Should -ActualValue $result.Length -Be 3 Should -ActualValue $result -BeLike 'feature/FOO-124' @@ -71,7 +71,7 @@ Describe 'git-show-downstream' { } It 'shows recursive the results of the a specified branch' { - $result = & ./git-show-downstream.ps1 -noFetch -recurse -target 'main' + $result = & ./git-show-dependants.ps1 -noFetch -recurse -target 'main' Should -ActualValue $result.Length -Be 5 Should -ActualValue $result -BeLike 'feature/FOO-123' diff --git a/git-show-upstream.json b/git-show-deps.json similarity index 67% rename from git-show-upstream.json rename to git-show-deps.json index f1593e8..0015c1f 100644 --- a/git-show-upstream.json +++ b/git-show-deps.json @@ -1,8 +1,8 @@ { "local": [ { - "id": "get-upstream", - "type": "get-upstream", + "id": "get-dependency", + "type": "get-dependency", "parameters": { "recurse": "$params.recurse", "includeRemote": "$params.includeRemote", @@ -11,5 +11,5 @@ } ], "finalize": [], - "output": "$actions['get-upstream'].outputs" + "output": "$actions['get-dependency'].outputs" } diff --git a/git-show-upstream.ps1 b/git-show-deps.ps1 similarity index 86% rename from git-show-upstream.ps1 rename to git-show-deps.ps1 index ea45681..c515210 100755 --- a/git-show-upstream.ps1 +++ b/git-show-deps.ps1 @@ -12,7 +12,7 @@ Import-Module -Scope Local "$PSScriptRoot/utils/input.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/scripting.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/query-state.psm1" -Invoke-JsonScript -scriptPath "$PSScriptRoot/git-show-upstream.json" -params @{ +Invoke-JsonScript -scriptPath "$PSScriptRoot/git-show-deps.json" -params @{ target = ($target ? $target : (Get-CurrentBranch ?? '')); recurse = $recurse; includeRemote = $includeRemote; diff --git a/git-show-upstream.tests.ps1 b/git-show-deps.tests.ps1 similarity index 75% rename from git-show-upstream.tests.ps1 rename to git-show-deps.tests.ps1 index 3979b3b..a0bca4c 100755 --- a/git-show-upstream.tests.ps1 +++ b/git-show-deps.tests.ps1 @@ -6,11 +6,11 @@ BeforeAll { # Mock -CommandName Write-Host {} } -Describe 'git-show-upstream' { +Describe 'git-show-deps' { Describe 'with a remote' { # Scenario: # - remote configured - # - upstreams include: + # - dependencies include: # feature/FOO-123 = main & infra/add-services # main = none # infra/add-services = infra/build-infrastructure @@ -18,7 +18,7 @@ Describe 'git-show-upstream' { # - no current branch BeforeEach { Initialize-ToolConfiguration - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-123' = $("main", "infra/add-services") 'main' = $() 'infra/add-services' = $('infra/build-infrastructure') @@ -26,8 +26,8 @@ Describe 'git-show-upstream' { } } - It 'shows the results of an upstream branch' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote -target 'feature/FOO-123' + It 'shows the results of an dependency branch' { + $result = & ./git-show-deps.ps1 -noFetch -includeRemote -target 'feature/FOO-123' $result | Should -Be @('origin/main', 'origin/infra/add-services') } @@ -40,41 +40,41 @@ Describe 'git-show-upstream' { } It 'shows the results of the current branch if none is specified and including remote in the response' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote + $result = & ./git-show-deps.ps1 -noFetch -includeRemote $result | Should -Be @('origin/main', 'origin/infra/add-services') } It 'allows specifying the branch with arguments and including remote in the response' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote -target infra/add-services + $result = & ./git-show-deps.ps1 -noFetch -includeRemote -target infra/add-services $result | Should -Be @('origin/infra/build-infrastructure') } It 'shows recursive the results of the current branch if none is specified and including remote in the response' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote -recurse + $result = & ./git-show-deps.ps1 -noFetch -includeRemote -recurse $result | Should -Be @('origin/main', 'origin/infra/add-services', 'origin/infra/build-infrastructure') } - + It 'shows the results of the current branch if none is specified' { - $result = & ./git-show-upstream.ps1 -noFetch + $result = & ./git-show-deps.ps1 -noFetch $result | Should -Be @('main', 'infra/add-services') } It 'allows specifying the branch with arguments' { - $result = & ./git-show-upstream.ps1 -noFetch -target infra/add-services + $result = & ./git-show-deps.ps1 -noFetch -target infra/add-services $result | Should -Be @('infra/build-infrastructure') } It 'shows recursive the results of the current branch if none is specified' { - $result = & ./git-show-upstream.ps1 -noFetch -recurse + $result = & ./git-show-deps.ps1 -noFetch -recurse $result | Should -Be @('main', 'infra/add-services', 'infra/build-infrastructure') } } } - + Describe 'without a remote' { # Scenario: # - remote configured - # - upstreams include: + # - dependencies include: # feature/FOO-123 = main & infra/add-services # main = none # infra/add-services = infra/build-infrastructure @@ -82,7 +82,7 @@ Describe 'git-show-upstream' { # - no current branch BeforeEach { Initialize-ToolConfiguration -noRemote - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-123' = $("main", "infra/add-services") 'main' = $() 'infra/add-services' = $('infra/build-infrastructure') @@ -90,8 +90,8 @@ Describe 'git-show-upstream' { } } - It 'shows the results of an upstream branch' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote -target 'feature/FOO-123' + It 'shows the results of an dependency branch' { + $result = & ./git-show-deps.ps1 -noFetch -includeRemote -target 'feature/FOO-123' $result | Should -Be @('main', 'infra/add-services') } @@ -104,32 +104,32 @@ Describe 'git-show-upstream' { } It 'shows the results of the current branch if none is specified and including remote in the response' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote + $result = & ./git-show-deps.ps1 -noFetch -includeRemote $result | Should -Be @('main', 'infra/add-services') } It 'allows specifying the branch with arguments and including remote in the response' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote -target infra/add-services + $result = & ./git-show-deps.ps1 -noFetch -includeRemote -target infra/add-services $result | Should -Be @('infra/build-infrastructure') } It 'shows recursive the results of the current branch if none is specified and including remote in the response' { - $result = & ./git-show-upstream.ps1 -noFetch -includeRemote -recurse + $result = & ./git-show-deps.ps1 -noFetch -includeRemote -recurse $result | Should -Be @('main', 'infra/add-services', 'infra/build-infrastructure') } - + It 'shows the results of the current branch if none is specified' { - $result = & ./git-show-upstream.ps1 -noFetch + $result = & ./git-show-deps.ps1 -noFetch $result | Should -Be @('main', 'infra/add-services') } It 'allows specifying the branch with arguments' { - $result = & ./git-show-upstream.ps1 -noFetch -target infra/add-services + $result = & ./git-show-deps.ps1 -noFetch -target infra/add-services $result | Should -Be @('infra/build-infrastructure') } It 'shows recursive the results of the current branch if none is specified' { - $result = & ./git-show-upstream.ps1 -noFetch -recurse + $result = & ./git-show-deps.ps1 -noFetch -recurse $result | Should -Be @('main', 'infra/add-services', 'infra/build-infrastructure') } } diff --git a/git-tool-audit-prune.ps1 b/git-tool-audit-prune.ps1 index dff9628..b87e79b 100755 --- a/git-tool-audit-prune.ps1 +++ b/git-tool-audit-prune.ps1 @@ -19,10 +19,10 @@ if (-not $noFetch) { $commonParams = @{ diagnostics = $diagnostics } -# Get all branches in upstreams +# Get all branches in dependencies -$originalUpstreams = Invoke-LocalAction @commonParams @{ - type = 'get-all-upstreams' +$originalDependencies = Invoke-LocalAction @commonParams @{ + type = 'get-all-dependencies' parameters= @{} } Assert-Diagnostics $diagnostics @@ -31,21 +31,21 @@ Assert-Diagnostics $diagnostics $allBranches = Select-Branches -# For all keys (downstream) in the upstreams: -# - If the downstream does not exist, replace it with its downstreams in all other upstreams +# For all keys (dependants) in the dependencies: +# - If the dependants does not exist, replace it with its dependants in all other dependencies -[string[]]$configuredBranches = @() + $originalUpstreams.Keys -$resultUpstreams = @{} +[string[]]$configuredBranches = @() + $originalDependencies.Keys +$resultDependencies = @{} foreach ($branch in $configuredBranches) { if ($branch -in $allBranches) { continue } - [string[]]$upstreams = $resultUpstreams[$branch] ?? $originalUpstreams[$branch] - foreach ($downstream in $configuredBranches) { - [string[]]$initial = $resultUpstreams[$downstream] ?? $originalUpstreams[$downstream] + [string[]]$dependencies = $resultDependencies[$branch] ?? $originalDependencies[$branch] + foreach ($dependants in $configuredBranches) { + [string[]]$initial = $resultDependencies[$dependants] ?? $originalDependencies[$dependants] if ($branch -notin $initial) { continue } - $resultUpstreams[$downstream] = Invoke-LocalAction @commonParams @{ + $resultDependencies[$dependants] = Invoke-LocalAction @commonParams @{ type = 'filter-branches' parameters = @{ - include = $initial + $upstreams + include = $initial + $dependencies exclude = @($branch) } } @@ -53,66 +53,66 @@ foreach ($branch in $configuredBranches) { } -# For all keys (downstream) in the upstreams: +# For all keys (dependants) in the dependencies: # - Remove entire branch configuration if the branch does not exist -# - Remove upstreams that do not exist +# - Remove dependencies that do not exist foreach ($branch in $configuredBranches) { if ($branch -notin $allBranches) { - $resultUpstreams[$branch] = $null + $resultDependencies[$branch] = $null continue } - [string[]]$upstreams = $resultUpstreams[$branch] ?? $originalUpstreams[$branch] - [string[]]$resultUpstream = @() - foreach ($upstream in $upstreams) { - if ($upstream -in $allBranches) { - $resultUpstream = $resultUpstream + @($upstream) + [string[]]$dependencies = $resultDependencies[$branch] ?? $originalDependencies[$branch] + [string[]]$resultDependency = @() + foreach ($dependency in $dependencies) { + if ($dependency -in $allBranches) { + $resultDependency = $resultDependency + @($dependency) } } } -# Simplify changed upstreams +# Simplify changed dependencies foreach ($branch in $configuredBranches) { - if (-not $resultUpstreams[$branch]) { continue } + if (-not $resultDependencies[$branch]) { continue } [string[]]$result = Invoke-LocalAction @commonParams @{ - type = 'simplify-upstream' + type = 'simplify-dependency' parameters = @{ - upstreamBranches = $resultUpstreams[$branch] - overrideUpstreams = $resultUpstreams + dependencyBranches = $resultDependencies[$branch] + overrideDependencies = $resultDependencies branchName = $branch } } - if ($result.length -ne ([string[]]$resultUpstreams[$branch]).length) { - $resultUpstreams[$branch] = $result + if ($result.length -ne ([string[]]$resultDependencies[$branch]).length) { + $resultDependencies[$branch] = $result } } Assert-Diagnostics $diagnostics -# Set upstream branch +# Set dependency branch -if ($resultUpstreams.Count -ne 0) { - $upstreamHash = Invoke-LocalAction @commonParams @{ - type = 'set-upstream' +if ($resultDependencies.Count -ne 0) { + $dependencyHash = Invoke-LocalAction @commonParams @{ + type = 'set-dependency' parameters = @{ - upstreamBranches = $resultUpstreams + dependencyBranches = $resultDependencies message = "Applied changes from 'prune' audit" } } Assert-Diagnostics $diagnostics } -# Finalize: Push upstream branch +# Finalize: Push dependency branch $commonParams = @{ diagnostics = $diagnostics dryRun = $dryRun } -if ($resultUpstreams.Count -ne 0) { +if ($resultDependencies.Count -ne 0) { Invoke-FinalizeAction @commonParams @{ type = 'set-branches' parameters = @{ branches = @{ - "$($config.upstreamBranch)" = $upstreamHash.commit + "$($config.dependencyBranch)" = $dependencyHash.commit } } } diff --git a/git-tool-audit-prune.tests.ps1 b/git-tool-audit-prune.tests.ps1 index 4e782a5..6da79fa 100755 --- a/git-tool-audit-prune.tests.ps1 +++ b/git-tool-audit-prune.tests.ps1 @@ -5,15 +5,15 @@ Describe 'Invoke-PruneAudit' { Import-Module -Scope Local "$PSScriptRoot/utils/input.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/query-state.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/actions.mocks.psm1" - - function Initialize-ValidDownstreamBranchNames { - $upstreams = Select-AllUpstreamBranches + + function Initialize-ValidDependantBranchNames { + $dependencies = Select-AllDependencyBranches [string[]]$entries = @() - foreach ($key in $upstreams.Keys) { - foreach ($downstream in $upstreams[$key]) { - if ($downstream -notin $entries) { - [string[]]$entries = $entries + @($downstream) - Initialize-AssertValidBranchName $downstream + foreach ($key in $dependencies.Keys) { + foreach ($dependants in $dependencies[$key]) { + if ($dependants -notin $entries) { + [string[]]$entries = $entries + @($dependants) + Initialize-AssertValidBranchName $dependants } } } @@ -28,7 +28,7 @@ Describe 'Invoke-PruneAudit' { function Add-StandardTests() { It 'does nothing when no branches are configured' { Initialize-SelectBranches @() - Initialize-AllUpstreamBranches @{} + Initialize-AllDependencyBranches @{} & $PSScriptRoot/git-tool-audit-prune.ps1 $fw.assertDiagnosticOutput | Should -BeNullOrEmpty @@ -45,51 +45,51 @@ Describe 'Invoke-PruneAudit' { } It 'does nothing when existing branches are configured correctly' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123") 'feature/FOO-123' = @('infra/shared') 'infra/shared' = @('main') } - Initialize-ValidDownstreamBranchNames + Initialize-ValidDependantBranchNames & $PSScriptRoot/git-tool-audit-prune.ps1 $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } It 'does not apply with a dry run' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") 'feature/FOO-123' = @('infra/shared') 'infra/shared' = @('main') 'feature/XYZ-1-services' = @() # intentionally have an extra configured branch here for removal } - Initialize-ValidDownstreamBranchNames - Initialize-LocalActionSetUpstream @{ + Initialize-ValidDependantBranchNames + Initialize-LocalActionSetDependency @{ 'feature/XYZ-1-services' = $null 'rc/2022-07-14' = @("feature/FOO-123") } "Applied changes from 'prune' audit" 'new-commit' - Initialize-AssertValidBranchName '_upstream' + Initialize-AssertValidBranchName '$dependencies' & $PSScriptRoot/git-tool-audit-prune.ps1 -dryRun $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } It 'prunes configuration of extra branches' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") 'feature/FOO-123' = @('infra/shared') 'infra/shared' = @('main') 'feature/XYZ-1-services' = @() # intentionally have an extra configured branch here for removal } - Initialize-ValidDownstreamBranchNames + Initialize-ValidDependantBranchNames $mock = @( - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/XYZ-1-services' = $null 'rc/2022-07-14' = @("feature/FOO-123") } "Applied changes from 'prune' audit" 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' } ) @@ -100,27 +100,27 @@ Describe 'Invoke-PruneAudit' { } It 'consolidates removed branches' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'rc/2022-07-14' = @("feature/FOO-123","feature/XYZ-1-services") 'feature/FOO-123' = @('infra/shared') 'infra/shared' = @('main') 'feature/XYZ-1-services' = @('infra/shared') # intentionally have an extra configured branch here for removal } - Initialize-ValidDownstreamBranchNames + Initialize-ValidDependantBranchNames $mock = @( - Initialize-LocalActionSetUpstream @{ + Initialize-LocalActionSetDependency @{ 'feature/XYZ-1-services' = $null 'rc/2022-07-14' = @("feature/FOO-123") } "Applied changes from 'prune' audit" 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' } ) & $PSScriptRoot/git-tool-audit-prune.ps1 $fw.assertDiagnosticOutput.Count | Should -Be 1 - $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'infra/shared' from upstream branches of 'rc/2022-07-14'; it is redundant via the following: feature/FOO-123" + $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'infra/shared' from dependency branches of 'rc/2022-07-14'; it is redundant via the following: feature/FOO-123" Invoke-VerifyMock $mock -Times 1 } diff --git a/git-tool-audit-simplify.ps1 b/git-tool-audit-simplify.ps1 index 4dafcc4..8b92f6e 100755 --- a/git-tool-audit-simplify.ps1 +++ b/git-tool-audit-simplify.ps1 @@ -22,34 +22,34 @@ $commonParams = @{ # For all branches: # Simplify -$originalUpstreams = Invoke-LocalAction @commonParams @{ - type = 'get-all-upstreams' +$originalDependencies = Invoke-LocalAction @commonParams @{ + type = 'get-all-dependencies' parameters= @{} } Assert-Diagnostics $diagnostics -$resultUpstreams = @{} -foreach ($branch in $originalUpstreams.Keys) { - if (-not $originalUpstreams[$branch]) { continue } +$resultDependencies = @{} +foreach ($branch in $originalDependencies.Keys) { + if (-not $originalDependencies[$branch]) { continue } [string[]]$result = Invoke-LocalAction @commonParams @{ - type = 'simplify-upstream' + type = 'simplify-dependency' parameters = @{ - upstreamBranches = $originalUpstreams[$branch] - overrideUpstreams = $originalUpstreams + dependencyBranches = $originalDependencies[$branch] + overrideDependencies = $originalDependencies branchName = $branch } } - if ($result.length -ne ([string[]]$originalUpstreams[$branch]).length) { - $resultUpstreams[$branch] = $result + if ($result.length -ne ([string[]]$originalDependencies[$branch]).length) { + $resultDependencies[$branch] = $result } } Assert-Diagnostics $diagnostics -if ($resultUpstreams.Count -ne 0) { - $upstreamHash = Invoke-LocalAction @commonParams @{ - type = 'set-upstream' +if ($resultDependencies.Count -ne 0) { + $dependencyHash = Invoke-LocalAction @commonParams @{ + type = 'set-dependency' parameters = @{ - upstreamBranches = $resultUpstreams + dependencyBranches = $resultDependencies message = "Applied changes from 'simplify' audit" } } @@ -57,19 +57,19 @@ if ($resultUpstreams.Count -ne 0) { } # Finalize: -# Push the new _upstream +# Push the new $dependencies $commonParams = @{ diagnostics = $diagnostics dryRun = $dryRun } -if ($resultUpstreams.Count -ne 0) { +if ($resultDependencies.Count -ne 0) { Invoke-FinalizeAction @commonParams @{ type = 'set-branches' parameters = @{ branches = @{ - "$($config.upstreamBranch)" = $upstreamHash.commit + "$($config.dependencyBranch)" = $dependencyHash.commit } } } diff --git a/git-tool-audit-simplify.tests.ps1 b/git-tool-audit-simplify.tests.ps1 index 25a7d1b..97b0b01 100755 --- a/git-tool-audit-simplify.tests.ps1 +++ b/git-tool-audit-simplify.tests.ps1 @@ -7,7 +7,7 @@ Describe 'git-tool-audit-simplify' { Import-Module -Scope Local "$PSScriptRoot/utils/git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/utils/actions.mocks.psm1" } - + BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework @@ -24,14 +24,14 @@ Describe 'git-tool-audit-simplify' { 'integrate/FOO-125_XYZ-1' = 'integrate/FOO-125_XYZ-1-commitish' } - function Initialize-ValidDownstreamBranchNames { - $upstreams = Select-AllUpstreamBranches + function Initialize-ValidDependantBranchNames { + $dependencies = Select-AllDependencyBranches [string[]]$entries = @() - foreach ($key in $upstreams.Keys) { - foreach ($downstream in $upstreams[$key]) { - if ($downstream -notin $entries) { - [string[]]$entries = $entries + @($downstream) - Initialize-AssertValidBranchName $downstream + foreach ($key in $dependencies.Keys) { + foreach ($dependants in $dependencies[$key]) { + if ($dependants -notin $entries) { + [string[]]$entries = $entries + @($dependants) + Initialize-AssertValidBranchName $dependants } } } @@ -41,7 +41,7 @@ Describe 'git-tool-audit-simplify' { function Add-StandardTests { It 'handles standard functionality' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') 'feature/FOO-124-comment' = @('main') @@ -51,23 +51,23 @@ Describe 'git-tool-audit-simplify' { 'main' = @() 'rc/2022-07-14' = @("feature/FOO-123", "integrate/FOO-125_XYZ-1", "feature/FOO-124-comment") } -initialCommits $initialCommits - Initialize-ValidDownstreamBranchNames - Initialize-LocalActionSetUpstream @{ + Initialize-ValidDependantBranchNames + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-123", "integrate/FOO-125_XYZ-1") 'feature/FOO-124_FOO-125' = @("feature/FOO-124-comment") } "Applied changes from 'simplify' audit" 'new-commit' Initialize-FinalizeActionSetBranches @{ - '_upstream' = 'new-commit' + '$dependencies' = 'new-commit' } & $PSScriptRoot/git-tool-audit-simplify.ps1 $fw.assertDiagnosticOutput.Count | Should -Be 2 - $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from upstream branches of 'feature/FOO-124_FOO-125'; it is redundant via the following: feature/FOO-124-comment" - $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'feature/FOO-124-comment' from upstream branches of 'rc/2022-07-14'; it is redundant via the following: integrate/FOO-125_XYZ-1" + $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from dependency branches of 'feature/FOO-124_FOO-125'; it is redundant via the following: feature/FOO-124-comment" + $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'feature/FOO-124-comment' from dependency branches of 'rc/2022-07-14'; it is redundant via the following: integrate/FOO-125_XYZ-1" } - + It 'can issue a dry run' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') 'feature/FOO-124-comment' = @('main') @@ -77,21 +77,21 @@ Describe 'git-tool-audit-simplify' { 'main' = @() 'rc/2022-07-14' = @("feature/FOO-123", "integrate/FOO-125_XYZ-1", "feature/FOO-124-comment") } -initialCommits $initialCommits - Initialize-ValidDownstreamBranchNames - Initialize-LocalActionSetUpstream @{ + Initialize-ValidDependantBranchNames + Initialize-LocalActionSetDependency @{ 'rc/2022-07-14' = @("feature/FOO-123", "integrate/FOO-125_XYZ-1") 'feature/FOO-124_FOO-125' = @("feature/FOO-124-comment") } "Applied changes from 'simplify' audit" 'new-commit' - Initialize-AssertValidBranchName "_upstream" + Initialize-AssertValidBranchName "`$dependencies" & $PSScriptRoot/git-tool-audit-simplify.ps1 -dryRun $fw.assertDiagnosticOutput.Count | Should -Be 2 - $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from upstream branches of 'feature/FOO-124_FOO-125'; it is redundant via the following: feature/FOO-124-comment" - $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'feature/FOO-124-comment' from upstream branches of 'rc/2022-07-14'; it is redundant via the following: integrate/FOO-125_XYZ-1" + $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'main' from dependency branches of 'feature/FOO-124_FOO-125'; it is redundant via the following: feature/FOO-124-comment" + $fw.assertDiagnosticOutput | Should -Contain "WARN: Removing 'feature/FOO-124-comment' from dependency branches of 'rc/2022-07-14'; it is redundant via the following: integrate/FOO-125_XYZ-1" } - + It 'does nothing if no changes are needed' { - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') 'feature/FOO-124-comment' = @('main') @@ -101,13 +101,13 @@ Describe 'git-tool-audit-simplify' { 'main' = @() 'rc/2022-07-14' = @("feature/FOO-123", "integrate/FOO-125_XYZ-1") } -initialCommits $initialCommits - Initialize-ValidDownstreamBranchNames + Initialize-ValidDependantBranchNames & $PSScriptRoot/git-tool-audit-simplify.ps1 $fw.assertDiagnosticOutput | Should -BeNullOrEmpty } } - + Context 'without a remote' { BeforeEach { Initialize-ToolConfiguration -noRemote diff --git a/git-tool-config.ps1 b/git-tool-config.ps1 index 155fd27..5ae159c 100755 --- a/git-tool-config.ps1 +++ b/git-tool-config.ps1 @@ -2,7 +2,7 @@ Param( [Parameter()][String] $remote, - [Parameter()][String] $upstreamBranch, + [Parameter()][String] $dependencyBranch, [Parameter()][String] $defaultServiceLine, [Switch] $enableAtomicPush, [Switch] $disableAtomicPush @@ -24,11 +24,11 @@ if ($remote -ne '') { Write-Host "Using previous remote: $remote" } -if ($upstreamBranch -ne '') { - git config scaled-git.upstreamBranch $upstreamBranch - Write-Host "Set upstream: $upstreamBranch" +if ($dependencyBranch -ne '') { + git config scaled-git.dependencyBranch $dependencyBranch + Write-Host "Set dependency tracking branch: $dependencyBranch" } else { - Write-Host "Using previous upstream: $($oldConfig.upstreamBranch)" + Write-Host "Using previous dependency tracking branch: $($oldConfig.dependencyBranch)" } if ($defaultServiceLine -ne '') { diff --git a/git-tool-update.tests.ps1 b/git-tool-update.tests.ps1 index 419e71a..53e2de3 100755 --- a/git-tool-update.tests.ps1 +++ b/git-tool-update.tests.ps1 @@ -1,20 +1,20 @@ -BeforeAll { - . "$PSScriptRoot/utils/testing.ps1" - Import-Module -Scope Local "$PSScriptRoot/utils/framework.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/utils/query-state.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/utils/git.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/migration/Invoke-Migration.mocks.psm1" - - Mock -CommandName git -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify HEAD' } { - $Global:LASTEXITCODE = 0 - 'old-commit' +Describe 'git-tool-update' { + BeforeAll { + . "$PSScriptRoot/utils/testing.ps1" + Import-Module -Scope Local "$PSScriptRoot/utils/framework.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/utils/query-state.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/utils/git.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/migration/Invoke-Migration.mocks.psm1" + + Mock -CommandName git -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify HEAD' } { + $Global:LASTEXITCODE = 0 + 'old-commit' + } + + # User-interface commands are a bit noisy; TODO: add quiet option and test it by making this throw + Mock -CommandName Write-Host { } } - # User-interface commands are a bit noisy; TODO: add quiet option and test it by making this throw - Mock -CommandName Write-Host { } -} - -Describe 'git-tool-update' { BeforeEach { Register-Framework } @@ -82,7 +82,7 @@ Describe 'git-tool-update' { Invoke-VerifyMock $mockCheckout -Times 1 Invoke-VerifyMock $mockPull -Times 1 } - + It 'allows running the script for mac' { Initialize-CleanWorkingDirectory diff --git a/git-verify-updated.json b/git-verify-updated.json index 6391ff7..007c3ec 100644 --- a/git-verify-updated.json +++ b/git-verify-updated.json @@ -33,6 +33,6 @@ ], "finalize": [], "output": [ - "$($params.target) is up-to-date with its upstreams" + "$($params.target) is up-to-date with its dependencies" ] } diff --git a/git-verify-updated.recurse.json b/git-verify-updated.recurse.json index 07f0b56..b713394 100644 --- a/git-verify-updated.recurse.json +++ b/git-verify-updated.recurse.json @@ -1,10 +1,10 @@ { "recursion": { "mode": "depth-first", - "paramScript": "$params.recurse ? ($actions['get-upstream'].outputs | Where-Object { $null -ne $_ -AND $_ -notin ($previous | ForEach-Object { $_.target }) } | ForEach-Object { @{ target = $_; recurse = $params.recurse } }) : @()", + "paramScript": "$params.recurse ? ($actions['get-dependency'].outputs | Where-Object { $null -ne $_ -AND $_ -notin ($previous | ForEach-Object { $_.target }) } | ForEach-Object { @{ target = $_; recurse = $params.recurse } }) : @()", "map": "@{}", "reduceToOutput": "@{}", - "actCondition": "$null -ne $actions['get-upstream'].outputs" + "actCondition": "$null -ne $actions['get-dependency'].outputs" }, "prepare": [ { @@ -14,17 +14,17 @@ } }, { - "id": "get-upstream", - "type": "get-upstream", + "id": "get-dependency", + "type": "get-dependency", "parameters": { "target": "$params.target" } }, - { + { "type": "add-diagnostic", - "condition": "$params.depth -eq 0 -AND $null -eq $actions['get-upstream'].outputs", + "condition": "$params.depth -eq 0 -AND $null -eq $actions['get-dependency'].outputs", "parameters": { - "message": "$($params.target) has no upstream branches to verify." + "message": "$($params.target) has no dependency branches to verify." } } ], @@ -34,17 +34,17 @@ "type": "merge-branches", "parameters": { "source": "$($params.target)", - "upstreamBranches": ["$actions['get-upstream'].outputs"] + "dependencyBranches": ["$actions['get-dependency'].outputs"] } }, - { + { "type": "add-diagnostic", "condition": "$actions['merge-branches'].outputs['failed']", "parameters": { "message": "$($params.target) has incoming conflicts from $($actions['merge-branches'].outputs['failed'])." } }, - { + { "type": "add-diagnostic", "condition": "$actions['merge-branches'].outputs['hasChanges'] ? $true : $false", "parameters": { diff --git a/git-verify-updated.tests.ps1 b/git-verify-updated.tests.ps1 index 43a9a6c..8c14c2c 100755 --- a/git-verify-updated.tests.ps1 +++ b/git-verify-updated.tests.ps1 @@ -22,16 +22,16 @@ Describe 'git-verify-updated' { { & $PSScriptRoot/git-verify-updated.ps1 } | Should -Throw } - + It 'uses the default branch when none specified' { $mocks = @( Initialize-CurrentBranch 'feature/PS-2' Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') } + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') } Initialize-LocalActionMergeBranches ` - -upstreamBranches @('feature/PS-1','infra/build-improvements') ` + -dependencyBranches @('feature/PS-1','infra/build-improvements') ` -noChangeBranches @('feature/PS-1','infra/build-improvements') ` -resultCommitish 'result-commitish' ` -source 'feature/PS-2' @@ -46,9 +46,9 @@ Describe 'git-verify-updated' { Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') } + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') } Initialize-LocalActionMergeBranches ` - -upstreamBranches @('feature/PS-1','infra/build-improvements') ` + -dependencyBranches @('feature/PS-1','infra/build-improvements') ` -noChangeBranches @('feature/PS-1','infra/build-improvements') ` -resultCommitish 'result-commitish' ` -source 'feature/PS-2' @@ -58,16 +58,16 @@ Describe 'git-verify-updated' { Invoke-VerifyMock $mocks -Times 1 } - It 'fails if there are no upstreams on the initial branch' { + It 'fails if there are no dependencies on the initial branch' { $mocks = @( Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ 'feature/PS-2' = @() } + Initialize-DependencyBranches @{ 'feature/PS-2' = @() } ) { & $PSScriptRoot/git-verify-updated.ps1 -target feature/PS-2 } - | Should -Throw 'ERR: feature/PS-2 has no upstream branches to verify.' + | Should -Throw 'ERR: feature/PS-2 has no dependency branches to verify.' Invoke-VerifyMock $mocks -Times 1 } @@ -76,9 +76,9 @@ Describe 'git-verify-updated' { Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') } + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') } Initialize-LocalActionMergeBranches ` - -upstreamBranches @('feature/PS-1','infra/build-improvements') ` + -dependencyBranches @('feature/PS-1','infra/build-improvements') ` -successfulBranches @('feature/PS-1') ` -noChangeBranches @('infra/build-improvements') ` -resultCommitish 'result-commitish' ` @@ -105,7 +105,7 @@ Describe 'git-verify-updated' { Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') 'feature/PS-1' = @('infra/ts-update') 'infra/build-improvements' = @('infra/ts-update') @@ -117,25 +117,25 @@ Describe 'git-verify-updated' { Initialize-LocalActionAssertPushedSuccess 'main' Initialize-LocalActionMergeBranches ` - -upstreamBranches @('main') ` + -dependencyBranches @('main') ` -noChangeBranches @('main') ` -resultCommitish $initialCommits["$($remotePrefix)infra/ts-update"] ` -source 'infra/ts-update' ` -initialCommits $initialCommits Initialize-LocalActionMergeBranches ` - -upstreamBranches @('infra/ts-update') ` + -dependencyBranches @('infra/ts-update') ` -noChangeBranches @('infra/ts-update') ` -resultCommitish $initialCommits["$($remotePrefix)infra/build-improvements"] ` -source 'infra/build-improvements' ` -initialCommits $initialCommits Initialize-LocalActionMergeBranches ` - -upstreamBranches @('infra/ts-update') ` + -dependencyBranches @('infra/ts-update') ` -noChangeBranches @('infra/ts-update') ` -resultCommitish $initialCommits["$($remotePrefix)feature/PS-1"] ` -source 'feature/PS-1' ` -initialCommits $initialCommits Initialize-LocalActionMergeBranches ` - -upstreamBranches @('feature/PS-1','infra/build-improvements') ` + -dependencyBranches @('feature/PS-1','infra/build-improvements') ` -noChangeBranches @('feature/PS-1','infra/build-improvements') ` -resultCommitish $initialCommits["$($remotePrefix)feature/PS-2"] ` -source 'feature/PS-2' ` @@ -161,7 +161,7 @@ Describe 'git-verify-updated' { Initialize-AssertValidBranchName 'feature/PS-2' Initialize-LocalActionAssertExistence -branches @('feature/PS-2') -shouldExist $true Initialize-LocalActionAssertPushedSuccess 'feature/PS-2' - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/PS-2' = @('feature/PS-1','infra/build-improvements') 'feature/PS-1' = @('infra/ts-update') 'infra/build-improvements' = @('infra/ts-update') @@ -173,19 +173,19 @@ Describe 'git-verify-updated' { Initialize-LocalActionAssertPushedSuccess 'main' Initialize-LocalActionMergeBranches ` - -upstreamBranches @('main') ` + -dependencyBranches @('main') ` -noChangeBranches @('main') ` -resultCommitish $initialCommits["$($remotePrefix)infra/ts-update"] ` -source 'infra/ts-update' ` -initialCommits $initialCommits Initialize-LocalActionMergeBranches ` - -upstreamBranches @('infra/ts-update') ` + -dependencyBranches @('infra/ts-update') ` -noChangeBranches @('infra/ts-update') ` -resultCommitish $initialCommits["$($remotePrefix)feature/PS-1"] ` -source 'feature/PS-1' ` -initialCommits $initialCommits Initialize-LocalActionMergeBranches ` - -upstreamBranches @('infra/ts-update') ` + -dependencyBranches @('infra/ts-update') ` -resultCommitish $initialCommits["$($remotePrefix)infra/build-improvements"] ` -source 'infra/build-improvements' ` -initialCommits $initialCommits @@ -212,7 +212,7 @@ Describe 'git-verify-updated' { } Add-StandardTests - + It 'uses the current branch if none specified, but fails if not pushed' { Initialize-CurrentBranch 'feature/PS-2' Initialize-AssertValidBranchName 'feature/PS-2' diff --git a/init.ps1 b/init.ps1 index 1b82d6b..d1eb866 100755 --- a/init.ps1 +++ b/init.ps1 @@ -8,38 +8,38 @@ git config alias.tool-config "!$dir/git-tool-config.ps1" # Allow self-updating on the current branch git config alias.tool-update "!$dir/git-tool-update.ps1" -# Check the upstream branch configuration for branches that no longer exist +# Check the dependency branch configuration for branches that no longer exist git config alias.tool-audit-prune "!$dir/git-tool-audit-prune.ps1" -# Check the upstream branch configuration for references to deeper upstreams and simplify +# Check the dependency branch configuration for references to deeper dependencies and simplify git config alias.tool-audit-simplify "!$dir/git-tool-audit-simplify.ps1" # Create a new branch git config alias.new "!$dir/git-new.ps1" -# Update current branch from its upstream/parent branches -git config alias.pull-upstream "!$dir/git-pull-upstream.ps1" +# Update current branch from its dependency/parent branches +git config alias.pull-deps "!$dir/git-pull-deps.ps1" -# List branches directly downstream from a branch -git config alias.show-downstream "!$dir/git-show-downstream.ps1" +# List branches directly dependants from a branch +git config alias.show-dependants "!$dir/git-show-dependants.ps1" -# List branches directly upstream from a branch -git config alias.show-upstream "!$dir/git-show-upstream.ps1" +# List branches directly dependency from a branch +git config alias.show-deps "!$dir/git-show-deps.ps1" -# Adds an upstream branch -git config alias.add-upstream "!$dir/git-add-upstream.ps1" +# Adds an dependency branch +git config alias.add-deps "!$dir/git-add-deps.ps1" # Build a release candidate from other branches git config alias.rc "!$dir/git-rc.ps1" -# Rebuild a branch from its upstreams +# Rebuild a branch from its dependencies git config alias.rebuild-rc "!$dir/git-rebuild-rc.ps1" -# Verify that a branch has all of its upstream up-to-date +# Verify that a branch has all of its dependency up-to-date git config alias.verify-updated "!$dir/git-verify-updated.ps1" -# Refactor upstream branches to redirect upstreams from "source" to "target" -git config alias.refactor-upstream "!$dir/git-refactor-upstream.ps1" +# Refactor dependency branches to redirect dependencies from "source" to "target" +git config alias.refactor-deps "!$dir/git-refactor-deps.ps1" # Release an RC branch to a service line git config alias.release "!$dir/git-release.ps1" diff --git a/migration/Invoke-Migration.psm1 b/migration/Invoke-Migration.psm1 index 4501167..a6d3baa 100644 --- a/migration/Invoke-Migration.psm1 +++ b/migration/Invoke-Migration.psm1 @@ -10,7 +10,7 @@ $migrations = @( Write-Host "Running migration, such as updating local configuration." # Migrations can do things like one-time `git config` changes in - # case our keys change, or adding in upstream tracking support for + # case our keys change, or adding in dependency tracking support for # multiple remotes, etc. This should consider local only to being on # the given version; remote does not (at this time) have a version # indicator, and will need that to be added for migrations first. diff --git a/utils/actions.mocks.psm1 b/utils/actions.mocks.psm1 index cb842c5..5cf18d8 100644 --- a/utils/actions.mocks.psm1 +++ b/utils/actions.mocks.psm1 @@ -7,11 +7,11 @@ Export-ModuleMember -Function Initialize-LocalActionAssertPushedNotTracked, Init Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionAssertUpdated.mocks.psm1" Export-ModuleMember -Function Initialize-LocalActionAssertUpdated -Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionGetAllUpstreams.mocks.psm1" -Export-ModuleMember -Function Initialize-AllUpstreamBranches +Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionGetAllDependencies.mocks.psm1" +Export-ModuleMember -Function Initialize-AllDependencyBranches -Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionGetUpstream.mocks.psm1" -Export-ModuleMember -Function Initialize-UpstreamBranches +Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionGetDependency.mocks.psm1" +Export-ModuleMember -Function Initialize-DependencyBranches Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionMergeBranches.mocks.psm1" Export-ModuleMember -Function Initialize-LocalActionMergeBranches,Initialize-LocalActionMergeBranchesFailure,Initialize-LocalActionMergeBranchesSuccess @@ -19,14 +19,14 @@ Export-ModuleMember -Function Initialize-LocalActionMergeBranches,Initialize-Loc Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionRecurse.mocks.psm1" Export-ModuleMember -Function Initialize-LocalActionRecurseSuccess -Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionSetUpstream.mocks.psm1" -Export-ModuleMember -Function Lock-LocalActionSetUpstream, Initialize-LocalActionSetUpstream +Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionSetDependency.mocks.psm1" +Export-ModuleMember -Function Lock-LocalActionSetDependency, Initialize-LocalActionSetDependency -Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionSimplifyUpstreamBranches.mocks.psm1" -Export-ModuleMember -Function Initialize-LocalActionSimplifyUpstreamBranchesSuccess,Initialize-LocalActionSimplifyUpstreamBranches +Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionSimplifyDependencyBranches.mocks.psm1" +Export-ModuleMember -Function Initialize-LocalActionSimplifyDependencyBranchesSuccess,Initialize-LocalActionSimplifyDependencyBranches -Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionUpstreamsUpdated.mocks.psm1" -Export-ModuleMember -Function Initialize-LocalActionUpstreamsUpdated +Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionDependenciesUpdated.mocks.psm1" +Export-ModuleMember -Function Initialize-LocalActionDependenciesUpdated Import-Module -Scope Local "$PSScriptRoot/actions/local/Register-LocalActionValidateBranchNames.mocks.psm1" Export-ModuleMember -Function Initialize-LocalActionValidateBranchNamesSuccess diff --git a/utils/actions/Invoke-LocalAction.psm1 b/utils/actions/Invoke-LocalAction.psm1 index 7ce179e..a3d9557 100644 --- a/utils/actions/Invoke-LocalAction.psm1 +++ b/utils/actions/Invoke-LocalAction.psm1 @@ -3,15 +3,15 @@ Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionAddDiagnosti Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionAssertPushed.psm1" Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionAssertUpdated.psm1" Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionEvaluate.psm1" -Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionGetAllUpstreams.psm1" -Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionGetUpstream.psm1" -Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionGetDownstream.psm1" +Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionGetAllDependencies.psm1" +Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionGetDependency.psm1" +Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionGetDependant.psm1" Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionFilterBranches.psm1" Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionMergeBranches.psm1" Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionRecurse.psm1" -Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionSetUpstream.psm1" -Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionSimplifyUpstreamBranches.psm1" -Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionUpstreamsUpdated.psm1" +Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionSetDependency.psm1" +Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionSimplifyDependencyBranches.psm1" +Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionDependenciesUpdated.psm1" Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionValidateBranchNames.psm1" Import-Module -Scope Local "$PSScriptRoot/local/Register-LocalActionAssertExistence.psm1" @@ -22,14 +22,14 @@ $localActions['assert-pushed'] = ${function:Invoke-AssertBranchPushedLocalAction $localActions['assert-updated'] = ${function:Invoke-AssertBranchUpToDateLocalAction} $localActions['evaluate'] = ${function:Invoke-EvaluateLocalAction} $localActions['filter-branches'] = ${function:Invoke-FilterBranchesLocalAction} -$localActions['get-all-upstreams'] = ${function:Invoke-GetAllUpstreamsLocalAction} -$localActions['get-downstream'] = ${function:Invoke-GetDownstreamLocalAction} -$localActions['get-upstream'] = ${function:Invoke-GetUpstreamLocalAction} +$localActions['get-all-dependencies'] = ${function:Invoke-GetAllDependenciesLocalAction} +$localActions['get-dependants'] = ${function:Invoke-GetDependantLocalAction} +$localActions['get-dependency'] = ${function:Invoke-GetDependencyLocalAction} $localActions['merge-branches'] = ${function:Invoke-MergeBranchesLocalAction} $localActions['recurse'] = ${function:Invoke-RecursiveScriptLocalAction} -$localActions['set-upstream'] = ${function:Invoke-SetUpstreamLocalAction} -$localActions['simplify-upstream'] = ${function:Invoke-SimplifyUpstreamLocalAction} -$localActions['upstreams-updated'] = ${function:Invoke-UpstreamsUpdatedLocalAction} +$localActions['set-dependency'] = ${function:Invoke-SetDependencyLocalAction} +$localActions['simplify-dependency'] = ${function:Invoke-SimplifyDependencyLocalAction} +$localActions['dependencies-updated'] = ${function:Invoke-DependenciesUpdatedLocalAction} $localActions['validate-branch-names'] = ${function:Invoke-AssertBranchNamesLocalAction} Export-ModuleMember -Function Invoke-LocalAction diff --git a/utils/actions/finalize/Register-FinalizeActionSetBranches.tests.ps1 b/utils/actions/finalize/Register-FinalizeActionSetBranches.tests.ps1 index 833bd57..8a255b4 100644 --- a/utils/actions/finalize/Register-FinalizeActionSetBranches.tests.ps1 +++ b/utils/actions/finalize/Register-FinalizeActionSetBranches.tests.ps1 @@ -8,7 +8,7 @@ Describe 'finalize action "set-branches"' { Import-Module -Scope Local "$PSScriptRoot/Register-FinalizeActionSetBranches.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { $fw = Register-Framework -throwInsteadOfExit @@ -17,11 +17,11 @@ Describe 'finalize action "set-branches"' { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $output = $fw.assertDiagnosticOutput [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $standardScript = ('{ - "type": "set-branches", + $standardScript = ('{ + "type": "set-branches", "parameters": { "branches": { - "_upstream": "new-upstream-commitish", + "$dependencies": "new-dependency-commitish", "other": "other-commitish", "another": "another-commitish", } @@ -29,7 +29,7 @@ Describe 'finalize action "set-branches"' { }' | ConvertFrom-Json) [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] [hashtable]$standardBranches = @{ - _upstream = "new-upstream-commitish"; + '$dependencies' = "new-dependency-commitish"; other ="other-commitish"; another ="another-commitish"; } @@ -43,25 +43,25 @@ Describe 'finalize action "set-branches"' { It 'handles standard functionality' { Initialize-NoCurrentBranch $mocks = @( - Initialize-AssertValidBranchName '_upstream' + Initialize-AssertValidBranchName '$dependencies' Initialize-AssertValidBranchName 'other' Initialize-AssertValidBranchName 'another' Invoke-MockGitModule -ModuleName 'Register-FinalizeActionSetBranches' ` - -gitCli "branch _upstream new-upstream-commitish -f" + -gitCli "branch `$dependencies new-dependency-commitish -f" Invoke-MockGitModule -ModuleName 'Register-FinalizeActionSetBranches' ` -gitCli "branch other other-commitish -f" Invoke-MockGitModule -ModuleName 'Register-FinalizeActionSetBranches' ` -gitCli "branch another another-commitish -f" ) - + Invoke-FinalizeAction $standardScript -diagnostics $diag $diag | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } It 'handles standard functionality for a single branch' { - $standardScript = ('{ - "type": "set-branches", + $standardScript = ('{ + "type": "set-branches", "parameters": { "branches": { "other": "other-commitish" @@ -74,7 +74,7 @@ Describe 'finalize action "set-branches"' { Invoke-MockGitModule -ModuleName 'Register-FinalizeActionSetBranches' ` -gitCli "branch other other-commitish -f" ) - + Invoke-FinalizeAction $standardScript -diagnostics $diag $diag | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 @@ -83,16 +83,16 @@ Describe 'finalize action "set-branches"' { It 'can execute a dry run' { Initialize-NoCurrentBranch $mocks = @( - Initialize-AssertValidBranchName '_upstream' + Initialize-AssertValidBranchName '$dependencies' Initialize-AssertValidBranchName 'other' Initialize-AssertValidBranchName 'another' ) - + $dryRunCommands = Invoke-FinalizeAction $standardScript -diagnostics $diag -dryRun $diag | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 - $dryRunCommands | Should -Contain 'git branch _upstream "new-upstream-commitish" -f' + $dryRunCommands | Should -Contain 'git branch $dependencies "new-dependency-commitish" -f' $dryRunCommands | Should -Contain 'git branch other "other-commitish" -f' $dryRunCommands | Should -Contain 'git branch another "another-commitish" -f' } @@ -119,7 +119,7 @@ Describe 'finalize action "set-branches"' { $diag | Should -BeNullOrEmpty Invoke-VerifyMock $mocks -Times 1 } - + It 'ensures the current branch, if updated, is clean' { Initialize-CurrentBranch 'another' $mocks = Initialize-FinalizeActionSetBranches $standardBranches -currentBranchDirty @@ -137,13 +137,13 @@ Describe 'finalize action "set-branches"' { It 'handles standard functionality' { $mocks = @( - Initialize-AssertValidBranchName '_upstream' + Initialize-AssertValidBranchName '$dependencies' Initialize-AssertValidBranchName 'other' Initialize-AssertValidBranchName 'another' Invoke-MockGitModule -ModuleName 'Register-FinalizeActionSetBranches' ` - -gitCli "push origin --atomic new-upstream-commitish:refs/heads/_upstream another-commitish:refs/heads/another other-commitish:refs/heads/other" + -gitCli "push origin --atomic new-dependency-commitish:refs/heads/`$dependencies another-commitish:refs/heads/another other-commitish:refs/heads/other" ) - + Invoke-FinalizeAction $standardScript -diagnostics $diag $diag | Should -Be $null Invoke-VerifyMock $mocks -Times 1 @@ -163,12 +163,12 @@ Describe 'finalize action "set-branches"' { } It 'reports force-push' { - $standardScript = ('{ - "type": "set-branches", + $standardScript = ('{ + "type": "set-branches", "parameters": { "force": true, "branches": { - "_upstream": "new-upstream-commitish", + "$dependencies": "new-dependency-commitish", "other": "other-commitish", "another": "another-commitish", } @@ -187,13 +187,13 @@ Describe 'finalize action "set-branches"' { It 'handles standard functionality' { $mocks = @( - Initialize-AssertValidBranchName '_upstream' + Initialize-AssertValidBranchName '$dependencies' Initialize-AssertValidBranchName 'other' Initialize-AssertValidBranchName 'another' Invoke-MockGitModule -ModuleName 'Register-FinalizeActionSetBranches' ` - -gitCli "push origin new-upstream-commitish:refs/heads/_upstream another-commitish:refs/heads/another other-commitish:refs/heads/other" + -gitCli "push origin new-dependency-commitish:refs/heads/`$dependencies another-commitish:refs/heads/another other-commitish:refs/heads/other" ) - + Invoke-FinalizeAction $standardScript -diagnostics $diag $diag | Should -Be $null Invoke-VerifyMock $mocks -Times 1 @@ -213,12 +213,12 @@ Describe 'finalize action "set-branches"' { } It 'supports force-push' { - $standardScript = ('{ - "type": "set-branches", + $standardScript = ('{ + "type": "set-branches", "parameters": { "force": true, "branches": { - "_upstream": "new-upstream-commitish", + "$dependencies": "new-dependency-commitish", "other": "other-commitish", "another": "another-commitish", } diff --git a/utils/actions/finalize/Register-FinalizeActionTrack.mocks.psm1 b/utils/actions/finalize/Register-FinalizeActionTrack.mocks.psm1 index f59e9c1..9d9a876 100644 --- a/utils/actions/finalize/Register-FinalizeActionTrack.mocks.psm1 +++ b/utils/actions/finalize/Register-FinalizeActionTrack.mocks.psm1 @@ -55,7 +55,7 @@ function Initialize-FinalizeActionTrackSuccess( } else { Initialize-CleanWorkingDirectory if ($untracked -contains $currentBranch) { - Invoke-MockGit "branch $currentBranch --set-upstream-to refs/remotes/$($config.remote)/$currentBranch" + Invoke-MockGit "branch $currentBranch --set-dependency-to refs/remotes/$($config.remote)/$currentBranch" } Invoke-MockGit "reset --hard refs/remotes/$($config.remote)/$branch" } diff --git a/utils/actions/finalize/Register-FinalizeActionTrack.psm1 b/utils/actions/finalize/Register-FinalizeActionTrack.psm1 index c0772e4..6b8b2ff 100644 --- a/utils/actions/finalize/Register-FinalizeActionTrack.psm1 +++ b/utils/actions/finalize/Register-FinalizeActionTrack.psm1 @@ -27,14 +27,14 @@ function Invoke-TrackFinalizeAction { # current branch matches tracked one, but doesn't currently track the remote $localBranch = $currentBranch if ($dryRun) { - "git branch $localBranch --set-upstream-to `"refs/remotes/$($config.remote)/$branch`"" + "git branch $localBranch --set-dependency-to `"refs/remotes/$($config.remote)/$branch`"" } else { - Invoke-ProcessLogs "git branch $localBranch --set-upstream-to refs/remotes/$($config.remote)/$branch" { - git branch $localBranch --set-upstream-to "refs/remotes/$($config.remote)/$branch" + Invoke-ProcessLogs "git branch $localBranch --set-dependency-to refs/remotes/$($config.remote)/$branch" { + git branch $localBranch --set-dependency-to "refs/remotes/$($config.remote)/$branch" } } } - + if ($currentBranch -eq $localBranch) { # update head Assert-CleanWorkingDirectory -diagnostics $diagnostics diff --git a/utils/actions/local/Register-LocalActionAssertUpdated.mocks.psm1 b/utils/actions/local/Register-LocalActionAssertUpdated.mocks.psm1 index 58a0cf3..90d8a24 100644 --- a/utils/actions/local/Register-LocalActionAssertUpdated.mocks.psm1 +++ b/utils/actions/local/Register-LocalActionAssertUpdated.mocks.psm1 @@ -12,20 +12,20 @@ function Get-CommitsWithRemote( } function Initialize-LocalActionAssertUpdated( - [Parameter()][string] $downstream, - [Parameter()][string] $upstream, + [Parameter()][string] $dependants, + [Parameter()][string] $dependency, [Parameter()][Hashtable] $initialCommits = @{}, [switch] $withChanges, [switch] $withConflict ) { - $resultCommit = $initialCommits[$downstream] ?? 'result-commitish' - $downstream = Get-RemoteBranchRef $downstream - $upstream = Get-RemoteBranchRef $upstream + $resultCommit = $initialCommits[$dependants] ?? 'result-commitish' + $dependants = Get-RemoteBranchRef $dependants + $dependency = Get-RemoteBranchRef $dependency $base = @{ - allBranches = @($upstream) + allBranches = @($dependency) initialCommits = (Get-CommitsWithRemote $initialCommits) - source = $downstream + source = $dependants messageTemplate = 'Verification Only' resultCommitish = $resultCommit } @@ -36,12 +36,12 @@ function Initialize-LocalActionAssertUpdated( -noChangeBranches @() } elseif ($withChanges) { Initialize-MergeTogether @base ` - -successfulBranches @($upstream) ` + -successfulBranches @($dependency) ` -noChangeBranches @() } else { Initialize-MergeTogether @base ` -successfulBranches @() ` - -noChangeBranches @($upstream) + -noChangeBranches @($dependency) } } diff --git a/utils/actions/local/Register-LocalActionAssertUpdated.psm1 b/utils/actions/local/Register-LocalActionAssertUpdated.psm1 index be598e0..ffff26b 100644 --- a/utils/actions/local/Register-LocalActionAssertUpdated.psm1 +++ b/utils/actions/local/Register-LocalActionAssertUpdated.psm1 @@ -5,25 +5,25 @@ Import-Module -Scope Local "$PSScriptRoot/../../git.psm1" function Invoke-AssertBranchUpToDateLocalAction { param( - [Parameter()][string] $downstream, - [Parameter()][string] $upstream, + [Parameter()][string] $dependants, + [Parameter()][string] $dependency, [hashtable] $commitMappingOverride = @{}, [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics ) - # Verifies that everything in "upstream" is in "downstream". Asserts if not. + # Verifies that everything in "dependency" is in "dependants". Asserts if not. $mergeResult = Invoke-MergeTogether ` - -source (Get-RemoteBranchRef $downstream) ` - -commitishes @(Get-RemoteBranchRef $upstream) ` + -source (Get-RemoteBranchRef $dependants) ` + -commitishes @(Get-RemoteBranchRef $dependency) ` -messageTemplate 'Verification Only' ` -commitMappingOverride $commitMappingOverride ` -diagnostics $diagnostics ` -noFailureMessages if ($mergeResult.failed) { - Add-ErrorDiagnostic $diagnostics "The branch $upstream conflicts with $downstream" + Add-ErrorDiagnostic $diagnostics "The branch $dependency conflicts with $dependants" } elseif ($mergeResult.hasChanges) { - Add-ErrorDiagnostic $diagnostics "The branch $upstream has changes that are not in $downstream" + Add-ErrorDiagnostic $diagnostics "The branch $dependency has changes that are not in $dependants" } return @{} diff --git a/utils/actions/local/Register-LocalActionAssertUpdated.tests.ps1 b/utils/actions/local/Register-LocalActionAssertUpdated.tests.ps1 index ce9ff8c..e7f22da 100644 --- a/utils/actions/local/Register-LocalActionAssertUpdated.tests.ps1 +++ b/utils/actions/local/Register-LocalActionAssertUpdated.tests.ps1 @@ -7,17 +7,17 @@ Describe 'local action "assert-updated"' { Import-Module -Scope Local "$PSScriptRoot/../../actions.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $standardScript = ('{ - "type": "assert-updated", + $standardScript = ('{ + "type": "assert-updated", "parameters": { - "downstream": "rc/next", - "upstream": "main", + "dependants": "rc/next", + "dependency": "main", } }' | ConvertFrom-Json) @@ -25,7 +25,7 @@ Describe 'local action "assert-updated"' { } It 'handles successful cases' { - Initialize-LocalActionAssertUpdated -downstream 'rc/next' -upstream 'main' + Initialize-LocalActionAssertUpdated -dependants 'rc/next' -dependency 'main' Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics @@ -34,7 +34,7 @@ Describe 'local action "assert-updated"' { } It 'reports an error for conflicts' { - Initialize-LocalActionAssertUpdated -downstream 'rc/next' -upstream 'main' -withConflict + Initialize-LocalActionAssertUpdated -dependants 'rc/next' -dependency 'main' -withConflict Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics @@ -43,7 +43,7 @@ Describe 'local action "assert-updated"' { } It 'reports an error if there are changes' { - Initialize-LocalActionAssertUpdated -downstream 'rc/next' -upstream 'main' -withChanges + Initialize-LocalActionAssertUpdated -dependants 'rc/next' -dependency 'main' -withChanges Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics diff --git a/utils/actions/local/Register-LocalActionUpstreamsUpdated.mocks.psm1 b/utils/actions/local/Register-LocalActionDependenciesUpdated.mocks.psm1 similarity index 56% rename from utils/actions/local/Register-LocalActionUpstreamsUpdated.mocks.psm1 rename to utils/actions/local/Register-LocalActionDependenciesUpdated.mocks.psm1 index cf8e2f5..dec43ce 100644 --- a/utils/actions/local/Register-LocalActionUpstreamsUpdated.mocks.psm1 +++ b/utils/actions/local/Register-LocalActionDependenciesUpdated.mocks.psm1 @@ -2,21 +2,21 @@ Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../testing.psm1" -Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionUpstreamsUpdated.psm1" +Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionDependenciesUpdated.psm1" function Invoke-MockGit([string] $gitCli, [object] $MockWith) { - return Invoke-MockGitModule -ModuleName 'Register-LocalActionUpstreamsUpdated' @PSBoundParameters + return Invoke-MockGitModule -ModuleName 'Register-LocalActionDependenciesUpdated' @PSBoundParameters } -function Initialize-LocalActionUpstreamsUpdated( +function Initialize-LocalActionDependenciesUpdated( [Parameter()][AllowEmptyCollection()][string[]] $upToDate, [Parameter()][Hashtable] $outOfDate, - [Parameter()][AllowNull()] $overrideUpstreams, + [Parameter()][AllowNull()] $overrideDependencies, [switch] $recurse ) { $selectStandardParams = @{ recurse = $recurse - overrideUpstreams = $overrideUpstreams + overrideDependencies = $overrideDependencies } $config = Get-Configuration @@ -25,18 +25,18 @@ function Initialize-LocalActionUpstreamsUpdated( $branches = ($upToDate + $outOfDate.Keys) | Where-Object { $_ } if ($null -eq $branches) { return } foreach ($branch in $branches) { - $upstreams = Select-UpstreamBranches -branch $branch @selectStandardParams + $dependencies = Select-DependencyBranches -branch $branch @selectStandardParams $target = "$prefix/$branch" - $fullyQualifiedUpstreams = $upstreams | ForEach-Object { "$prefix/$_" } + $fullyQualifiedDependencies = $dependencies | ForEach-Object { "$prefix/$_" } if ($upToDate -contains $branch) { - Invoke-MockGit "for-each-ref --format=%(refname:lstrip=3) %(ahead-behind:$target) $fullyQualifiedUpstreams" ` - -mockWith (($upstreams | ForEach-Object { "$_ 0 5" })) + Invoke-MockGit "for-each-ref --format=%(refname:lstrip=3) %(ahead-behind:$target) $fullyQualifiedDependencies" ` + -mockWith (($dependencies | ForEach-Object { "$_ 0 5" })) } else { - Invoke-MockGit "for-each-ref --format=%(refname:lstrip=3) %(ahead-behind:$target) $fullyQualifiedUpstreams" ` - -mockWith (($upstreams | ForEach-Object { "$_ $($outOfDate[$branch] -contains $_ ? '1' : '0' ) 5" })) + Invoke-MockGit "for-each-ref --format=%(refname:lstrip=3) %(ahead-behind:$target) $fullyQualifiedDependencies" ` + -mockWith (($dependencies | ForEach-Object { "$_ $($outOfDate[$branch] -contains $_ ? '1' : '0' ) 5" })) } } } -Export-ModuleMember -Function Initialize-LocalActionUpstreamsUpdated +Export-ModuleMember -Function Initialize-LocalActionDependenciesUpdated diff --git a/utils/actions/local/Register-LocalActionUpstreamsUpdated.psm1 b/utils/actions/local/Register-LocalActionDependenciesUpdated.psm1 similarity index 54% rename from utils/actions/local/Register-LocalActionUpstreamsUpdated.psm1 rename to utils/actions/local/Register-LocalActionDependenciesUpdated.psm1 index 59ce0ff..085563f 100644 --- a/utils/actions/local/Register-LocalActionUpstreamsUpdated.psm1 +++ b/utils/actions/local/Register-LocalActionDependenciesUpdated.psm1 @@ -2,36 +2,36 @@ Import-Module -Scope Local "$PSScriptRoot/../../core.psm1" Import-Module -Scope Local "$PSScriptRoot/../../framework.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" -function Invoke-UpstreamsUpdatedLocalAction { +function Invoke-DependenciesUpdatedLocalAction { param( [Parameter()][AllowEmptyCollection()][string[]] $branches, - [Parameter()][AllowNull()] $overrideUpstreams, + [Parameter()][AllowNull()] $overrideDependencies, [Parameter()][bool] $recurse = $false, [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics ) $selectStandardParams = @{ recurse = $recurse - overrideUpstreams = $overrideUpstreams + overrideDependencies = $overrideDependencies } $config = Get-Configuration $prefix = $config.remote ? "refs/remotes/$($config.remote)" : "refs/heads/" $needsUpdate = @{} $isUpdated = @() - $noUpstreams = @() + $noDependencies = @() foreach ($branch in $branches) { - $upstreams = Select-UpstreamBranches -branch $branch @selectStandardParams - if (-not $upstreams) { - $noUpstreams += $branch + $dependencies = Select-DependencyBranches -branch $branch @selectStandardParams + if (-not $dependencies) { + $noDependencies += $branch continue } $target = "$prefix/$branch" - [string[]]$fullyQualifiedUpstreams = $upstreams | ForEach-Object { "$prefix/$_" } - [string[]]$upstreamResults = Invoke-ProcessLogs "git for-each-ref --format=`"%(refname:lstrip=3) %(ahead-behind:$target)`" $fullyQualifiedUpstreams" { - git for-each-ref --format="%(refname:lstrip=3) %(ahead-behind:$target)" @fullyQualifiedUpstreams + [string[]]$fullyQualifiedDependencies = $dependencies | ForEach-Object { "$prefix/$_" } + [string[]]$dependencyResults = Invoke-ProcessLogs "git for-each-ref --format=`"%(refname:lstrip=3) %(ahead-behind:$target)`" $fullyQualifiedDependencies" { + git for-each-ref --format="%(refname:lstrip=3) %(ahead-behind:$target)" @fullyQualifiedDependencies } -allowSuccessOutput - $outOfDate = ($upstreamResults | Where-Object { ($_ -split ' ')[1] -gt 0 } | ForEach-Object { ($_ -split ' ')[0] }) + $outOfDate = ($dependencyResults | Where-Object { ($_ -split ' ')[1] -gt 0 } | ForEach-Object { ($_ -split ' ')[0] }) if ($outOfDate.Count -gt 0) { $needsUpdate[$branch] = $outOfDate } else { @@ -40,10 +40,10 @@ function Invoke-UpstreamsUpdatedLocalAction { } return @{ - noUpstreams = $noUpstreams + noDependencies = $noDependencies needsUpdate = $needsUpdate isUpdated = $isUpdated } } -Export-ModuleMember -Function Invoke-UpstreamsUpdatedLocalAction +Export-ModuleMember -Function Invoke-DependenciesUpdatedLocalAction diff --git a/utils/actions/local/Register-LocalActionUpstreamsUpdated.tests.ps1 b/utils/actions/local/Register-LocalActionDependenciesUpdated.tests.ps1 similarity index 77% rename from utils/actions/local/Register-LocalActionUpstreamsUpdated.tests.ps1 rename to utils/actions/local/Register-LocalActionDependenciesUpdated.tests.ps1 index 3c505a5..063819e 100644 --- a/utils/actions/local/Register-LocalActionUpstreamsUpdated.tests.ps1 +++ b/utils/actions/local/Register-LocalActionDependenciesUpdated.tests.ps1 @@ -1,4 +1,4 @@ -Describe 'local action "upstreams-updated"' { +Describe 'local action "dependencies-updated"' { BeforeAll { Import-Module -Scope Local "$PSScriptRoot/../../framework.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" @@ -7,12 +7,12 @@ Describe 'local action "upstreams-updated"' { Import-Module -Scope Local "$PSScriptRoot/../../actions.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-456' = @("infra/add-services", "infra/refactor-api") 'feature/FOO-123' = @("infra/add-services") 'infra/add-services' = @("main") @@ -24,8 +24,8 @@ Describe 'local action "upstreams-updated"' { Context 'without recursion' { BeforeAll { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $standardScript = ('{ - "type": "upstreams-updated", + $standardScript = ('{ + "type": "dependencies-updated", "parameters": { "branches": ["feature/FOO-456", "feature/FOO-123"] } @@ -33,11 +33,11 @@ Describe 'local action "upstreams-updated"' { } It 'reports when everything is up-to-date' { - $mocks = Initialize-LocalActionUpstreamsUpdated @('feature/FOO-456', 'feature/FOO-123') - + $mocks = Initialize-LocalActionDependenciesUpdated @('feature/FOO-456', 'feature/FOO-123') + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - - $outputs.noUpstreams | Should -BeNullOrEmpty + + $outputs.noDependencies | Should -BeNullOrEmpty $outputs.needsUpdate.Keys | Should -BeNullOrEmpty $outputs.isUpdated | Should -Contain 'feature/FOO-456' $outputs.isUpdated | Should -Contain 'feature/FOO-123' @@ -46,18 +46,18 @@ Describe 'local action "upstreams-updated"' { Invoke-VerifyMock $mocks -Times 1 } - It 'reports when there are no upstreams' { - $standardScript = ('{ - "type": "upstreams-updated", + It 'reports when there are no dependencies' { + $standardScript = ('{ + "type": "dependencies-updated", "parameters": { "branches": ["unknown"] } }' | ConvertFrom-Json) - $mocks = Initialize-LocalActionUpstreamsUpdated @() - + $mocks = Initialize-LocalActionDependenciesUpdated @() + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - - $outputs.noUpstreams | Should -Contain 'unknown' + + $outputs.noDependencies | Should -Contain 'unknown' $outputs.needsUpdate.Keys | Should -BeNullOrEmpty $outputs.isUpdated | Should -BeNullOrEmpty Invoke-FlushAssertDiagnostic $fw.diagnostics @@ -66,11 +66,11 @@ Describe 'local action "upstreams-updated"' { } It 'reports when everything is up-to-date' { - $mocks = Initialize-LocalActionUpstreamsUpdated @('feature/FOO-456', 'feature/FOO-123') - + $mocks = Initialize-LocalActionDependenciesUpdated @('feature/FOO-456', 'feature/FOO-123') + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - - $outputs.noUpstreams | Should -BeNullOrEmpty + + $outputs.noDependencies | Should -BeNullOrEmpty $outputs.needsUpdate.Keys | Should -BeNullOrEmpty $outputs.isUpdated | Should -Contain 'feature/FOO-456' $outputs.isUpdated | Should -Contain 'feature/FOO-123' @@ -80,11 +80,11 @@ Describe 'local action "upstreams-updated"' { } It 'reports when a single branch is out of date' { - $mocks = Initialize-LocalActionUpstreamsUpdated @('feature/FOO-456') -outOfDate @{ 'feature/FOO-123' = @('infra/add-services') } - + $mocks = Initialize-LocalActionDependenciesUpdated @('feature/FOO-456') -outOfDate @{ 'feature/FOO-123' = @('infra/add-services') } + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - - $outputs.noUpstreams | Should -BeNullOrEmpty + + $outputs.noDependencies | Should -BeNullOrEmpty $outputs.isUpdated | Should -Contain 'feature/FOO-456' $outputs.needsUpdate['feature/FOO-123'] | Should -Contain 'infra/add-services' Invoke-FlushAssertDiagnostic $fw.diagnostics @@ -93,11 +93,11 @@ Describe 'local action "upstreams-updated"' { } It 'reports when a multiple branches are out of date' { - $mocks = Initialize-LocalActionUpstreamsUpdated -outOfDate @{ 'feature/FOO-123' = @('infra/add-services'); 'feature/FOO-456' = @('infra/refactor-api') } - + $mocks = Initialize-LocalActionDependenciesUpdated -outOfDate @{ 'feature/FOO-123' = @('infra/add-services'); 'feature/FOO-456' = @('infra/refactor-api') } + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - - $outputs.noUpstreams | Should -BeNullOrEmpty + + $outputs.noDependencies | Should -BeNullOrEmpty $outputs.isUpdated | Should -BeNullOrEmpty $outputs.needsUpdate['feature/FOO-123'] | Should -Contain @('infra/add-services') $outputs.needsUpdate['feature/FOO-456'] | Should -Be @('infra/refactor-api') @@ -106,12 +106,12 @@ Describe 'local action "upstreams-updated"' { Invoke-VerifyMock $mocks -Times 1 } } - + Context 'with recursion' { BeforeAll { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $standardScript = ('{ - "type": "upstreams-updated", + $standardScript = ('{ + "type": "dependencies-updated", "parameters": { "branches": ["feature/FOO-456", "feature/FOO-123"], "recurse": true @@ -120,10 +120,10 @@ Describe 'local action "upstreams-updated"' { } It 'reports when everything is up-to-date' { - $mocks = Initialize-LocalActionUpstreamsUpdated @('feature/FOO-456', 'feature/FOO-123') -recurse - + $mocks = Initialize-LocalActionDependenciesUpdated @('feature/FOO-456', 'feature/FOO-123') -recurse + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - + $outputs.needsUpdate.Keys | Should -BeNullOrEmpty $outputs.isUpdated | Should -Contain 'feature/FOO-456' $outputs.isUpdated | Should -Contain 'feature/FOO-123' @@ -133,10 +133,10 @@ Describe 'local action "upstreams-updated"' { } It 'reports when a single branch is out of date' { - $mocks = Initialize-LocalActionUpstreamsUpdated @('feature/FOO-456') -outOfDate @{ 'feature/FOO-123' = @('main') } -recurse - + $mocks = Initialize-LocalActionDependenciesUpdated @('feature/FOO-456') -outOfDate @{ 'feature/FOO-123' = @('main') } -recurse + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - + $outputs.isUpdated | Should -Contain 'feature/FOO-456' $outputs.needsUpdate['feature/FOO-123'] | Should -Contain 'main' Invoke-FlushAssertDiagnostic $fw.diagnostics @@ -145,10 +145,10 @@ Describe 'local action "upstreams-updated"' { } It 'reports when a multiple branches are out of date' { - $mocks = Initialize-LocalActionUpstreamsUpdated -outOfDate @{ 'feature/FOO-123' = @('main'); 'feature/FOO-456' = @('infra/refactor-api') } -recurse - + $mocks = Initialize-LocalActionDependenciesUpdated -outOfDate @{ 'feature/FOO-123' = @('main'); 'feature/FOO-456' = @('infra/refactor-api') } -recurse + $outputs = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - + $outputs.isUpdated | Should -BeNullOrEmpty $outputs.needsUpdate['feature/FOO-123'] | Should -Contain @('main') $outputs.needsUpdate['feature/FOO-456'] | Should -Be @('infra/refactor-api') @@ -167,22 +167,22 @@ Describe 'local action "upstreams-updated"' { Add-StandardTests It 'allows for overrides' { - $script = ('{ - "type": "upstreams-updated", + $script = ('{ + "type": "dependencies-updated", "parameters": { "branches": ["feature/FOO-123"], - "overrideUpstreams": { + "overrideDependencies": { "feature/FOO-123": ["main"] } } }' | ConvertFrom-Json) - - $mocks = Initialize-LocalActionUpstreamsUpdated @('feature/FOO-123') -recurse -overrideUpstreams:@{ + + $mocks = Initialize-LocalActionDependenciesUpdated @('feature/FOO-123') -recurse -overrideDependencies:@{ "feature/FOO-123" = @("main") } - + $outputs = Invoke-LocalAction $script -diagnostics $fw.diagnostics - + $outputs.needsUpdate.Keys | Should -BeNullOrEmpty $outputs.isUpdated | Should -Contain 'feature/FOO-123' Invoke-FlushAssertDiagnostic $fw.diagnostics diff --git a/utils/actions/local/Register-LocalActionGetAllUpstreams.mocks.psm1 b/utils/actions/local/Register-LocalActionGetAllDependencies.mocks.psm1 similarity index 53% rename from utils/actions/local/Register-LocalActionGetAllUpstreams.mocks.psm1 rename to utils/actions/local/Register-LocalActionGetAllDependencies.mocks.psm1 index 7562e58..7650604 100644 --- a/utils/actions/local/Register-LocalActionGetAllUpstreams.mocks.psm1 +++ b/utils/actions/local/Register-LocalActionGetAllDependencies.mocks.psm1 @@ -1,3 +1,3 @@ Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" -Export-ModuleMember -Function Initialize-AllUpstreamBranches +Export-ModuleMember -Function Initialize-AllDependencyBranches diff --git a/utils/actions/local/Register-LocalActionGetAllUpstreams.psm1 b/utils/actions/local/Register-LocalActionGetAllDependencies.psm1 similarity index 54% rename from utils/actions/local/Register-LocalActionGetAllUpstreams.psm1 rename to utils/actions/local/Register-LocalActionGetAllDependencies.psm1 index 36c70a9..0aafc33 100644 --- a/utils/actions/local/Register-LocalActionGetAllUpstreams.psm1 +++ b/utils/actions/local/Register-LocalActionGetAllDependencies.psm1 @@ -2,13 +2,13 @@ Import-Module -Scope Local "$PSScriptRoot/../../core.psm1" Import-Module -Scope Local "$PSScriptRoot/../../framework.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" -function Invoke-GetAllUpstreamsLocalAction { +function Invoke-GetAllDependenciesLocalAction { param( - [Parameter()][AllowNull()] $overrideUpstreams, + [Parameter()][AllowNull()] $overrideDependencies, [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics ) - return Select-AllUpstreamBranches -overrideUpstreams:$overrideUpstreams + return Select-AllDependencyBranches -overrideDependencies:$overrideDependencies } -Export-ModuleMember -Function Invoke-GetAllUpstreamsLocalAction +Export-ModuleMember -Function Invoke-GetAllDependenciesLocalAction diff --git a/utils/actions/local/Register-LocalActionGetAllUpstreams.tests.ps1 b/utils/actions/local/Register-LocalActionGetAllDependencies.tests.ps1 similarity index 90% rename from utils/actions/local/Register-LocalActionGetAllUpstreams.tests.ps1 rename to utils/actions/local/Register-LocalActionGetAllDependencies.tests.ps1 index 23caf66..5052289 100644 --- a/utils/actions/local/Register-LocalActionGetAllUpstreams.tests.ps1 +++ b/utils/actions/local/Register-LocalActionGetAllDependencies.tests.ps1 @@ -1,4 +1,4 @@ -Describe 'local action "get-all-upstreams"' { +Describe 'local action "get-all-dependencies"' { BeforeAll { Import-Module -Scope Local "$PSScriptRoot/../../framework.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" @@ -7,7 +7,7 @@ Describe 'local action "get-all-upstreams"' { Import-Module -Scope Local "$PSScriptRoot/../../actions.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { Initialize-ToolConfiguration @@ -15,15 +15,15 @@ Describe 'local action "get-all-upstreams"' { $fw = Register-Framework [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $standardScript = ('{ - "type": "get-all-upstreams", + $standardScript = ('{ + "type": "get-all-dependencies", "parameters": { } }' | ConvertFrom-Json) } - It 'returns all upstream data' { - Initialize-AllUpstreamBranches @{ + It 'returns all dependency data' { + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123") 'feature/FOO-123' = @("main") @@ -49,9 +49,9 @@ Describe 'local action "get-all-upstreams"' { $results['rc/1.1.0'] | Should -Contain "feature/FOO-123" $results['rc/1.1.0'] | Should -Contain "feature/XYZ-1-services" } - - It 'can override upstreams' { - Initialize-AllUpstreamBranches @{ + + It 'can override dependencies' { + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123") 'feature/FOO-123' = @("main") @@ -61,10 +61,10 @@ Describe 'local action "get-all-upstreams"' { 'bad-recursive-branch-1' = @('bad-recursive-branch-2') 'bad-recursive-branch-2' = @('bad-recursive-branch-1') } - $script = ('{ - "type": "get-all-upstreams", + $script = ('{ + "type": "get-all-dependencies", "parameters": { - "overrideUpstreams": { + "overrideDependencies": { "feature/FOO-123": "infra/new", "infra/new": "main" } diff --git a/utils/actions/local/Register-LocalActionGetDownstream.psm1 b/utils/actions/local/Register-LocalActionGetDependant.psm1 similarity index 58% rename from utils/actions/local/Register-LocalActionGetDownstream.psm1 rename to utils/actions/local/Register-LocalActionGetDependant.psm1 index f78dec3..97631e1 100644 --- a/utils/actions/local/Register-LocalActionGetDownstream.psm1 +++ b/utils/actions/local/Register-LocalActionGetDependant.psm1 @@ -2,17 +2,17 @@ Import-Module -Scope Local "$PSScriptRoot/../../core.psm1" Import-Module -Scope Local "$PSScriptRoot/../../framework.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" -function Invoke-GetDownstreamLocalAction { +function Invoke-GetDependantLocalAction { param( [Parameter(Mandatory)][string] $target, - [Parameter()][AllowNull()] $overrideUpstreams, + [Parameter()][AllowNull()] $overrideDependencies, [switch] $recurse, [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics ) - [string[]]$result = Select-DownstreamBranches -branchName $target -recurse:$recurse -overrideUpstreams:$overrideUpstreams + [string[]]$result = Select-DependantBranches -branchName $target -recurse:$recurse -overrideDependencies:$overrideDependencies return $result } -Export-ModuleMember -Function Invoke-GetDownstreamLocalAction +Export-ModuleMember -Function Invoke-GetDependantLocalAction diff --git a/utils/actions/local/Register-LocalActionGetDownstream.tests.ps1 b/utils/actions/local/Register-LocalActionGetDependant.tests.ps1 similarity index 87% rename from utils/actions/local/Register-LocalActionGetDownstream.tests.ps1 rename to utils/actions/local/Register-LocalActionGetDependant.tests.ps1 index a5623e8..0808ab5 100644 --- a/utils/actions/local/Register-LocalActionGetDownstream.tests.ps1 +++ b/utils/actions/local/Register-LocalActionGetDependant.tests.ps1 @@ -1,4 +1,4 @@ -Describe 'local action "get-downstream"' { +Describe 'local action "get-dependants"' { BeforeAll { Import-Module -Scope Local "$PSScriptRoot/../../framework.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" @@ -7,14 +7,14 @@ Describe 'local action "get-downstream"' { Import-Module -Scope Local "$PSScriptRoot/../../actions.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { Initialize-ToolConfiguration [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123") 'feature/FOO-123' = @("main") @@ -26,9 +26,9 @@ Describe 'local action "get-downstream"' { } } - It 'gets downstream branches' { + It 'gets dependants branches' { $result = Invoke-LocalAction ('{ - "type": "get-downstream", + "type": "get-dependants", "parameters": { "target": "feature/FOO-123", "recurse": false @@ -42,9 +42,9 @@ Describe 'local action "get-downstream"' { $result | Should -Contain 'feature/FOO-124' } - It 'gets downstream branches recursively' { + It 'gets dependants branches recursively' { $result = Invoke-LocalAction ('{ - "type": "get-downstream", + "type": "get-dependants", "parameters": { "target": "feature/FOO-123", "recurse": true @@ -59,12 +59,12 @@ Describe 'local action "get-downstream"' { $result | Should -Contain 'rc/1.1.0' } - It 'gets downstream branches with overrides' { + It 'gets dependants branches with overrides' { [string[]]$result = Invoke-LocalAction ('{ - "type": "get-downstream", + "type": "get-dependants", "parameters": { "target": "infra/new", - "overrideUpstreams": { + "overrideDependencies": { "feature/FOO-123": "infra/new", "infra/new": "main" } diff --git a/utils/actions/local/Register-LocalActionGetUpstream.mocks.psm1 b/utils/actions/local/Register-LocalActionGetDependency.mocks.psm1 similarity index 80% rename from utils/actions/local/Register-LocalActionGetUpstream.mocks.psm1 rename to utils/actions/local/Register-LocalActionGetDependency.mocks.psm1 index 2c3b7b8..38f9fd6 100644 --- a/utils/actions/local/Register-LocalActionGetUpstream.mocks.psm1 +++ b/utils/actions/local/Register-LocalActionGetDependency.mocks.psm1 @@ -2,6 +2,6 @@ Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../testing.psm1" -Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionGetUpstream.psm1" +Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionGetDependency.psm1" -Export-ModuleMember -Function Initialize-UpstreamBranches +Export-ModuleMember -Function Initialize-DependencyBranches diff --git a/utils/actions/local/Register-LocalActionGetUpstream.psm1 b/utils/actions/local/Register-LocalActionGetDependency.psm1 similarity index 57% rename from utils/actions/local/Register-LocalActionGetUpstream.psm1 rename to utils/actions/local/Register-LocalActionGetDependency.psm1 index 6856ccf..e4a8489 100644 --- a/utils/actions/local/Register-LocalActionGetUpstream.psm1 +++ b/utils/actions/local/Register-LocalActionGetDependency.psm1 @@ -2,18 +2,18 @@ Import-Module -Scope Local "$PSScriptRoot/../../core.psm1" Import-Module -Scope Local "$PSScriptRoot/../../framework.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" -function Invoke-GetUpstreamLocalAction { +function Invoke-GetDependencyLocalAction { param( [Parameter(Mandatory)][string] $target, - [Parameter()][AllowNull()] $overrideUpstreams, + [Parameter()][AllowNull()] $overrideDependencies, [switch] $recurse, [switch] $includeRemote, [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics ) - [string[]]$result = Select-UpstreamBranches -branchName $target -recurse:$recurse -includeRemote:$includeRemote -overrideUpstreams:$overrideUpstreams + [string[]]$result = Select-DependencyBranches -branchName $target -recurse:$recurse -includeRemote:$includeRemote -overrideDependencies:$overrideDependencies return $result } -Export-ModuleMember -Function Invoke-GetUpstreamLocalAction +Export-ModuleMember -Function Invoke-GetDependencyLocalAction diff --git a/utils/actions/local/Register-LocalActionGetUpstream.tests.ps1 b/utils/actions/local/Register-LocalActionGetDependency.tests.ps1 similarity index 84% rename from utils/actions/local/Register-LocalActionGetUpstream.tests.ps1 rename to utils/actions/local/Register-LocalActionGetDependency.tests.ps1 index 35def5b..ab5dfc3 100644 --- a/utils/actions/local/Register-LocalActionGetUpstream.tests.ps1 +++ b/utils/actions/local/Register-LocalActionGetDependency.tests.ps1 @@ -1,20 +1,20 @@ -Describe 'local action "get-upstream"' { +Describe 'local action "get-dependency"' { BeforeAll { Import-Module -Scope Local "$PSScriptRoot/../../framework.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../Invoke-LocalAction.psm1" - Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionGetUpstream.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionGetDependency.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] $fw = Register-Framework [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $standardScript = ('{ - "type": "get-upstream", + $standardScript = ('{ + "type": "get-dependency", "parameters": { "target": "my-branch" } @@ -22,37 +22,37 @@ Describe 'local action "get-upstream"' { } function Initialize-StandardTests { - It 'gets the configured upstream branches' { - Initialize-UpstreamBranches @{ + It 'gets the configured dependency branches' { + Initialize-DependencyBranches @{ 'my-branch' = @('main') } - + $results = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - + Invoke-FlushAssertDiagnostic $fw.diagnostics $fw.assertDiagnosticOutput | Should -BeNullOrEmpty $results | Should -Be @('main') } - It 'gets all configured upstream branches' { - Initialize-UpstreamBranches @{ + It 'gets all configured dependency branches' { + Initialize-DependencyBranches @{ 'my-branch' = @('feature-base', 'infra/refactor') } - + $results = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - + Invoke-FlushAssertDiagnostic $fw.diagnostics $fw.assertDiagnosticOutput | Should -BeNullOrEmpty $results | Should -Be @('feature-base', 'infra/refactor') } It 'gets an empty array if no configuration exists' { - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'my-other-branch' = @('feature-base', 'infra/refactor') } - + $results = Invoke-LocalAction $standardScript -diagnostics $fw.diagnostics - + Invoke-FlushAssertDiagnostic $fw.diagnostics $fw.assertDiagnosticOutput | Should -BeNullOrEmpty $results | Should -Be @() @@ -65,24 +65,24 @@ Describe 'local action "get-upstream"' { } Initialize-StandardTests - - It 'gets upstream branches with overrides' { - Initialize-AllUpstreamBranches @{ + + It 'gets dependency branches with overrides' { + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123") 'feature/FOO-123' = @("main") 'feature/XYZ-1-services' = @("main") 'rc/1.1.0' = @("integrate/FOO-123_XYZ-1") - + 'bad-recursive-branch-1' = @('bad-recursive-branch-2') 'bad-recursive-branch-2' = @('bad-recursive-branch-1') } [string[]]$result = Invoke-LocalAction ('{ - "type": "get-upstream", + "type": "get-dependency", "parameters": { "target": "infra/new", - "overrideUpstreams": { + "overrideDependencies": { "feature/FOO-123": "infra/new", "infra/new": "main" } diff --git a/utils/actions/local/Register-LocalActionMergeBranches.mocks.psm1 b/utils/actions/local/Register-LocalActionMergeBranches.mocks.psm1 index 3b29118..701ef95 100644 --- a/utils/actions/local/Register-LocalActionMergeBranches.mocks.psm1 +++ b/utils/actions/local/Register-LocalActionMergeBranches.mocks.psm1 @@ -5,7 +5,7 @@ Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionMergeBranches.psm1 Import-Module -Scope Local "$PSScriptRoot/../../testing.psm1" function Initialize-LocalActionMergeBranches( - [Parameter(Mandatory)][string[]] $upstreamBranches, + [Parameter(Mandatory)][string[]] $dependencyBranches, [AllowEmptyCollection()][string[]] $successfulBranches, [AllowEmptyCollection()][string[]] $noChangeBranches, [Parameter()][Hashtable] $initialCommits = @{}, @@ -17,7 +17,7 @@ function Initialize-LocalActionMergeBranches( ) { $config = Get-Configuration if ($null -ne $config.remote) { - $upstreamBranches = [string[]]$upstreamBranches | Foreach-Object { "$($config.remote)/$_" } + $dependencyBranches = [string[]]$dependencyBranches | Foreach-Object { "$($config.remote)/$_" } $successfulBranches = [string[]]$successfulBranches | Where-Object { $_ } | Foreach-Object { "$($config.remote)/$_" } $noChangeBranches = [string[]]$noChangeBranches | Where-Object { $_ } | Foreach-Object { "$($config.remote)/$_" } if ($null -ne $source -AND '' -ne $source) { @@ -30,7 +30,7 @@ function Initialize-LocalActionMergeBranches( return } - Initialize-MergeTogether -allBranches $upstreamBranches -successfulBranches $successfulBranches -noChangeBranches $noChangeBranches ` + Initialize-MergeTogether -allBranches $dependencyBranches -successfulBranches $successfulBranches -noChangeBranches $noChangeBranches ` -initialCommits $initialCommits ` -skipRevParse $skipRevParse ` -source $source ` @@ -39,15 +39,15 @@ function Initialize-LocalActionMergeBranches( } function Initialize-LocalActionMergeBranchesFailure( - [Parameter(Mandatory)][string[]] $upstreamBranches, + [Parameter(Mandatory)][string[]] $dependencyBranches, [Parameter(Mandatory)][string[]] $failures, [Parameter(Mandatory)][string] $resultCommitish, [Parameter(Mandatory)][string] $mergeMessageTemplate, [Parameter()][string] $source ) { - $successfulBranches = ($upstreamBranches | Where-Object { $_ -notin $failures }) + $successfulBranches = ($dependencyBranches | Where-Object { $_ -notin $failures }) Initialize-LocalActionMergeBranches ` - -upstreamBranches $upstreamBranches ` + -dependencyBranches $dependencyBranches ` -successfulBranches $successfulBranches ` -resultCommitish $resultCommitish ` -mergeMessageTemplate $mergeMessageTemplate ` @@ -56,19 +56,19 @@ function Initialize-LocalActionMergeBranchesFailure( } function Initialize-LocalActionMergeBranchesSuccess( - [Parameter(Mandatory)][string[]] $upstreamBranches, + [Parameter(Mandatory)][string[]] $dependencyBranches, [Parameter(Mandatory)][string] $resultCommitish, [Parameter(Mandatory)][string] $mergeMessageTemplate, [Parameter()][string] $source, [Parameter()][int] $failAtMerge = -1, [Parameter()][string[]] $failedBranches ) { - [string[]]$successfulBranches = $failAtMerge -eq -1 -AND -not $failedBranches ? $upstreamBranches - : $failedBranches ? ($upstreamBranches | Where-Object { $failedBranches -notcontains $_ }) + [string[]]$successfulBranches = $failAtMerge -eq -1 -AND -not $failedBranches ? $dependencyBranches + : $failedBranches ? ($dependencyBranches | Where-Object { $failedBranches -notcontains $_ }) : $failAtMerge -eq 0 ? @() - : ($upstreamBranches | Select-Object -First $failAtMerge) + : ($dependencyBranches | Select-Object -First $failAtMerge) Initialize-LocalActionMergeBranches ` - -upstreamBranches $upstreamBranches ` + -dependencyBranches $dependencyBranches ` -successfulBranches $successfulBranches ` -resultCommitish $resultCommitish ` -mergeMessageTemplate $mergeMessageTemplate ` diff --git a/utils/actions/local/Register-LocalActionMergeBranches.psm1 b/utils/actions/local/Register-LocalActionMergeBranches.psm1 index c5ff76e..685fe61 100644 --- a/utils/actions/local/Register-LocalActionMergeBranches.psm1 +++ b/utils/actions/local/Register-LocalActionMergeBranches.psm1 @@ -7,7 +7,7 @@ function Invoke-MergeBranchesLocalAction { param( [string] $source, - [string[]] $upstreamBranches, + [string[]] $dependencyBranches, [string] $mergeMessageTemplate = "Merge {}", [hashtable] $commitMappingOverride = @{}, @@ -17,13 +17,13 @@ function Invoke-MergeBranchesLocalAction $config = Get-Configuration if ($null -ne $config.remote) { - $upstreamBranches = [string[]]$upstreamBranches | Where-Object { $_ } | Foreach-Object { "$($config.remote)/$_" } + $dependencyBranches = [string[]]$dependencyBranches | Where-Object { $_ } | Foreach-Object { "$($config.remote)/$_" } if ($null -ne $source -AND '' -ne $source) { $source = "$($config.remote)/$source" } } - if ($null -eq $upstreamBranches) { + if ($null -eq $dependencyBranches) { # Nothing to merge return @{ commit = $null; @@ -35,7 +35,7 @@ function Invoke-MergeBranchesLocalAction $mergeResult = Invoke-MergeTogether ` -source $source ` - -commitishes $upstreamBranches ` + -commitishes $dependencyBranches ` -messageTemplate $mergeMessageTemplate ` -commitMappingOverride $commitMappingOverride ` -diagnostics $diagnostics ` diff --git a/utils/actions/local/Register-LocalActionMergeBranches.tests.ps1 b/utils/actions/local/Register-LocalActionMergeBranches.tests.ps1 index d489903..3bddf12 100644 --- a/utils/actions/local/Register-LocalActionMergeBranches.tests.ps1 +++ b/utils/actions/local/Register-LocalActionMergeBranches.tests.ps1 @@ -20,10 +20,10 @@ Describe 'local action "merge-branches"' { It 'creates from a single branch' { Initialize-LocalActionMergeBranchesSuccess @('baz') 'new-Commit' -mergeMessageTemplate "Merge {}" - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { - "upstreamBranches": [ + "dependencyBranches": [ "baz" ], "mergeMessageTemplate": "Merge {}" @@ -41,10 +41,10 @@ Describe 'local action "merge-branches"' { It 'handles standard functionality' { $mocks = Initialize-LocalActionMergeBranchesSuccess @('baz', 'barbaz') 'new-Commit' -mergeMessageTemplate "Merge {}" - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { - "upstreamBranches": [ + "dependencyBranches": [ "baz", "barbaz" ], @@ -66,10 +66,10 @@ Describe 'local action "merge-branches"' { -mergeMessageTemplate "Merge {}" ` -failAtMerge 0 - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { - "upstreamBranches": [ + "dependencyBranches": [ "baz", "barbaz" ], @@ -92,11 +92,11 @@ Describe 'local action "merge-branches"' { -source 'foo' ` -mergeMessageTemplate "Merge {}" - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { "source": "foo", - "upstreamBranches": [ + "dependencyBranches": [ "baz", "barbaz" ], @@ -118,11 +118,11 @@ Describe 'local action "merge-branches"' { -source 'foo' ` -mergeMessageTemplate "Merge {}" - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { "source": "foo", - "upstreamBranches": [ + "dependencyBranches": [ "baz", "barbaz" ], @@ -144,27 +144,27 @@ Describe 'local action "merge-branches"' { Invoke-VerifyMock $mocks -Times 1 } } - + Context 'without remote' { BeforeEach { Initialize-ToolConfiguration -noRemote - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/homepage-redesign' = @('infra/upgrade-dependencies') } } AddStandardTests - + It 'reports merge failures' { $mocks = Initialize-LocalActionMergeBranchesSuccess @('baz', 'barbaz') 'new-Commit' ` -mergeMessageTemplate "Merge {}" ` -failAtMerge 1 - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { - "upstreamBranches": [ + "dependencyBranches": [ "baz", "barbaz" ], @@ -182,27 +182,27 @@ Describe 'local action "merge-branches"' { Invoke-VerifyMock $mocks -Times 1 } } - + Context 'with remote' { BeforeEach { Initialize-ToolConfiguration - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/homepage-redesign' = @('infra/upgrade-dependencies') } } - + AddStandardTests - + It 'reports merge failures' { $mocks = Initialize-LocalActionMergeBranchesSuccess @('baz', 'barbaz') 'new-Commit' ` -mergeMessageTemplate "Merge {}" ` -failAtMerge 1 - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { - "upstreamBranches": [ + "dependencyBranches": [ "baz", "barbaz" ], @@ -219,16 +219,16 @@ Describe 'local action "merge-branches"' { } Invoke-VerifyMock $mocks -Times 1 } - + It 'reports merge failures' { $mocks = Initialize-LocalActionMergeBranchesSuccess @('baz', 'barbaz') 'new-Commit' ` -mergeMessageTemplate "Merge {}" ` -failedBranches @('barbaz') - $result = Invoke-LocalAction ('{ - "type": "merge-branches", + $result = Invoke-LocalAction ('{ + "type": "merge-branches", "parameters": { - "upstreamBranches": [ + "dependencyBranches": [ "baz", "barbaz" ], diff --git a/utils/actions/local/Register-LocalActionSetDependency.mocks.psm1 b/utils/actions/local/Register-LocalActionSetDependency.mocks.psm1 new file mode 100644 index 0000000..520988f --- /dev/null +++ b/utils/actions/local/Register-LocalActionSetDependency.mocks.psm1 @@ -0,0 +1,40 @@ +Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" +Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSetDependency.psm1" +Import-Module -Scope Local "$PSScriptRoot/../../testing.psm1" + +function Lock-LocalActionSetDependency() { + Mock -ModuleName 'Register-LocalActionSetDependency' -CommandName Set-GitFiles -MockWith { + throw "Register-LocalActionSetDependency was not set up for this test, $commitMessage, $($files | ConvertTo-Json)" + } +} + +function Initialize-LocalActionSetDependency([PSObject] $dependencyBranches, [string] $message, [string] $commitish) { + Lock-LocalActionSetDependency + $contents = (@( + '' -ne $message ? "`$message -eq '$($message.Replace("'", "''"))'" : $null + $null -ne $dependencyBranches ? @( + "`$files.Keys.Count -eq $($dependencyBranches.Keys.Count)" + ($dependencyBranches.Keys | ForEach-Object { + if ($null -eq $dependencyBranches[$_] -OR $dependencyBranches[$_].length -eq 0) { + "`$files['$_'] -eq `$null" + } else { + "`$files['$_'].split(`"``n`").Count -eq $($dependencyBranches[$_].Count + 1)" + foreach ($branch in $dependencyBranches[$_]) { + "`$files['$_'].split(`"``n`") -contains '$branch'" + } + } + }) + ) : $null + ) | ForEach-Object { $_ } | Where-Object { $_ -ne $null }) -join ' -AND ' + + $result = New-VerifiableMock ` + -CommandName Set-GitFiles ` + -ModuleName 'Register-LocalActionSetDependency' ` + -ParameterFilter $([scriptblock]::Create($contents)) + Invoke-WrapMock $result -MockWith { + $global:LASTEXITCODE = 0 + $commitish + }.GetNewClosure() + return $result +} +Export-ModuleMember -Function Lock-LocalActionSetDependency, Initialize-LocalActionSetDependency diff --git a/utils/actions/local/Register-LocalActionSetUpstream.psm1 b/utils/actions/local/Register-LocalActionSetDependency.psm1 similarity index 75% rename from utils/actions/local/Register-LocalActionSetUpstream.psm1 rename to utils/actions/local/Register-LocalActionSetDependency.psm1 index 044e398..59faf6d 100644 --- a/utils/actions/local/Register-LocalActionSetUpstream.psm1 +++ b/utils/actions/local/Register-LocalActionSetDependency.psm1 @@ -3,20 +3,20 @@ Import-Module -Scope Local "$PSScriptRoot/../../framework.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" Import-Module -Scope Local "$PSScriptRoot/../../git.psm1" -function Invoke-SetUpstreamLocalAction { +function Invoke-SetDependencyLocalAction { param( - [PSObject] $upstreamBranches, + [PSObject] $dependencyBranches, [string] $message, [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics ) - $upstreamBranch = Get-UpstreamBranch - $ht = ConvertTo-Hashtable $upstreamBranches + $dependencyBranch = Get-DependencyBranch + $ht = ConvertTo-Hashtable $dependencyBranches $contents = $ht.Keys | ConvertTo-HashMap -getValue { if ($null -eq $ht[$_] -OR $ht[$_].length -eq 0) { return $null } "$(($ht[$_] | Where-Object { $_ }) -join "`n")`n" } - $commit = Set-GitFiles $contents -m $message -initialCommitish $upstreamBranch + $commit = Set-GitFiles $contents -m $message -initialCommitish $dependencyBranch if ($null -eq $commit) { throw "Set-GitFiles was unable to create a new commit." } @@ -25,4 +25,4 @@ function Invoke-SetUpstreamLocalAction { } } -Export-ModuleMember -Function Invoke-SetUpstreamLocalAction +Export-ModuleMember -Function Invoke-SetDependencyLocalAction diff --git a/utils/actions/local/Register-LocalActionSetUpstream.tests.ps1 b/utils/actions/local/Register-LocalActionSetDependency.tests.ps1 similarity index 70% rename from utils/actions/local/Register-LocalActionSetUpstream.tests.ps1 rename to utils/actions/local/Register-LocalActionSetDependency.tests.ps1 index 51e7828..8e12fe6 100644 --- a/utils/actions/local/Register-LocalActionSetUpstream.tests.ps1 +++ b/utils/actions/local/Register-LocalActionSetDependency.tests.ps1 @@ -1,13 +1,13 @@ -Describe 'local action "set-upstream"' { +Describe 'local action "set-dependency"' { BeforeAll { Import-Module -Scope Local "$PSScriptRoot/../../framework.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../Invoke-LocalAction.psm1" - Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSetUpstream.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSetDependency.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { $fw = Register-Framework [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] @@ -16,13 +16,13 @@ Describe 'local action "set-upstream"' { Context 'with remote' { BeforeAll { - Initialize-ToolConfiguration -remote 'github' -upstreamBranchName 'my-upstream' + Initialize-ToolConfiguration -remote 'github' -dependencyBranchName 'my-dependency' } It 'sets the git file' { - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify github/my-upstream -q' } { 'upstream-HEAD' } - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify github/my-upstream^{tree} -q' } { 'upstream-TREE' } - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'ls-tree upstream-TREE' } { + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify github/my-dependency -q' } { 'dependency-HEAD' } + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify github/my-dependency^{tree} -q' } { 'dependency-TREE' } + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'ls-tree dependency-TREE' } { "100644 blob 2adfafd75a2c423627081bb19f06dca28d09cd8e`t.dockerignore" } Initialize-WriteBlob ([Text.Encoding]::UTF8.GetBytes("baz`nbarbaz`n")) 'new-FILE' @@ -30,14 +30,14 @@ Describe 'local action "set-upstream"' { $treeEntries -contains "100644 blob 2adfafd75a2c423627081bb19f06dca28d09cd8e`t.dockerignore" ` -AND $treeEntries -contains "100644 blob new-FILE`tfoobar" } { return 'new-TREE' } - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'commit-tree new-TREE -m Add barbaz to foobar -p upstream-HEAD' } { + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'commit-tree new-TREE -m Add barbaz to foobar -p dependency-HEAD' } { 'new-COMMIT' } $result = Invoke-LocalAction @{ - type = 'set-upstream' + type = 'set-dependency' parameters = @{ - upstreamBranches = @{ foobar = @('baz'; 'barbaz') }; + dependencyBranches = @{ foobar = @('baz'; 'barbaz') }; message = 'Add barbaz to foobar' } } -diagnostics $diag @@ -46,12 +46,12 @@ Describe 'local action "set-upstream"' { } It 'provides mocks to do the same' { - $mock = Initialize-LocalActionSetUpstream @{ 'foobar' = @('baz', 'barbaz') } -message 'Add barbaz to foobar' -commitish 'new-COMMIT' + $mock = Initialize-LocalActionSetDependency @{ 'foobar' = @('baz', 'barbaz') } -message 'Add barbaz to foobar' -commitish 'new-COMMIT' $result = Invoke-LocalAction @{ - type = 'set-upstream' + type = 'set-dependency' parameters = @{ - upstreamBranches = @{ foobar = @('baz', 'barbaz') }; + dependencyBranches = @{ foobar = @('baz', 'barbaz') }; message = 'Add barbaz to foobar' } } -diagnostics $diag @@ -60,13 +60,13 @@ Describe 'local action "set-upstream"' { } It 'handles action deserialized from json' { - $mock = Initialize-LocalActionSetUpstream @{ 'foobar' = @('baz', 'barbaz') } -message 'Add barbaz to foobar' -commitish 'new-COMMIT' + $mock = Initialize-LocalActionSetDependency @{ 'foobar' = @('baz', 'barbaz') } -message 'Add barbaz to foobar' -commitish 'new-COMMIT' - $result = Invoke-LocalAction ('{ - "type": "set-upstream", + $result = Invoke-LocalAction ('{ + "type": "set-dependency", "parameters": { "message": "Add barbaz to foobar", - "upstreamBranches": { + "dependencyBranches": { "foobar": [ "baz", "barbaz" @@ -79,13 +79,13 @@ Describe 'local action "set-upstream"' { } It 'allows the mock to not provide the commit message' { - $mock = Initialize-LocalActionSetUpstream @{ 'foobar' = @('baz', 'barbaz') } -commitish 'new-COMMIT' + $mock = Initialize-LocalActionSetDependency @{ 'foobar' = @('baz', 'barbaz') } -commitish 'new-COMMIT' - $result = Invoke-LocalAction ('{ - "type": "set-upstream", + $result = Invoke-LocalAction ('{ + "type": "set-dependency", "parameters": { "message": "Add barbaz to foobar", - "upstreamBranches": { + "dependencyBranches": { "foobar": [ "baz", "barbaz" @@ -98,13 +98,13 @@ Describe 'local action "set-upstream"' { } It 'allows the mock to not provide the files' { - $mock = Initialize-LocalActionSetUpstream -message 'Add barbaz to foobar' -commitish 'new-COMMIT' + $mock = Initialize-LocalActionSetDependency -message 'Add barbaz to foobar' -commitish 'new-COMMIT' - $result = Invoke-LocalAction ('{ - "type": "set-upstream", + $result = Invoke-LocalAction ('{ + "type": "set-dependency", "parameters": { "message": "Add barbaz to foobar", - "upstreamBranches": { + "dependencyBranches": { "foobar": [ "baz", "barbaz" @@ -117,13 +117,13 @@ Describe 'local action "set-upstream"' { } It 'allows a branch to be removed from configuration' { - $mock = Initialize-LocalActionSetUpstream @{ 'foobar' = $null } -message 'Remove foobar' -commitish 'new-COMMIT' + $mock = Initialize-LocalActionSetDependency @{ 'foobar' = $null } -message 'Remove foobar' -commitish 'new-COMMIT' - $result = Invoke-LocalAction ('{ - "type": "set-upstream", + $result = Invoke-LocalAction ('{ + "type": "set-dependency", "parameters": { "message": "Remove foobar", - "upstreamBranches": { + "dependencyBranches": { "foobar": null } } @@ -135,13 +135,13 @@ Describe 'local action "set-upstream"' { Context 'without remote' { BeforeAll { - Initialize-ToolConfiguration -noRemote -upstreamBranchName 'my-upstream' + Initialize-ToolConfiguration -noRemote -dependencyBranchName 'my-dependency' } It 'sets the git file' { - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify my-upstream -q' } { 'upstream-HEAD' } - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify my-upstream^{tree} -q' } { 'upstream-TREE' } - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'ls-tree upstream-TREE' } { + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify my-dependency -q' } { 'dependency-HEAD' } + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'rev-parse --verify my-dependency^{tree} -q' } { 'dependency-TREE' } + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'ls-tree dependency-TREE' } { "100644 blob 2adfafd75a2c423627081bb19f06dca28d09cd8e`t.dockerignore" } Initialize-WriteBlob ([Text.Encoding]::UTF8.GetBytes("baz`nbarbaz`n")) 'new-FILE' @@ -149,14 +149,14 @@ Describe 'local action "set-upstream"' { "100644 blob 2adfafd75a2c423627081bb19f06dca28d09cd8e`t.dockerignore", "100644 blob new-FILE`tfoobar" ) 'new-TREE' - Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'commit-tree new-TREE -m Add barbaz to foobar -p upstream-HEAD' } { + Mock git -ModuleName 'Set-GitFiles' -ParameterFilter { ($args -join ' ') -eq 'commit-tree new-TREE -m Add barbaz to foobar -p dependency-HEAD' } { 'new-COMMIT' } $result = Invoke-LocalAction @{ - type = 'set-upstream' + type = 'set-dependency' parameters = @{ - upstreamBranches = @{ foobar = @('baz', 'barbaz') }; + dependencyBranches = @{ foobar = @('baz', 'barbaz') }; message = 'Add barbaz to foobar' } } -diagnostics $diag diff --git a/utils/actions/local/Register-LocalActionSetUpstream.mocks.psm1 b/utils/actions/local/Register-LocalActionSetUpstream.mocks.psm1 deleted file mode 100644 index f6e3bc4..0000000 --- a/utils/actions/local/Register-LocalActionSetUpstream.mocks.psm1 +++ /dev/null @@ -1,40 +0,0 @@ -Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" -Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSetUpstream.psm1" -Import-Module -Scope Local "$PSScriptRoot/../../testing.psm1" - -function Lock-LocalActionSetUpstream() { - Mock -ModuleName 'Register-LocalActionSetUpstream' -CommandName Set-GitFiles -MockWith { - throw "Register-LocalActionSetUpstream was not set up for this test, $commitMessage, $($files | ConvertTo-Json)" - } -} - -function Initialize-LocalActionSetUpstream([PSObject] $upstreamBranches, [string] $message, [string] $commitish) { - Lock-LocalActionSetUpstream - $contents = (@( - '' -ne $message ? "`$message -eq '$($message.Replace("'", "''"))'" : $null - $null -ne $upstreamBranches ? @( - "`$files.Keys.Count -eq $($upstreamBranches.Keys.Count)" - ($upstreamBranches.Keys | ForEach-Object { - if ($null -eq $upstreamBranches[$_] -OR $upstreamBranches[$_].length -eq 0) { - "`$files['$_'] -eq `$null" - } else { - "`$files['$_'].split(`"``n`").Count -eq $($upstreamBranches[$_].Count + 1)" - foreach ($branch in $upstreamBranches[$_]) { - "`$files['$_'].split(`"``n`") -contains '$branch'" - } - } - }) - ) : $null - ) | ForEach-Object { $_ } | Where-Object { $_ -ne $null }) -join ' -AND ' - - $result = New-VerifiableMock ` - -CommandName Set-GitFiles ` - -ModuleName 'Register-LocalActionSetUpstream' ` - -ParameterFilter $([scriptblock]::Create($contents)) - Invoke-WrapMock $result -MockWith { - $global:LASTEXITCODE = 0 - $commitish - }.GetNewClosure() - return $result -} -Export-ModuleMember -Function Lock-LocalActionSetUpstream, Initialize-LocalActionSetUpstream diff --git a/utils/actions/local/Register-LocalActionSimplifyDependencyBranches.mocks.psm1 b/utils/actions/local/Register-LocalActionSimplifyDependencyBranches.mocks.psm1 new file mode 100644 index 0000000..64b672e --- /dev/null +++ b/utils/actions/local/Register-LocalActionSimplifyDependencyBranches.mocks.psm1 @@ -0,0 +1,47 @@ +Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" +Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" +Import-Module -Scope Local "$PSScriptRoot/../../input.mocks.psm1" +Import-Module -Scope Local "$PSScriptRoot/../../testing.psm1" +Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSimplifyDependencyBranches.psm1" + +function Lock-LocalActionSimplifyDependencyBranches() { + Mock -ModuleName 'Register-LocalActionSimplifyDependencyBranches' -CommandName Compress-DependencyBranches -MockWith { + throw "Register-LocalActionSimplifyDependencyBranches was not set up for this test, $originalDependency" + } +} + +function Initialize-LocalActionSimplifyDependencyBranchesSuccess( + [string[]] $from, + [string[]] $to +) { + Lock-LocalActionSimplifyDependencyBranches + foreach ($branch in $from) { + Initialize-AssertValidBranchName $branch + } + + $contents = (@( + "`$originalDependency.Count -eq $($from.Count)" + $from | ForEach-Object { "`$originalDependency -contains '$_'" } + ) | ForEach-Object { $_ } | Where-Object { $_ -ne $null }) -join ' -AND ' + + $result = New-VerifiableMock ` + -CommandName Compress-DependencyBranches ` + -ModuleName 'Register-LocalActionSimplifyDependencyBranches' ` + -ParameterFilter $([scriptblock]::Create($contents)) + Invoke-WrapMock $result -MockWith { + $global:LASTEXITCODE = 0 + $to + }.GetNewClosure() + return $result +} + +# Uses expected dependency branches to determine simplification +function Initialize-LocalActionSimplifyDependencyBranches( + [string[]] $from +) { + foreach ($branch in $from) { + Initialize-AssertValidBranchName $branch + } +} + +Export-ModuleMember -Function Initialize-LocalActionSimplifyDependencyBranchesSuccess,Initialize-LocalActionSimplifyDependencyBranches diff --git a/utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.psm1 b/utils/actions/local/Register-LocalActionSimplifyDependencyBranches.psm1 similarity index 52% rename from utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.psm1 rename to utils/actions/local/Register-LocalActionSimplifyDependencyBranches.psm1 index 3116364..c7450dc 100644 --- a/utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.psm1 +++ b/utils/actions/local/Register-LocalActionSimplifyDependencyBranches.psm1 @@ -3,31 +3,31 @@ Import-Module -Scope Local "$PSScriptRoot/../../framework.psm1" Import-Module -Scope Local "$PSScriptRoot/../../input.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" -function Invoke-SimplifyUpstreamLocalAction { +function Invoke-SimplifyDependencyLocalAction { param( - [Parameter(Mandatory)][AllowEmptyCollection()][AllowEmptyString()][string[]] $upstreamBranches, - [Parameter()][AllowNull()] $overrideUpstreams, + [Parameter(Mandatory)][AllowEmptyCollection()][AllowEmptyString()][string[]] $dependencyBranches, + [Parameter()][AllowNull()] $overrideDependencies, [Parameter()][AllowNull()][string] $branchName, [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics ) - $upstreamBranches = $upstreamBranches | Where-Object { $_ } - if ($upstreamBranches.Count -ne 0) { - $upstreamBranches | Assert-ValidBranchName -diagnostics $diagnostics + $dependencyBranches = $dependencyBranches | Where-Object { $_ } + if ($dependencyBranches.Count -ne 0) { + $dependencyBranches | Assert-ValidBranchName -diagnostics $diagnostics } if (Get-HasErrorDiagnostic $diagnostics) { return $null } - if ($upstreamBranches.Count -eq 0) { + if ($dependencyBranches.Count -eq 0) { $config = Get-Configuration if ($null -eq $config.defaultServiceLine) { - Add-ErrorDiagnostic $diagnostics 'At least one upstream branch must be specified or the default service line must be set' + Add-ErrorDiagnostic $diagnostics 'At least one dependency branch must be specified or the default service line must be set' } # default to service line if none provided and config has a service line return @( $config.defaultServiceLine ) } - $result = Compress-UpstreamBranches $upstreamBranches -diagnostics:$diagnostics -overrideUpstreams:$overrideUpstreams -branchName:$branchName + $result = Compress-DependencyBranches $dependencyBranches -diagnostics:$diagnostics -overrideDependencies:$overrideDependencies -branchName:$branchName return $result } -Export-ModuleMember -Function Invoke-SimplifyUpstreamLocalAction +Export-ModuleMember -Function Invoke-SimplifyDependencyLocalAction diff --git a/utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.tests.ps1 b/utils/actions/local/Register-LocalActionSimplifyDependencyBranches.tests.ps1 similarity index 81% rename from utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.tests.ps1 rename to utils/actions/local/Register-LocalActionSimplifyDependencyBranches.tests.ps1 index 4c30c17..74de5b5 100644 --- a/utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.tests.ps1 +++ b/utils/actions/local/Register-LocalActionSimplifyDependencyBranches.tests.ps1 @@ -1,13 +1,13 @@ -Describe 'local action "simplify-upstream"' { +Describe 'local action "simplify-dependency"' { BeforeAll { Import-Module -Scope Local "$PSScriptRoot/../../framework.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../../git.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../Invoke-LocalAction.psm1" - Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSimplifyUpstreamBranches.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSimplifyDependencyBranches.mocks.psm1" . "$PSScriptRoot/../../testing.ps1" } - + BeforeEach { $fw = Register-Framework -throwInsteadOfExit [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] @@ -20,9 +20,9 @@ Describe 'local action "simplify-upstream"' { Initialize-ToolConfiguration -defaultServiceLine 'line/1.0' $result = Invoke-LocalAction @{ - type = 'simplify-upstream' + type = 'simplify-dependency' parameters = @{ - upstreamBranches = @() + dependencyBranches = @() } } -diagnostics $diag try { Assert-Diagnostics $diag } catch { } @@ -31,12 +31,12 @@ Describe 'local action "simplify-upstream"' { } It 'allows mocked simplification' { - Initialize-LocalActionSimplifyUpstreamBranchesSuccess -from @('foo', 'bar') -to @('foo') + Initialize-LocalActionSimplifyDependencyBranchesSuccess -from @('foo', 'bar') -to @('foo') $result = Invoke-LocalAction @{ - type = 'simplify-upstream' + type = 'simplify-dependency' parameters = @{ - upstreamBranches = @('foo', 'bar') + dependencyBranches = @('foo', 'bar') } } -diagnostics $diag try { Assert-Diagnostics $diag } catch { } diff --git a/utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.mocks.psm1 b/utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.mocks.psm1 deleted file mode 100644 index d6e9a8e..0000000 --- a/utils/actions/local/Register-LocalActionSimplifyUpstreamBranches.mocks.psm1 +++ /dev/null @@ -1,47 +0,0 @@ -Import-Module -Scope Local "$PSScriptRoot/../../query-state.psm1" -Import-Module -Scope Local "$PSScriptRoot/../../query-state.mocks.psm1" -Import-Module -Scope Local "$PSScriptRoot/../../input.mocks.psm1" -Import-Module -Scope Local "$PSScriptRoot/../../testing.psm1" -Import-Module -Scope Local "$PSScriptRoot/Register-LocalActionSimplifyUpstreamBranches.psm1" - -function Lock-LocalActionSimplifyUpstreamBranches() { - Mock -ModuleName 'Register-LocalActionSimplifyUpstreamBranches' -CommandName Compress-UpstreamBranches -MockWith { - throw "Register-LocalActionSimplifyUpstreamBranches was not set up for this test, $originalUpstream" - } -} - -function Initialize-LocalActionSimplifyUpstreamBranchesSuccess( - [string[]] $from, - [string[]] $to -) { - Lock-LocalActionSimplifyUpstreamBranches - foreach ($branch in $from) { - Initialize-AssertValidBranchName $branch - } - - $contents = (@( - "`$originalUpstream.Count -eq $($from.Count)" - $from | ForEach-Object { "`$originalUpstream -contains '$_'" } - ) | ForEach-Object { $_ } | Where-Object { $_ -ne $null }) -join ' -AND ' - - $result = New-VerifiableMock ` - -CommandName Compress-UpstreamBranches ` - -ModuleName 'Register-LocalActionSimplifyUpstreamBranches' ` - -ParameterFilter $([scriptblock]::Create($contents)) - Invoke-WrapMock $result -MockWith { - $global:LASTEXITCODE = 0 - $to - }.GetNewClosure() - return $result -} - -# Uses expected upstream branches to determine simplification -function Initialize-LocalActionSimplifyUpstreamBranches( - [string[]] $from -) { - foreach ($branch in $from) { - Initialize-AssertValidBranchName $branch - } -} - -Export-ModuleMember -Function Initialize-LocalActionSimplifyUpstreamBranchesSuccess,Initialize-LocalActionSimplifyUpstreamBranches diff --git a/utils/git/Set-RemoteTracking.mocks.psm1 b/utils/git/Set-RemoteTracking.mocks.psm1 index 0c23e4d..7a9f129 100644 --- a/utils/git/Set-RemoteTracking.mocks.psm1 +++ b/utils/git/Set-RemoteTracking.mocks.psm1 @@ -8,6 +8,6 @@ function Invoke-MockGit([string] $gitCli, [object] $MockWith) { function Initialize-SetRemoteTracking($branchName) { $remote = $(Get-Configuration).remote - return Invoke-MockGit "branch --set-upstream-to=refs/remotes/$($remote)/$($branchName) $($branchName)" + return Invoke-MockGit "branch --set-dependency-to=refs/remotes/$($remote)/$($branchName) $($branchName)" } Export-ModuleMember -Function Initialize-SetRemoteTracking diff --git a/utils/git/Set-RemoteTracking.psm1 b/utils/git/Set-RemoteTracking.psm1 index c2cb76c..a1fc1ce 100644 --- a/utils/git/Set-RemoteTracking.psm1 +++ b/utils/git/Set-RemoteTracking.psm1 @@ -2,7 +2,7 @@ Import-Module -Scope Local "$PSScriptRoot/../query-state.psm1" function Set-RemoteTracking([String]$branchName) { $config = Get-Configuration - git branch --set-upstream-to="refs/remotes/$($config.remote)/$($branchName)" $($branchName) + git branch --set-dependency-to="refs/remotes/$($config.remote)/$($branchName)" $($branchName) if ($LASTEXITCODE -ne 0) { throw "Could not set '$branchName' from '$($source)'" } diff --git a/utils/query-state.mocks.psm1 b/utils/query-state.mocks.psm1 index 2467ff8..fe1dc8d 100644 --- a/utils/query-state.mocks.psm1 +++ b/utils/query-state.mocks.psm1 @@ -1,7 +1,7 @@ Import-Module -Scope Local "$PSScriptRoot/query-state/Assert-CleanWorkingDirectory.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Configuration.mocks.psm1" -Import-Module -Scope Local "$PSScriptRoot/query-state/Get-UpstreamBranch.mocks.psm1" -Import-Module -Scope Local "$PSScriptRoot/query-state/Select-UpstreamBranches.mocks.psm1" +Import-Module -Scope Local "$PSScriptRoot/query-state/Get-DependencyBranch.mocks.psm1" +Import-Module -Scope Local "$PSScriptRoot/query-state/Select-DependencyBranches.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Update-GitRemote.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Get-CurrentBranch.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Get-GitFile.mocks.psm1" @@ -10,8 +10,8 @@ Import-Module -Scope Local "$PSScriptRoot/query-state/Get-MergeTree.mocks.psm1" Export-ModuleMember -Function ` Initialize-CleanWorkingDirectory, Initialize-DirtyWorkingDirectory, Initialize-UntrackedFiles ` , Initialize-ToolConfiguration ` - , Initialize-FetchUpstreamBranch ` - , Initialize-UpstreamBranches ` + , Initialize-FetchDependencyBranch ` + , Initialize-DependencyBranches ` , Initialize-UpdateGitRemote ` , Initialize-CurrentBranch, Initialize-NoCurrentBranch ` , Initialize-OtherGitFilesAsBlank, Initialize-GitFile ` @@ -19,15 +19,15 @@ Export-ModuleMember -Function ` Import-Module -Scope Local "$PSScriptRoot/query-state/Get-BranchCommit.mocks.psm1" Export-ModuleMember -Function Initialize-GetBranchCommit - + Import-Module -Scope Local "$PSScriptRoot/query-state/Get-BranchSyncState.mocks.psm1" Export-ModuleMember -Function Initialize-RemoteBranchBehind, Initialize-RemoteBranchAhead, Initialize-RemoteBranchNotTracked, Initialize-RemoteBranchInSync, Initialize-RemoteBranchAheadAndBehind Import-Module -Scope Local "$PSScriptRoot/query-state/Get-LocalBranchForRemote.mocks.psm1" Export-ModuleMember -Function Initialize-GetLocalBranchForRemote -Import-Module -Scope Local "$PSScriptRoot/query-state/Select-AllUpstreamBranches.mocks.psm1" -Export-ModuleMember -Function Initialize-AllUpstreamBranches +Import-Module -Scope Local "$PSScriptRoot/query-state/Select-AllDependencyBranches.mocks.psm1" +Export-ModuleMember -Function Initialize-AllDependencyBranches Import-Module -Scope Local "$PSScriptRoot/query-state/Select-Branches.mocks.psm1" Export-ModuleMember -Function Initialize-SelectBranches diff --git a/utils/query-state.psm1 b/utils/query-state.psm1 index eb404b9..6713c1b 100644 --- a/utils/query-state.psm1 +++ b/utils/query-state.psm1 @@ -1,9 +1,9 @@ Import-Module -Scope Local "$PSScriptRoot/query-state/Configuration.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Update-GitRemote.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Assert-CleanWorkingDirectory.psm1" -Import-Module -Scope Local "$PSScriptRoot/query-state/Compress-UpstreamBranches.psm1" -Import-Module -Scope Local "$PSScriptRoot/query-state/Select-UpstreamBranches.psm1" -Import-Module -Scope Local "$PSScriptRoot/query-state/Get-UpstreamBranch.psm1" +Import-Module -Scope Local "$PSScriptRoot/query-state/Compress-DependencyBranches.psm1" +Import-Module -Scope Local "$PSScriptRoot/query-state/Select-DependencyBranches.psm1" +Import-Module -Scope Local "$PSScriptRoot/query-state/Get-DependencyBranch.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Get-CurrentBranch.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Get-GitFile.psm1" Import-Module -Scope Local "$PSScriptRoot/query-state/Get-MergeTree.psm1" @@ -11,9 +11,9 @@ Import-Module -Scope Local "$PSScriptRoot/query-state/Get-MergeTree.psm1" Export-ModuleMember -Function Get-Configuration ` , Update-GitRemote ` , Assert-CleanWorkingDirectory ` - , Compress-UpstreamBranches ` - , Select-UpstreamBranches ` - , Get-UpstreamBranch ` + , Compress-DependencyBranches ` + , Select-DependencyBranches ` + , Get-DependencyBranch ` , Get-CurrentBranch ` , Get-GitFile ` , Get-MergeTree ` @@ -33,8 +33,8 @@ Export-ModuleMember -Function Get-RemoteBranchRef Import-Module -Scope Local "$PSScriptRoot/query-state/Select-Branches.psm1" Export-ModuleMember -Function Select-Branches -Import-Module -Scope Local "$PSScriptRoot/query-state/Select-AllUpstreamBranches.psm1" -Export-ModuleMember -Function Select-AllUpstreamBranches +Import-Module -Scope Local "$PSScriptRoot/query-state/Select-AllDependencyBranches.psm1" +Export-ModuleMember -Function Select-AllDependencyBranches -Import-Module -Scope Local "$PSScriptRoot/query-state/Select-DownstreamBranches.psm1" -Export-ModuleMember -Function Select-DownstreamBranches +Import-Module -Scope Local "$PSScriptRoot/query-state/Select-DependantBranches.psm1" +Export-ModuleMember -Function Select-DependantBranches diff --git a/utils/query-state/Compress-DependencyBranches.psm1 b/utils/query-state/Compress-DependencyBranches.psm1 new file mode 100644 index 0000000..1171857 --- /dev/null +++ b/utils/query-state/Compress-DependencyBranches.psm1 @@ -0,0 +1,32 @@ +Import-Module -Scope Local "$PSScriptRoot/../core.psm1" +Import-Module -Scope Local "$PSScriptRoot/../framework.psm1" +Import-Module -Scope Local "$PSScriptRoot/Select-DependencyBranches.psm1" + +function Compress-DependencyBranches( + [Parameter(Mandatory)][AllowEmptyCollection()][string[]] $originalDependency, + [Parameter()][AllowNull()] $overrideDependencies, + [Parameter()][AllowNull()][string] $branchName, + [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics +) { + $allDependency = $originalDependency | ConvertTo-HashMap -getValue { + return ([string[]](Select-DependencyBranches $_ -recurse -overrideDependencies:$overrideDependencies)) + } + $resultDependency = [System.Collections.ArrayList]$originalDependency + for ($i = 0; $i -lt $resultDependency.Count; $i++) { + $branch = $resultDependency[$i] + $alreadyContainedBy = ($resultDependency | Where-Object { $_ -ne $branch -AND $allDependency[$_] -contains $branch }) + if ($alreadyContainedBy -ne $nil) { + if (-not $branchName) { + Add-WarningDiagnostic $diagnostics "Removing '$branch' from branches; it is redundant via the following: $alreadyContainedBy" + } else { + Add-WarningDiagnostic $diagnostics "Removing '$branch' from dependency branches of '$branchName'; it is redundant via the following: $alreadyContainedBy" + } + # $branch is in the recursive dependency of at least one other branch + $resultDependency.Remove($branch) + $i-- + } + } + return [string[]]$resultDependency +} + +Export-ModuleMember -Function Compress-DependencyBranches diff --git a/utils/query-state/Compress-UpstreamBranches.tests.ps1 b/utils/query-state/Compress-DependencyBranches.tests.ps1 similarity index 56% rename from utils/query-state/Compress-UpstreamBranches.tests.ps1 rename to utils/query-state/Compress-DependencyBranches.tests.ps1 index 80bef56..dde7b6c 100644 --- a/utils/query-state/Compress-UpstreamBranches.tests.ps1 +++ b/utils/query-state/Compress-DependencyBranches.tests.ps1 @@ -1,15 +1,15 @@ BeforeAll { . "$PSScriptRoot/../testing.ps1" - Import-Module -Scope Local "$PSScriptRoot/Compress-UpstreamBranches.psm1" + Import-Module -Scope Local "$PSScriptRoot/Compress-DependencyBranches.psm1" Import-Module -Scope Local "$PSScriptRoot/../query-state.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../framework.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/Select-UpstreamBranches.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Select-DependencyBranches.mocks.psm1" } -Describe 'Compress-UpstreamBranches' { +Describe 'Compress-DependencyBranches' { BeforeAll { Initialize-ToolConfiguration - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'my-branch' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-123' = @('main') 'feature/XYZ-1-services' = @('main') @@ -28,59 +28,59 @@ Describe 'Compress-UpstreamBranches' { } It 'can handle a flat string' { - Compress-UpstreamBranches my-branch | Should -Be @( 'my-branch' ) + Compress-DependencyBranches my-branch | Should -Be @( 'my-branch' ) } It 'does not reduce any if none can be reduced' { - Compress-UpstreamBranches @("feature/FOO-123", "feature/XYZ-1-services") | Should -Be @("feature/FOO-123", "feature/XYZ-1-services") + Compress-DependencyBranches @("feature/FOO-123", "feature/XYZ-1-services") | Should -Be @("feature/FOO-123", "feature/XYZ-1-services") } It 'reduces redundant branches' { - Compress-UpstreamBranches @("my-branch", "feature/XYZ-1-services") | Should -Be @("my-branch") + Compress-DependencyBranches @("my-branch", "feature/XYZ-1-services") | Should -Be @("my-branch") } It 'allows an empty list' { - Compress-UpstreamBranches @() | Should -Be @() + Compress-DependencyBranches @() | Should -Be @() } It 'does not eliminate all recursive branches' { - Compress-UpstreamBranches @('bad-recursive-branch-1', 'bad-recursive-branch-2') | Should -Be @('bad-recursive-branch-2') + Compress-DependencyBranches @('bad-recursive-branch-1', 'bad-recursive-branch-2') | Should -Be @('bad-recursive-branch-2') } It 'allows overrides' { - Compress-UpstreamBranches @("feature/FOO-123", "feature/XYZ-1-services") -overrideUpstreams @{ + Compress-DependencyBranches @("feature/FOO-123", "feature/XYZ-1-services") -overrideDependencies @{ 'feature/FOO-123' = 'feature/XYZ-1-services' } | Should -Be @("feature/FOO-123") } Context 'with diagnostics' { It 'can handle a flat string' { - Compress-UpstreamBranches my-branch -diagnostics:$diag | Should -Be @( 'my-branch' ) + Compress-DependencyBranches my-branch -diagnostics:$diag | Should -Be @( 'my-branch' ) Should -ActualValue (Get-DiagnosticStrings $diag) -Be @() } It 'does not reduce any if none can be reduced' { - Compress-UpstreamBranches @("feature/FOO-123", "feature/XYZ-1-services") -diagnostics:$diag | Should -Be @("feature/FOO-123", "feature/XYZ-1-services") + Compress-DependencyBranches @("feature/FOO-123", "feature/XYZ-1-services") -diagnostics:$diag | Should -Be @("feature/FOO-123", "feature/XYZ-1-services") Should -ActualValue (Get-DiagnosticStrings $diag) -Be @() } It 'reduces redundant branches' { - Compress-UpstreamBranches @("my-branch", "feature/XYZ-1-services") -diagnostics:$diag | Should -Be @("my-branch") + Compress-DependencyBranches @("my-branch", "feature/XYZ-1-services") -diagnostics:$diag | Should -Be @("my-branch") Should -ActualValue (Get-DiagnosticStrings -diagnostics:$diag) -Be @("WARN: Removing 'feature/XYZ-1-services' from branches; it is redundant via the following: my-branch") } It 'reduces redundant branches with a named branch' { - Compress-UpstreamBranches @("my-branch", "feature/XYZ-1-services") -diagnostics:$diag -branchName:'feature/ABC' | Should -Be @("my-branch") - Should -ActualValue (Get-DiagnosticStrings -diagnostics:$diag) -Be @("WARN: Removing 'feature/XYZ-1-services' from upstream branches of 'feature/ABC'; it is redundant via the following: my-branch") + Compress-DependencyBranches @("my-branch", "feature/XYZ-1-services") -diagnostics:$diag -branchName:'feature/ABC' | Should -Be @("my-branch") + Should -ActualValue (Get-DiagnosticStrings -diagnostics:$diag) -Be @("WARN: Removing 'feature/XYZ-1-services' from dependency branches of 'feature/ABC'; it is redundant via the following: my-branch") } It 'allows an empty list' { - Compress-UpstreamBranches @() -diagnostics:$diag | Should -Be @() + Compress-DependencyBranches @() -diagnostics:$diag | Should -Be @() Should -ActualValue (Get-DiagnosticStrings $diag) -Be @() } It 'does not eliminate all recursive branches' { - Compress-UpstreamBranches @('bad-recursive-branch-1', 'bad-recursive-branch-2') -diagnostics:$diag | Should -Be @('bad-recursive-branch-2') + Compress-DependencyBranches @('bad-recursive-branch-1', 'bad-recursive-branch-2') -diagnostics:$diag | Should -Be @('bad-recursive-branch-2') Should -ActualValue (Get-DiagnosticStrings $diag) -Be @("WARN: Removing 'bad-recursive-branch-1' from branches; it is redundant via the following: bad-recursive-branch-2") } diff --git a/utils/query-state/Compress-UpstreamBranches.psm1 b/utils/query-state/Compress-UpstreamBranches.psm1 deleted file mode 100644 index cadf1b5..0000000 --- a/utils/query-state/Compress-UpstreamBranches.psm1 +++ /dev/null @@ -1,32 +0,0 @@ -Import-Module -Scope Local "$PSScriptRoot/../core.psm1" -Import-Module -Scope Local "$PSScriptRoot/../framework.psm1" -Import-Module -Scope Local "$PSScriptRoot/Select-UpstreamBranches.psm1" - -function Compress-UpstreamBranches( - [Parameter(Mandatory)][AllowEmptyCollection()][string[]] $originalUpstream, - [Parameter()][AllowNull()] $overrideUpstreams, - [Parameter()][AllowNull()][string] $branchName, - [Parameter()][AllowNull()][AllowEmptyCollection()][System.Collections.ArrayList] $diagnostics -) { - $allUpstream = $originalUpstream | ConvertTo-HashMap -getValue { - return ([string[]](Select-UpstreamBranches $_ -recurse -overrideUpstreams:$overrideUpstreams)) - } - $resultUpstream = [System.Collections.ArrayList]$originalUpstream - for ($i = 0; $i -lt $resultUpstream.Count; $i++) { - $branch = $resultUpstream[$i] - $alreadyContainedBy = ($resultUpstream | Where-Object { $_ -ne $branch -AND $allUpstream[$_] -contains $branch }) - if ($alreadyContainedBy -ne $nil) { - if (-not $branchName) { - Add-WarningDiagnostic $diagnostics "Removing '$branch' from branches; it is redundant via the following: $alreadyContainedBy" - } else { - Add-WarningDiagnostic $diagnostics "Removing '$branch' from upstream branches of '$branchName'; it is redundant via the following: $alreadyContainedBy" - } - # $branch is in the recursive upstream of at least one other branch - $resultUpstream.Remove($branch) - $i-- - } - } - return [string[]]$resultUpstream -} - -Export-ModuleMember -Function Compress-UpstreamBranches diff --git a/utils/query-state/Configuration.mocks.psm1 b/utils/query-state/Configuration.mocks.psm1 index 0c8fca9..1a86bcc 100644 --- a/utils/query-state/Configuration.mocks.psm1 +++ b/utils/query-state/Configuration.mocks.psm1 @@ -9,7 +9,7 @@ function Initialize-ToolConfiguration( [switch]$noRemote, [string]$remote = 'origin', [string]$defaultServiceLine = 'main', - [string]$upstreamBranchName = '_upstream', + [string]$dependencyBranchName = '$dependencies', [switch]$noAtomicPush ) { if ($noRemote) { @@ -19,7 +19,7 @@ function Initialize-ToolConfiguration( Invoke-MockGit 'config scaled-git.remote' $remote } - Invoke-MockGit 'config scaled-git.upstreamBranch' $upstreamBranchName + Invoke-MockGit 'config scaled-git.dependencyBranch' $dependencyBranchName Invoke-MockGit 'config scaled-git.defaultServiceLine' -MockWith $defaultServiceLine Invoke-MockGit 'config scaled-git.atomicPushEnabled' -MockWith (-not $noAtomicPush) } diff --git a/utils/query-state/Configuration.psm1 b/utils/query-state/Configuration.psm1 index bea2209..d8e3948 100644 --- a/utils/query-state/Configuration.psm1 +++ b/utils/query-state/Configuration.psm1 @@ -3,7 +3,7 @@ function Get-Configuration() { $remote = Get-ConfiguredRemote return @{ remote = $remote - upstreamBranch = Get-ConfiguredUpstreamBranch + dependencyBranch = Get-ConfiguredDependencyBranch defaultServiceLine = Get-ConfiguredDefaultServiceLine -remote $remote atomicPushEnabled = Get-ConfiguredAtomicPushEnabled } @@ -15,12 +15,12 @@ function Get-ConfiguredRemote() { return git remote | Select-Object -First 1 } -function Get-ConfiguredUpstreamBranch() { - $result = git config scaled-git.upstreamBranch +function Get-ConfiguredDependencyBranch() { + $result = git config scaled-git.dependencyBranch if ($null -ne $result) { return $result; } - return '_upstream' + return '$dependencies' } function Get-ConfiguredDefaultServiceLine([string]$remote) { diff --git a/utils/query-state/Configuration.tests.ps1 b/utils/query-state/Configuration.tests.ps1 index e4f15c5..8390ad1 100644 --- a/utils/query-state/Configuration.tests.ps1 +++ b/utils/query-state/Configuration.tests.ps1 @@ -14,10 +14,10 @@ Describe 'Get-Configuration' { Invoke-MockGit 'remote' Invoke-MockGit 'config scaled-git.defaultServiceLine' Invoke-MockGit 'rev-parse --verify main -q' { 'some-hash' } - Invoke-MockGit 'config scaled-git.upstreamBranch' + Invoke-MockGit 'config scaled-git.dependencyBranch' Invoke-MockGit 'config scaled-git.atomicPushEnabled' - Get-Configuration | Assert-ShouldBeObject @{ remote = $null; upstreamBranch = '_upstream'; defaultServiceLine = 'main'; atomicPushEnabled = $true } + Get-Configuration | Assert-ShouldBeObject @{ remote = $null; dependencyBranch = '$dependencies'; defaultServiceLine = 'main'; atomicPushEnabled = $true } } It 'Defaults values with no main branch' { @@ -25,10 +25,10 @@ Describe 'Get-Configuration' { Invoke-MockGit 'remote' Invoke-MockGit 'config scaled-git.defaultServiceLine' Invoke-MockGit 'rev-parse --verify main -q' { $global:LASTEXITCODE = 128 } - Invoke-MockGit 'config scaled-git.upstreamBranch' + Invoke-MockGit 'config scaled-git.dependencyBranch' Invoke-MockGit 'config scaled-git.atomicPushEnabled' - Get-Configuration | Assert-ShouldBeObject @{ remote = $null; upstreamBranch = '_upstream'; defaultServiceLine = $null; atomicPushEnabled = $true } + Get-Configuration | Assert-ShouldBeObject @{ remote = $null; dependencyBranch = '$dependencies'; defaultServiceLine = $null; atomicPushEnabled = $true } } It 'Defaults values with a remote main branch' { @@ -36,18 +36,18 @@ Describe 'Get-Configuration' { Invoke-MockGit 'remote' { 'origin' } Invoke-MockGit 'config scaled-git.defaultServiceLine' Invoke-MockGit 'rev-parse --verify origin/main -q' { 'some-hash'} - Invoke-MockGit 'config scaled-git.upstreamBranch' + Invoke-MockGit 'config scaled-git.dependencyBranch' Invoke-MockGit 'config scaled-git.atomicPushEnabled' - Get-Configuration | Assert-ShouldBeObject @{ remote = 'origin'; upstreamBranch = '_upstream'; defaultServiceLine = 'main'; atomicPushEnabled = $true } + Get-Configuration | Assert-ShouldBeObject @{ remote = 'origin'; dependencyBranch = '$dependencies'; defaultServiceLine = 'main'; atomicPushEnabled = $true } } It 'Overrides defaults' { Invoke-MockGit 'config scaled-git.remote' { 'github' } - Invoke-MockGit 'config scaled-git.upstreamBranch' { 'upstream-config' } + Invoke-MockGit 'config scaled-git.dependencyBranch' { 'dependency-config' } Invoke-MockGit 'config scaled-git.defaultServiceLine' { 'trunk' } Invoke-MockGit 'config scaled-git.atomicPushEnabled' { $false } - Get-Configuration | Assert-ShouldBeObject @{ remote = 'github'; upstreamBranch = 'upstream-config'; defaultServiceLine = 'trunk'; atomicPushEnabled = $false } + Get-Configuration | Assert-ShouldBeObject @{ remote = 'github'; dependencyBranch = 'dependency-config'; defaultServiceLine = 'trunk'; atomicPushEnabled = $false } } } diff --git a/utils/query-state/Get-DependencyBranch.mocks.psm1 b/utils/query-state/Get-DependencyBranch.mocks.psm1 new file mode 100644 index 0000000..c249907 --- /dev/null +++ b/utils/query-state/Get-DependencyBranch.mocks.psm1 @@ -0,0 +1,12 @@ +Import-Module -Scope Local "$PSScriptRoot/../testing.psm1" +Import-Module -Scope Local "$PSScriptRoot/Get-DependencyBranch.psm1" +Import-Module -Scope Local "$PSScriptRoot/../query-state.psm1" + +function Initialize-FetchDependencyBranch() { + $config = Get-Configuration + if ($config.remote -ne $nil) { + Invoke-MockGitModule -ModuleName 'Get-DependencyBranch' -gitCli "fetch $($config.remote) $($config.dependencyBranch)" + } +} + +Export-ModuleMember -Function Initialize-FetchDependencyBranch diff --git a/utils/query-state/Get-DependencyBranch.psm1 b/utils/query-state/Get-DependencyBranch.psm1 new file mode 100644 index 0000000..cc732b7 --- /dev/null +++ b/utils/query-state/Get-DependencyBranch.psm1 @@ -0,0 +1,15 @@ +Import-Module -Scope Local "$PSScriptRoot/Configuration.psm1" + +function Get-DependencyBranch( + [switch] $fetch +) { + $config = Get-Configuration + $dependencyBranch = $config.remote -eq $nil ? $config.dependencyBranch : "$($config.remote)/$($config.dependencyBranch)" + + if ($config.remote -ne $nil -AND $fetch) { + git fetch $config.remote $config.dependencyBranch 2> $nil + } + + return $dependencyBranch +} +Export-ModuleMember -Function Get-DependencyBranch diff --git a/utils/query-state/Get-DependencyBranch.tests.ps1 b/utils/query-state/Get-DependencyBranch.tests.ps1 new file mode 100644 index 0000000..a8c9172 --- /dev/null +++ b/utils/query-state/Get-DependencyBranch.tests.ps1 @@ -0,0 +1,29 @@ +BeforeAll { + . "$PSScriptRoot/../testing.ps1" + Import-Module -Scope Local "$PSScriptRoot/../framework.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Configuration.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Get-DependencyBranch.psm1" + Import-Module -Scope Local "$PSScriptRoot/Get-DependencyBranch.mocks.psm1" +} + +Describe 'Get-DependencyBranch' { + BeforeEach { + Register-Framework + } + + It 'computes the dependency tracking branch name' { + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' -remote 'github' + Get-DependencyBranch | Should -Be 'github/my-dependency' + } + It 'can handle no remote' { + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' -noRemote + Get-DependencyBranch | Should -Be 'my-dependency' + } + It 'fetches if requested' { + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' -remote 'github' + $mock = Initialize-FetchDependencyBranch + + Get-DependencyBranch -fetch | Should -Be 'github/my-dependency' + Invoke-VerifyMock $mock -Times 1 + } +} diff --git a/utils/query-state/Get-GitFile.tests.ps1 b/utils/query-state/Get-GitFile.tests.ps1 index 584bd83..e0fae34 100644 --- a/utils/query-state/Get-GitFile.tests.ps1 +++ b/utils/query-state/Get-GitFile.tests.ps1 @@ -6,9 +6,9 @@ BeforeAll { Describe 'Get-GitFile' { It 'outputs a file' { - Initialize-GitFile 'origin/_upstream' 'integrate/FOO-125_XYZ-1' @("feature/FOO-124_FOO-125", "feature/XYZ-1-services") + Initialize-GitFile 'origin/$dependencies' 'integrate/FOO-125_XYZ-1' @("feature/FOO-124_FOO-125", "feature/XYZ-1-services") - $result = Get-GitFile 'integrate/FOO-125_XYZ-1' 'origin/_upstream' + $result = Get-GitFile 'integrate/FOO-125_XYZ-1' 'origin/$dependencies' $result[0] | Should -Be "feature/FOO-124_FOO-125" $result[1] | Should -Be "feature/XYZ-1-services" } diff --git a/utils/query-state/Get-UpstreamBranch.mocks.psm1 b/utils/query-state/Get-UpstreamBranch.mocks.psm1 deleted file mode 100644 index bca24fc..0000000 --- a/utils/query-state/Get-UpstreamBranch.mocks.psm1 +++ /dev/null @@ -1,12 +0,0 @@ -Import-Module -Scope Local "$PSScriptRoot/../testing.psm1" -Import-Module -Scope Local "$PSScriptRoot/Get-UpstreamBranch.psm1" -Import-Module -Scope Local "$PSScriptRoot/../query-state.psm1" - -function Initialize-FetchUpstreamBranch() { - $config = Get-Configuration - if ($config.remote -ne $nil) { - Invoke-MockGitModule -ModuleName 'Get-UpstreamBranch' -gitCli "fetch $($config.remote) $($config.upstreamBranch)" - } -} - -Export-ModuleMember -Function Initialize-FetchUpstreamBranch diff --git a/utils/query-state/Get-UpstreamBranch.psm1 b/utils/query-state/Get-UpstreamBranch.psm1 deleted file mode 100644 index c156621..0000000 --- a/utils/query-state/Get-UpstreamBranch.psm1 +++ /dev/null @@ -1,15 +0,0 @@ -Import-Module -Scope Local "$PSScriptRoot/Configuration.psm1" - -function Get-UpstreamBranch( - [switch] $fetch -) { - $config = Get-Configuration - $upstreamBranch = $config.remote -eq $nil ? $config.upstreamBranch : "$($config.remote)/$($config.upstreamBranch)" - - if ($config.remote -ne $nil -AND $fetch) { - git fetch $config.remote $config.upstreamBranch 2> $nil - } - - return $upstreamBranch -} -Export-ModuleMember -Function Get-UpstreamBranch diff --git a/utils/query-state/Get-UpstreamBranch.tests.ps1 b/utils/query-state/Get-UpstreamBranch.tests.ps1 deleted file mode 100644 index 5af74b3..0000000 --- a/utils/query-state/Get-UpstreamBranch.tests.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -BeforeAll { - . "$PSScriptRoot/../testing.ps1" - Import-Module -Scope Local "$PSScriptRoot/../framework.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/Configuration.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/Get-UpstreamBranch.psm1" - Import-Module -Scope Local "$PSScriptRoot/Get-UpstreamBranch.mocks.psm1" -} - -Describe 'Get-UpstreamBranch' { - BeforeEach { - Register-Framework - } - - It 'computes the upstream tracking branch name' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' -remote 'github' - Get-UpstreamBranch | Should -Be 'github/my-upstream' - } - It 'can handle no remote' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' -noRemote - Get-UpstreamBranch | Should -Be 'my-upstream' - } - It 'fetches if requested' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' -remote 'github' - $mock = Initialize-FetchUpstreamBranch - - Get-UpstreamBranch -fetch | Should -Be 'github/my-upstream' - Invoke-VerifyMock $mock -Times 1 - } -} diff --git a/utils/query-state/Select-AllDependencyBranches.mocks.psm1 b/utils/query-state/Select-AllDependencyBranches.mocks.psm1 new file mode 100644 index 0000000..4620d03 --- /dev/null +++ b/utils/query-state/Select-AllDependencyBranches.mocks.psm1 @@ -0,0 +1,24 @@ +Import-Module -Scope Local "$PSScriptRoot/../../utils/testing.psm1" +Import-Module -Scope Local "$PSScriptRoot/Get-DependencyBranch.psm1" +Import-Module -Scope Local "$PSScriptRoot/Select-AllDependencyBranches.psm1" + +function Invoke-MockGit([string] $gitCli, [object] $MockWith) { + return Invoke-MockGitModule -ModuleName 'Select-AllDependencyBranches' @PSBoundParameters +} + +function Initialize-AllDependencyBranches([PSObject] $dependencyConfiguration) { + $dependency = Get-DependencyBranch + $workDir = [System.IO.Path]::GetRandomFileName() + Invoke-MockGit "rev-parse --show-toplevel" -MockWith $workDir + + $treeEntries = $dependencyConfiguration.Keys | ForEach-Object { "100644 blob $_-blob`t$_" } | Sort-Object + Invoke-MockGit "ls-tree -r $dependency" -MockWith $treeEntries + + if ($dependencyConfiguration.Count -gt 0) { + $result = ($dependencyConfiguration.Keys | ForEach-Object { + "`t$_-blob`n$($dependencyConfiguration[$_] -join "`n")" + }) -join "`n`n" + Invoke-MockGit "cat-file --batch=`t%(objectname)" -MockWith $result + } +} +Export-ModuleMember -Function Initialize-AllDependencyBranches diff --git a/utils/query-state/Select-AllUpstreamBranches.psm1 b/utils/query-state/Select-AllDependencyBranches.psm1 similarity index 66% rename from utils/query-state/Select-AllUpstreamBranches.psm1 rename to utils/query-state/Select-AllDependencyBranches.psm1 index f3ff8ce..4b67df1 100644 --- a/utils/query-state/Select-AllUpstreamBranches.psm1 +++ b/utils/query-state/Select-AllDependencyBranches.psm1 @@ -1,11 +1,11 @@ Import-Module -Scope Local "$PSScriptRoot/../core.psm1" Import-Module -Scope Local "$PSScriptRoot/../framework.psm1" -Import-Module -Scope Local "$PSScriptRoot/Get-UpstreamBranch.psm1" +Import-Module -Scope Local "$PSScriptRoot/Get-DependencyBranch.psm1" Import-Module -Scope Local "$PSScriptRoot/Get-GitFile.psm1" Import-Module -Scope Local "$PSScriptRoot/Configuration.psm1" -# allUpstreams is a hashmap where the key is the git working directory and -$allUpstreams = @{} +# allDependencies is a hashmap where the key is the git working directory and +$allDependencies = @{} function Select-Override( [Parameter(Mandatory)][System.Collections.Hashtable] $first, @@ -18,23 +18,23 @@ function Select-Override( return $result } -function Select-AllUpstreamBranches([switch]$refresh, [Parameter()][AllowNull()] $overrideUpstreams) { +function Select-AllDependencyBranches([switch]$refresh, [Parameter()][AllowNull()] $overrideDependencies) { $workDir = Invoke-ProcessLogs "git rev-parse --show-toplevel" { git rev-parse --show-toplevel } -allowSuccessOutput - if ($allUpstreams[$workDir] -AND -not $refresh) { - return $overrideUpstreams ? (Select-Override -first $allUpstreams[$workDir] -second (ConvertTo-Hashtable $overrideUpstreams)) : $allUpstreams[$workDir] + if ($allDependencies[$workDir] -AND -not $refresh) { + return $overrideDependencies ? (Select-Override -first $allDependencies[$workDir] -second (ConvertTo-Hashtable $overrideDependencies)) : $allDependencies[$workDir] } - $nodes = $allUpstreams[$workDir] = @{} + $nodes = $allDependencies[$workDir] = @{} - $upstreamBranch = Get-UpstreamBranch + $dependencyBranch = Get-DependencyBranch # --format would be nice to use, but it was introduced in git version 2.36, which isn't the default installed yet. # Rather than adding a version check, I figured parsing it would be fine. # The default format is: permission ' blob ' hash '`t' branchName - $treeEntries = (Invoke-ProcessLogs "git ls-tree -r $upstreamBranch" { - git ls-tree -r $upstreamBranch + $treeEntries = (Invoke-ProcessLogs "git ls-tree -r $dependencyBranch" { + git ls-tree -r $dependencyBranch } -allowSuccessOutput) | ForEach-Object { $record, $name = $_.Split("`t") $permission, $type, $hash = $record.Split(' ') @@ -63,17 +63,17 @@ function Select-AllUpstreamBranches([switch]$refresh, [Parameter()][AllowNull()] } } - return $overrideUpstreams ? (Select-Override -first $nodes -second (ConvertTo-Hashtable $overrideUpstreams)) : $nodes + return $overrideDependencies ? (Select-Override -first $nodes -second (ConvertTo-Hashtable $overrideDependencies)) : $nodes } -function Clear-AllUpstreamBranchCache([string] $workDir) { +function Clear-AllDependencyBranchCache([string] $workDir) { if ($workDir) { - $allUpstreams[$workDir] = $null + $allDependencies[$workDir] = $null } else { - $allUpstreams = @{} + $allDependencies = @{} } } # This module is intentionally kept internal to the query-state folder in case of breaking changes. -# Use `Select-UpstreamBranches` or other query-state utility instead. -Export-ModuleMember -Function Select-AllUpstreamBranches, Clear-AllUpstreamBranchCache +# Use `Select-DependencyBranches` or other query-state utility instead. +Export-ModuleMember -Function Select-AllDependencyBranches, Clear-AllDependencyBranchCache diff --git a/utils/query-state/Select-AllUpstreamBranches.tests.ps1 b/utils/query-state/Select-AllDependencyBranches.tests.ps1 similarity index 59% rename from utils/query-state/Select-AllUpstreamBranches.tests.ps1 rename to utils/query-state/Select-AllDependencyBranches.tests.ps1 index 2ef86db..1153ce5 100644 --- a/utils/query-state/Select-AllUpstreamBranches.tests.ps1 +++ b/utils/query-state/Select-AllDependencyBranches.tests.ps1 @@ -1,47 +1,47 @@ BeforeAll { . "$PSScriptRoot/../testing.ps1" Import-Module -Scope Local "$PSScriptRoot/../framework.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/Select-AllUpstreamBranches.psm1" - Import-Module -Scope Local "$PSScriptRoot/Select-AllUpstreamBranches.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Select-AllDependencyBranches.psm1" + Import-Module -Scope Local "$PSScriptRoot/Select-AllDependencyBranches.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../query-state.mocks.psm1" } -Describe 'Select-AllUpstreamBranches' { +Describe 'Select-AllDependencyBranches' { BeforeEach { Register-Framework } Describe 'simple structure' { BeforeEach { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $mocks = Initialize-AllUpstreamBranches @{ + $mocks = Initialize-AllDependencyBranches @{ 'my-branch' = @("feature/FOO-123", "feature/XYZ-1-services") } } - It 'finds upstream branches from git' { - (Select-AllUpstreamBranches)['my-branch'] | Should -Be @( 'feature/FOO-123', 'feature/XYZ-1-services' ) + It 'finds dependency branches from git' { + (Select-AllDependencyBranches)['my-branch'] | Should -Be @( 'feature/FOO-123', 'feature/XYZ-1-services' ) Invoke-VerifyMock $mocks -Times 1 } It 'provides $null for missing branches' { - (Select-AllUpstreamBranches)['not/a/branch'] | Should -Be $null + (Select-AllDependencyBranches)['not/a/branch'] | Should -Be $null Invoke-VerifyMock $mocks -Times 1 } It 'only runs once, even if called multiple times' { - Select-AllUpstreamBranches - Select-AllUpstreamBranches + Select-AllDependencyBranches + Select-AllDependencyBranches Invoke-VerifyMock $mocks -Times 1 - { + { Invoke-ProcessLogs 'testing' { Invoke-VerifyMock $mocks -Times 2 } } | Should -Throw } It 'runs twice if specified' { - Select-AllUpstreamBranches - Select-AllUpstreamBranches -refresh + Select-AllDependencyBranches + Select-AllDependencyBranches -refresh Invoke-VerifyMock $mocks -Times 2 } } @@ -50,7 +50,7 @@ Describe 'Select-AllUpstreamBranches' { BeforeEach { Initialize-ToolConfiguration [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification='This is put in scope and used in the tests below')] - $mocks = Initialize-AllUpstreamBranches @{ + $mocks = Initialize-AllDependencyBranches @{ 'rc/1.1.0' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-123' = @("line/1.0") 'feature/XYZ-1-services' = @("infra/some-service") @@ -59,8 +59,8 @@ Describe 'Select-AllUpstreamBranches' { } It 'handles deep folders' { - (Select-AllUpstreamBranches)['feature/FOO-123'] | Should -Be @("line/1.0") - (Select-AllUpstreamBranches)['feature/XYZ-1-services'] | Should -Be @("infra/some-service") + (Select-AllDependencyBranches)['feature/FOO-123'] | Should -Be @("line/1.0") + (Select-AllDependencyBranches)['feature/XYZ-1-services'] | Should -Be @("infra/some-service") Invoke-VerifyMock $mocks -Times 1 } } @@ -71,19 +71,19 @@ Describe 'Select-AllUpstreamBranches' { } It 'handles deep folders' { - $mocks = Initialize-AllUpstreamBranches @{ + $mocks = Initialize-AllDependencyBranches @{ 'rc/1.1.0' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/XYZ-1-services' = @("infra/some-service") 'infra/some-service' = @("line/1.0") } - $overrideUpstreams = @{ + $overrideDependencies = @{ 'feature/FOO-123' = @("line/1.0") 'infra/some-service' = @('main') }; - (Select-AllUpstreamBranches -overrideUpstreams $overrideUpstreams)['feature/FOO-123'] | Should -Be @("line/1.0") - (Select-AllUpstreamBranches -overrideUpstreams $overrideUpstreams)['feature/XYZ-1-services'] | Should -Be @("infra/some-service") - (Select-AllUpstreamBranches -overrideUpstreams $overrideUpstreams)['infra/some-service'] | Should -Be @("main") + (Select-AllDependencyBranches -overrideDependencies $overrideDependencies)['feature/FOO-123'] | Should -Be @("line/1.0") + (Select-AllDependencyBranches -overrideDependencies $overrideDependencies)['feature/XYZ-1-services'] | Should -Be @("infra/some-service") + (Select-AllDependencyBranches -overrideDependencies $overrideDependencies)['infra/some-service'] | Should -Be @("main") Invoke-VerifyMock $mocks -Times 1 } } diff --git a/utils/query-state/Select-AllUpstreamBranches.mocks.psm1 b/utils/query-state/Select-AllUpstreamBranches.mocks.psm1 deleted file mode 100644 index c03c9ae..0000000 --- a/utils/query-state/Select-AllUpstreamBranches.mocks.psm1 +++ /dev/null @@ -1,24 +0,0 @@ -Import-Module -Scope Local "$PSScriptRoot/../../utils/testing.psm1" -Import-Module -Scope Local "$PSScriptRoot/Get-UpstreamBranch.psm1" -Import-Module -Scope Local "$PSScriptRoot/Select-AllUpstreamBranches.psm1" - -function Invoke-MockGit([string] $gitCli, [object] $MockWith) { - return Invoke-MockGitModule -ModuleName 'Select-AllUpstreamBranches' @PSBoundParameters -} - -function Initialize-AllUpstreamBranches([PSObject] $upstreamConfiguration) { - $upstream = Get-UpstreamBranch - $workDir = [System.IO.Path]::GetRandomFileName() - Invoke-MockGit "rev-parse --show-toplevel" -MockWith $workDir - - $treeEntries = $upstreamConfiguration.Keys | ForEach-Object { "100644 blob $_-blob`t$_" } | Sort-Object - Invoke-MockGit "ls-tree -r $upstream" -MockWith $treeEntries - - if ($upstreamConfiguration.Count -gt 0) { - $result = ($upstreamConfiguration.Keys | ForEach-Object { - "`t$_-blob`n$($upstreamConfiguration[$_] -join "`n")" - }) -join "`n`n" - Invoke-MockGit "cat-file --batch=`t%(objectname)" -MockWith $result - } -} -Export-ModuleMember -Function Initialize-AllUpstreamBranches diff --git a/utils/query-state/Select-DownstreamBranches.psm1 b/utils/query-state/Select-DependantBranches.psm1 similarity index 69% rename from utils/query-state/Select-DownstreamBranches.psm1 rename to utils/query-state/Select-DependantBranches.psm1 index b88bcb6..504a8e6 100644 --- a/utils/query-state/Select-DownstreamBranches.psm1 +++ b/utils/query-state/Select-DependantBranches.psm1 @@ -1,12 +1,12 @@ -Import-Module -Scope Local "$PSScriptRoot/Select-AllUpstreamBranches.psm1" +Import-Module -Scope Local "$PSScriptRoot/Select-AllDependencyBranches.psm1" Import-Module -Scope Local "$PSScriptRoot/Configuration.psm1" -function Select-DownstreamBranches( +function Select-DependantBranches( [String]$branchName, [switch] $recurse, - [string[]] $exclude, - [Parameter()][AllowNull()] $overrideUpstreams) { - $all = Select-AllUpstreamBranches -overrideUpstreams:$overrideUpstreams + [string[]] $exclude, + [Parameter()][AllowNull()] $overrideDependencies) { + $all = Select-AllDependencyBranches -overrideDependencies:$overrideDependencies $parentBranches = $all.Keys | Where-Object { $exclude -notcontains $_ } | Where-Object { @@ -20,7 +20,7 @@ function Select-DownstreamBranches( if ($recurse) { $currentExclude = [string[]]( @($branchName, $exclude) | ForEach-Object { $_ } ) $finalParents = [string[]]( $parentBranches | ForEach-Object { - $newParents = [string[]](Select-DownstreamBranches $_ -recurse -exclude $currentExclude) + $newParents = [string[]](Select-DependantBranches $_ -recurse -exclude $currentExclude) if ($newParents -eq $nil) { return @() } @@ -31,4 +31,4 @@ function Select-DownstreamBranches( } return $parentBranches } -Export-ModuleMember -Function Select-DownstreamBranches +Export-ModuleMember -Function Select-DependantBranches diff --git a/utils/query-state/Select-DownstreamBranches.tests.ps1 b/utils/query-state/Select-DependantBranches.tests.ps1 similarity index 68% rename from utils/query-state/Select-DownstreamBranches.tests.ps1 rename to utils/query-state/Select-DependantBranches.tests.ps1 index 6ac3a11..6ed2b42 100644 --- a/utils/query-state/Select-DownstreamBranches.tests.ps1 +++ b/utils/query-state/Select-DependantBranches.tests.ps1 @@ -1,17 +1,17 @@ BeforeAll { . "$PSScriptRoot/../testing.ps1" Import-Module -Scope Local "$PSScriptRoot/../framework.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/Select-DownstreamBranches.psm1" - Import-Module -Scope Local "$PSScriptRoot/Select-AllUpstreamBranches.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Select-DependantBranches.psm1" + Import-Module -Scope Local "$PSScriptRoot/Select-AllDependencyBranches.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../query-state.mocks.psm1" } -Describe 'Select-DownstreamBranches' { +Describe 'Select-DependantBranches' { BeforeEach { Register-Framework Initialize-ToolConfiguration - Initialize-AllUpstreamBranches @{ + Initialize-AllDependencyBranches @{ 'integrate/FOO-123_XYZ-1' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-124' = @("feature/FOO-123") 'feature/FOO-123' = @("main") @@ -23,20 +23,20 @@ Describe 'Select-DownstreamBranches' { } } - It 'finds downstream branches' { - $results = Select-DownstreamBranches 'main' + It 'finds dependants branches' { + $results = Select-DependantBranches 'main' $results.Length | Should -Be 2 $results | Should -Contain 'feature/FOO-123' $results | Should -Contain 'feature/XYZ-1-services' } - It 'allows some downstreams to be excluded' { - $results = Select-DownstreamBranches 'main' -exclude @('feature/FOO-123') + It 'allows some dependants to be excluded' { + $results = Select-DependantBranches 'main' -exclude @('feature/FOO-123') $results | Should -Be @( 'feature/XYZ-1-services' ) } - It 'finds recursive downstream branches' { - $results = Select-DownstreamBranches 'main' -recurse + It 'finds recursive dependants branches' { + $results = Select-DependantBranches 'main' -recurse $results.Length | Should -Be 5 $results | Should -Contain 'feature/FOO-123' $results | Should -Contain 'feature/XYZ-1-services' @@ -46,7 +46,7 @@ Describe 'Select-DownstreamBranches' { } It 'allows some to be excluded even through ancestors' { - $results = Select-DownstreamBranches 'main' -recurse -exclude @('rc/1.1.0') + $results = Select-DependantBranches 'main' -recurse -exclude @('rc/1.1.0') $results.Length | Should -Be 4 $results | Should -Contain 'feature/FOO-123' $results | Should -Contain 'feature/XYZ-1-services' @@ -55,12 +55,12 @@ Describe 'Select-DownstreamBranches' { } It 'handles (invalid) recursiveness without failing' { - $results = Select-DownstreamBranches bad-recursive-branch-1 -recurse + $results = Select-DependantBranches bad-recursive-branch-1 -recurse $results | Should -Be @( 'bad-recursive-branch-2' ) } It 'allows overrides' { - $results = Select-DownstreamBranches infra/next -overrideUpstreams @{ 'feature/FOO-123' = 'infra/next' } + $results = Select-DependantBranches infra/next -overrideDependencies @{ 'feature/FOO-123' = 'infra/next' } $results | Should -Be @( 'feature/FOO-123' ) } } diff --git a/utils/query-state/Select-DependencyBranches.mocks.psm1 b/utils/query-state/Select-DependencyBranches.mocks.psm1 new file mode 100644 index 0000000..c1189cd --- /dev/null +++ b/utils/query-state/Select-DependencyBranches.mocks.psm1 @@ -0,0 +1,8 @@ +Import-Module -Scope Local "$PSScriptRoot/Get-DependencyBranch.psm1" +Import-Module -Scope Local "$PSScriptRoot/Get-GitFile.mocks.psm1" +Import-Module -Scope Local "$PSScriptRoot/Select-AllDependencyBranches.mocks.psm1" + +function Initialize-DependencyBranches([PSObject] $dependencyConfiguration) { + Initialize-AllDependencyBranches $dependencyConfiguration +} +Export-ModuleMember -Function Initialize-DependencyBranches diff --git a/utils/query-state/Select-UpstreamBranches.psm1 b/utils/query-state/Select-DependencyBranches.psm1 similarity index 68% rename from utils/query-state/Select-UpstreamBranches.psm1 rename to utils/query-state/Select-DependencyBranches.psm1 index d031071..501ef24 100644 --- a/utils/query-state/Select-UpstreamBranches.psm1 +++ b/utils/query-state/Select-DependencyBranches.psm1 @@ -1,15 +1,15 @@ -Import-Module -Scope Local "$PSScriptRoot/Select-AllUpstreamBranches.psm1" +Import-Module -Scope Local "$PSScriptRoot/Select-AllDependencyBranches.psm1" Import-Module -Scope Local "$PSScriptRoot/Configuration.psm1" -function Select-UpstreamBranches( - [String]$branchName, - [switch] $includeRemote, - [switch] $recurse, - [string[]] $exclude, - [Parameter()][AllowNull()] $overrideUpstreams +function Select-DependencyBranches( + [String]$branchName, + [switch] $includeRemote, + [switch] $recurse, + [string[]] $exclude, + [Parameter()][AllowNull()] $overrideDependencies ) { $config = Get-Configuration - $all = Select-AllUpstreamBranches -overrideUpstreams:$overrideUpstreams + $all = Select-AllDependencyBranches -overrideDependencies:$overrideDependencies $parentBranches = [string[]]($all[$branchName]) $parentBranches = $parentBranches | Where-Object { $exclude -notcontains $_ } @@ -21,7 +21,7 @@ function Select-UpstreamBranches( if ($recurse) { $currentExclude = [string[]]( @($branchName, $exclude) | ForEach-Object { $_ } ) $finalParents = [string[]]( $parentBranches | ForEach-Object { - $newParents = [string[]](Select-UpstreamBranches $_ -recurse -exclude $currentExclude) + $newParents = [string[]](Select-DependencyBranches $_ -recurse -exclude $currentExclude) if ($newParents -eq $nil) { return @() } @@ -37,4 +37,4 @@ function Select-UpstreamBranches( return $parentBranches } } -Export-ModuleMember -Function Select-UpstreamBranches +Export-ModuleMember -Function Select-DependencyBranches diff --git a/utils/query-state/Select-UpstreamBranches.tests.ps1 b/utils/query-state/Select-DependencyBranches.tests.ps1 similarity index 51% rename from utils/query-state/Select-UpstreamBranches.tests.ps1 rename to utils/query-state/Select-DependencyBranches.tests.ps1 index 7c3720b..399f0c1 100644 --- a/utils/query-state/Select-UpstreamBranches.tests.ps1 +++ b/utils/query-state/Select-DependencyBranches.tests.ps1 @@ -1,85 +1,85 @@ BeforeAll { . "$PSScriptRoot/../testing.ps1" Import-Module -Scope Local "$PSScriptRoot/../framework.mocks.psm1" - Import-Module -Scope Local "$PSScriptRoot/Select-UpstreamBranches.psm1" - Import-Module -Scope Local "$PSScriptRoot/Select-UpstreamBranches.mocks.psm1" + Import-Module -Scope Local "$PSScriptRoot/Select-DependencyBranches.psm1" + Import-Module -Scope Local "$PSScriptRoot/Select-DependencyBranches.mocks.psm1" Import-Module -Scope Local "$PSScriptRoot/../query-state.mocks.psm1" } -Describe 'Select-UpstreamBranches' { +Describe 'Select-DependencyBranches' { BeforeEach { Register-Framework } - It 'finds upstream branches from git and does not include remote by default' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' - Initialize-UpstreamBranches @{ + It 'finds dependency branches from git and does not include remote by default' { + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' + Initialize-DependencyBranches @{ 'my-branch' = @("feature/FOO-123", "feature/XYZ-1-services") } - $results = Select-UpstreamBranches my-branch + $results = Select-DependencyBranches my-branch $results | Should -Be @( 'feature/FOO-123', 'feature/XYZ-1-services' ) } - It 'finds upstream branches from git and includes remote when requested' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' - Initialize-UpstreamBranches @{ + It 'finds dependency branches from git and includes remote when requested' { + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' + Initialize-DependencyBranches @{ 'my-branch' = @("feature/FOO-123", "feature/XYZ-1-services") } - $results = Select-UpstreamBranches my-branch -includeRemote + $results = Select-DependencyBranches my-branch -includeRemote $results | Should -Be @( 'origin/feature/FOO-123', 'origin/feature/XYZ-1-services' ) } - It 'finds upstream branches from git (when there is one) and includes remote when requested' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' - Initialize-UpstreamBranches @{ + It 'finds dependency branches from git (when there is one) and includes remote when requested' { + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' + Initialize-DependencyBranches @{ 'my-branch' = @("feature/FOO-123") } - $results = Select-UpstreamBranches my-branch -includeRemote + $results = Select-DependencyBranches my-branch -includeRemote $results | Should -Be @( 'origin/feature/FOO-123' ) } It 'allows some to be excluded' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' - Initialize-UpstreamBranches @{ + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' + Initialize-DependencyBranches @{ 'rc/1.1.0' = @("feature/FOO-123", "line/1.0") } - $results = Select-UpstreamBranches rc/1.1.0 -includeRemote -exclude @('line/1.0') + $results = Select-DependencyBranches rc/1.1.0 -includeRemote -exclude @('line/1.0') $results | Should -Be @( 'origin/feature/FOO-123' ) } It 'allows some to be excluded even through ancestors' { - Initialize-ToolConfiguration -upstreamBranchName 'my-upstream' - Initialize-UpstreamBranches @{ + Initialize-ToolConfiguration -dependencyBranchName 'my-dependency' + Initialize-DependencyBranches @{ 'rc/1.1.0' = @("feature/FOO-123", "feature/XYZ-1-services") 'feature/FOO-123' = @("line/1.0") 'feature/XYZ-1-services' = @("line/1.0", "infra/some-service") 'infra/some-service' = @("line/1.0") } - $results = Select-UpstreamBranches rc/1.1.0 -includeRemote -recurse -exclude @('line/1.0') + $results = Select-DependencyBranches rc/1.1.0 -includeRemote -recurse -exclude @('line/1.0') $results | Should -Be @( 'origin/feature/FOO-123', 'origin/feature/XYZ-1-services', 'origin/infra/some-service' ) } It 'handles (invalid) recursiveness without failing' { Initialize-ToolConfiguration - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'bad-recursive-branch-1' = @('bad-recursive-branch-2') 'bad-recursive-branch-2' = @('bad-recursive-branch-1') } - $results = Select-UpstreamBranches bad-recursive-branch-1 -recurse + $results = Select-DependencyBranches bad-recursive-branch-1 -recurse $results | Should -Be @( 'bad-recursive-branch-2' ) } It 'allows overrides' { Initialize-ToolConfiguration - Initialize-UpstreamBranches @{ + Initialize-DependencyBranches @{ 'feature/FOO-123' = @("line/1.0") } - $results = Select-UpstreamBranches 'feature/FOO-123' -overrideUpstreams @{ 'feature/FOO-123' = @('infra/next') } + $results = Select-DependencyBranches 'feature/FOO-123' -overrideDependencies @{ 'feature/FOO-123' = @('infra/next') } $results | Should -Be @( 'infra/next' ) } } diff --git a/utils/query-state/Select-UpstreamBranches.mocks.psm1 b/utils/query-state/Select-UpstreamBranches.mocks.psm1 deleted file mode 100644 index 5439cf8..0000000 --- a/utils/query-state/Select-UpstreamBranches.mocks.psm1 +++ /dev/null @@ -1,8 +0,0 @@ -Import-Module -Scope Local "$PSScriptRoot/Get-UpstreamBranch.psm1" -Import-Module -Scope Local "$PSScriptRoot/Get-GitFile.mocks.psm1" -Import-Module -Scope Local "$PSScriptRoot/Select-AllUpstreamBranches.mocks.psm1" - -function Initialize-UpstreamBranches([PSObject] $upstreamConfiguration) { - Initialize-AllUpstreamBranches $upstreamConfiguration -} -Export-ModuleMember -Function Initialize-UpstreamBranches diff --git a/utils/scripting/ConvertFrom-ParameterizedArray.tests.ps1 b/utils/scripting/ConvertFrom-ParameterizedArray.tests.ps1 index 061ef04..315bcab 100644 --- a/utils/scripting/ConvertFrom-ParameterizedArray.tests.ps1 +++ b/utils/scripting/ConvertFrom-ParameterizedArray.tests.ps1 @@ -30,30 +30,30 @@ Describe 'ConvertFrom-ParameterizedArray' { It 'reports errors' { $params = @{ foo = @('bar', 'baz') } $variables = @{ config=@{}; params=$params; actions=@{} } - $result = ConvertFrom-ParameterizedArray @('foo', '$($config.upstreamBranch)') -variables $variables -convertFromParameterized ${function:ConvertFrom-ParameterizedString} + $result = ConvertFrom-ParameterizedArray @('foo', '$($config.dependencyBranch)') -variables $variables -convertFromParameterized ${function:ConvertFrom-ParameterizedString} $result.fail | Should -Be $true } It 'reports warnings if diagnostics are provided' { $params = @{ foo = @('bar', 'baz') } $variables = @{ config=@{}; params=$params; actions=@{} } - $result = ConvertFrom-ParameterizedArray @('foo', '$($config.upstreamBranch)') -variables $variables -diagnostics $diag -convertFromParameterized ${function:ConvertFrom-ParameterizedString} + $result = ConvertFrom-ParameterizedArray @('foo', '$($config.dependencyBranch)') -variables $variables -diagnostics $diag -convertFromParameterized ${function:ConvertFrom-ParameterizedString} $result.fail | Should -Be $true $output = Register-Diagnostics -throwInsteadOfExit { Assert-Diagnostics $diag } | Should -Not -Throw - $output | Should -Be @('WARN: Unable to evaluate script: ''$($config.upstreamBranch)''') + $output | Should -Be @('WARN: Unable to evaluate script: ''$($config.dependencyBranch)''') } It 'reports errors if diagnostics are provided and flagged to fail on error' { $params = @{ foo = @('bar', 'baz') } $variables = @{ config=@{}; params=$params; actions=@{} } - $result = ConvertFrom-ParameterizedArray @('foo', '$($config.upstreamBranch)') -variables $variables -diagnostics $diag -failOnError -convertFromParameterized ${function:ConvertFrom-ParameterizedString} + $result = ConvertFrom-ParameterizedArray @('foo', '$($config.dependencyBranch)') -variables $variables -diagnostics $diag -failOnError -convertFromParameterized ${function:ConvertFrom-ParameterizedString} $result.fail | Should -Be $true $output = Register-Diagnostics -throwInsteadOfExit { Assert-Diagnostics $diag } | Should -Throw - $output | Should -Be @('ERR: Unable to evaluate script: ''$($config.upstreamBranch)''') + $output | Should -Be @('ERR: Unable to evaluate script: ''$($config.dependencyBranch)''') } } diff --git a/utils/scripting/ConvertFrom-ParameterizedString.tests.ps1 b/utils/scripting/ConvertFrom-ParameterizedString.tests.ps1 index a448787..7a9079e 100644 --- a/utils/scripting/ConvertFrom-ParameterizedString.tests.ps1 +++ b/utils/scripting/ConvertFrom-ParameterizedString.tests.ps1 @@ -37,29 +37,29 @@ Describe 'ConvertFrom-ParameterizedString' { } It 'returns null if an error occurs' { - $result = ConvertFrom-ParameterizedString -script '$($config.upstreamBranch)' -variables @{ config=@{}; params=@{}; actions=@{} } + $result = ConvertFrom-ParameterizedString -script '$($config.dependencyBranch)' -variables @{ config=@{}; params=@{}; actions=@{} } $result.result | Should -Be $null $result.fail | Should -Be $true } It 'reports warnings if diagnostics are provided' { - $result = ConvertFrom-ParameterizedString -script '$($config.upstreamBranch)' -variables @{ config=@{}; params=@{}; actions=@{} } -diagnostics $diag + $result = ConvertFrom-ParameterizedString -script '$($config.dependencyBranch)' -variables @{ config=@{}; params=@{}; actions=@{} } -diagnostics $diag $result.result | Should -Be $null $result.fail | Should -Be $true $output = Register-Diagnostics -throwInsteadOfExit { Assert-Diagnostics $diag } | Should -Not -Throw - $output | Should -Be @('WARN: Unable to evaluate script: ''$($config.upstreamBranch)''') + $output | Should -Be @('WARN: Unable to evaluate script: ''$($config.dependencyBranch)''') } It 'reports errors if diagnostics are provided and flagged to fail on error' { - $result = ConvertFrom-ParameterizedString -script '$($config.upstreamBranch)' -variables @{ config=@{}; params=@{}; actions=@{} } -diagnostics $diag -failOnError + $result = ConvertFrom-ParameterizedString -script '$($config.dependencyBranch)' -variables @{ config=@{}; params=@{}; actions=@{} } -diagnostics $diag -failOnError $result.result | Should -Be $null $result.fail | Should -Be $true $output = Register-Diagnostics -throwInsteadOfExit { Assert-Diagnostics $diag } | Should -Throw - $output | Should -Be @('ERR: Unable to evaluate script: ''$($config.upstreamBranch)''') + $output | Should -Be @('ERR: Unable to evaluate script: ''$($config.dependencyBranch)''') } }