Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Support --targetBranch for Azure Devops Server/TFS for remote repos…
Browse files Browse the repository at this point in the history
…itories (#1008)

* chore: Improve targetBranch's description

* test: Verify targetBranch is used for remote tfs

Add test to verify that when a custom value is provided to the
`--targetBranch` option, the `TfsSettingsReader` properly populates the
`RemoteInfo.BranchName` property in case of a remote URI for the
repository.

* feat(tfs): Support targetBranch for remote URIs

Currently the `repository` command does not make use of the custom value
provided through the `--targetBranch` option when the URI points to a
remote repository, not a local one.

This was the case because the `TfsSettingsReader` did not make use of
the value in case of a remote URI.

This commit simply instantiates a new `RemoteInfo` with `BranchName` set
to the provided value in case of a remote URI.

* docs: Add ADServer/TFS as supporting targetBranch
  • Loading branch information
CrispyDrone committed Nov 21, 2020
1 parent b355582 commit 317d457
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions NuKeeper.AzureDevOps/TfsSettingsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override async Task<RepositorySettings> RepositorySettings(Uri repository

var settings = repositoryUri.IsFile
? await CreateSettingsFromLocal(repositoryUri, targetBranch)
: CreateSettingsFromRemote(repositoryUri);
: CreateSettingsFromRemote(repositoryUri, targetBranch);
if (settings == null)
{
throw new NuKeeperException($"The provided uri was is not in the correct format. Provided {repositoryUri.ToString()} and format should be {UrlPattern}");
Expand All @@ -64,9 +64,9 @@ public override async Task<RepositorySettings> RepositorySettings(Uri repository
return settings;
}

private static RepositorySettings CreateSettingsFromRemote(Uri repositoryUri)
private static RepositorySettings CreateSettingsFromRemote(Uri repositoryUri, string targetBranch)
{
return RepositorySettings(repositoryUri);
return RepositorySettings(repositoryUri, new RemoteInfo { BranchName = targetBranch });
}

private async Task<RepositorySettings> CreateSettingsFromLocal(Uri repositoryUri, string targetBranch)
Expand Down
2 changes: 1 addition & 1 deletion NuKeeper/Commands/RepositoryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RepositoryCommand(ICollaborationEngine engine, IConfigureLogger logger, I
public string RepositoryUri { get; set; }

[Option(CommandOptionType.SingleValue, LongName = "targetBranch",
Description = "If the target branch is another branch than that you are currently on, set this to the target")]
Description = "Use another target branch than the currently active HEAD branch of the remote or local repository")]
public string TargetBranch { get; set; }

[Option(CommandOptionType.SingleValue, ShortName = "cdir", Description = "If you want NuKeeper to check out the repository to an alternate path, set it here (by default, a temporary directory is used).")]
Expand Down
10 changes: 10 additions & 0 deletions Nukeeper.AzureDevOps.Tests/TfsSettingsReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,15 @@ public async Task RepositorySettings_HandlesSpaces()
Assert.AreEqual("project name", settings.RepositoryOwner);
}

[Test]
public async Task RepositorySettings_WithRemoteUrlAndTargetBranch_ReturnsRemoteInfoWithSpecifiedBranchName()
{
var uri = new Uri("https://internalserver/tfs/project%20name/_git/repo%20name");
var targetBranch = "myTargetBranch";

var settings = await _azureSettingsReader.RepositorySettings(uri, targetBranch);

Assert.AreEqual("myTargetBranch", settings.RemoteInfo.BranchName);
}
}
}
2 changes: 1 addition & 1 deletion site/content/commands/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This is only available for azure devops and vsts
### Using a targetBranch

{{% notice info %}}
This is only available for azure devops, vsts and github right now
This is only available for azure devops, azure devops server, vsts, tfs, and github right now
{{% /notice %}}

In some cases you want NuKeeper not to run on the default branch but on a specific (feature-)branch
Expand Down

0 comments on commit 317d457

Please sign in to comment.