-
Notifications
You must be signed in to change notification settings - Fork 652
Improved support for dynamic repositories #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
namespace GitVersion | ||
{ | ||
using System; | ||
|
||
static partial class ExtensionMethods | ||
{ | ||
public static string GetCanonicalBranchName(this string branchName) | ||
{ | ||
if (branchName.IsPullRequest()) | ||
{ | ||
branchName = branchName.Replace("pull-requests", "pull"); | ||
branchName = branchName.Replace("pr", "pull"); | ||
|
||
return string.Format("refs/{0}/head", branchName); | ||
} | ||
|
||
return string.Format("refs/heads/{0}", branchName); | ||
} | ||
|
||
public static bool IsHotfix(this string branchName) | ||
{ | ||
return branchName.StartsWith("hotfix-") || branchName.StartsWith("hotfix/"); | ||
} | ||
|
||
public static string GetHotfixSuffix(this string branchName) | ||
{ | ||
return branchName.TrimStart("hotfix-").TrimStart("hotfix/"); | ||
} | ||
|
||
public static bool IsRelease(this string branchName) | ||
{ | ||
return branchName.StartsWith("release-") || branchName.StartsWith("release/"); | ||
} | ||
|
||
public static string GetReleaseSuffix(this string branchName) | ||
{ | ||
return branchName.TrimStart("release-").TrimStart("release/"); | ||
} | ||
|
||
public static string GetUnknownBranchSuffix(this string branchName) | ||
{ | ||
var unknownBranchSuffix = branchName.Split('-', '/'); | ||
if (unknownBranchSuffix.Length == 1) | ||
return branchName; | ||
return unknownBranchSuffix[1]; | ||
} | ||
|
||
public static string GetSuffix(this string branchName, BranchType branchType) | ||
{ | ||
switch (branchType) | ||
{ | ||
case BranchType.Hotfix: | ||
return branchName.GetHotfixSuffix(); | ||
|
||
case BranchType.Release: | ||
return branchName.GetReleaseSuffix(); | ||
|
||
case BranchType.Unknown: | ||
return branchName.GetUnknownBranchSuffix(); | ||
|
||
default: | ||
throw new NotSupportedException(string.Format("Unexpected branch type {0}.", branchType)); | ||
} | ||
} | ||
|
||
public static bool IsDevelop(this string branchName) | ||
{ | ||
return branchName == "develop"; | ||
} | ||
|
||
public static bool IsMaster(this string branchName) | ||
{ | ||
return branchName == "master"; | ||
} | ||
|
||
public static bool IsPullRequest(this string branchName) | ||
{ | ||
return branchName.Contains("pull/") || branchName.Contains("pull-requests/") || branchName.Contains("pr/"); | ||
} | ||
|
||
public static bool IsSupport(this string branchName) | ||
{ | ||
return branchName.ToLower().StartsWith("support-"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
namespace GitVersionExe.Tests | ||
{ | ||
using System.IO; | ||
using GitVersion; | ||
using LibGit2Sharp; | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class GitPreparerTests | ||
{ | ||
public GitPreparerTests() | ||
{ | ||
Logger.WriteInfo = s => { }; | ||
Logger.WriteWarning = s => { }; | ||
Logger.WriteError = s => { }; | ||
} | ||
|
||
const string RemoteRepositoryUrl = "https://github.com/ParticularLabs/GitVersion.git"; | ||
const string DefaultBranchName = "master"; | ||
const string SpecificBranchName = "gh-pages"; | ||
|
||
[Explicit] | ||
[TestCase(null, DefaultBranchName)] | ||
[TestCase(SpecificBranchName, SpecificBranchName)] | ||
public void WorksCorrectlyWithRemoteRepository(string branchName, string expectedBranchName) | ||
{ | ||
var tempDir = Path.GetTempPath(); | ||
|
||
var arguments = new Arguments | ||
{ | ||
TargetPath = tempDir, | ||
TargetUrl = RemoteRepositoryUrl | ||
}; | ||
|
||
if (!string.IsNullOrWhiteSpace(branchName)) | ||
{ | ||
arguments.TargetBranch = branchName; | ||
} | ||
|
||
var gitPreparer = new GitPreparer(arguments); | ||
var dynamicRepositoryPath = gitPreparer.Prepare(); | ||
|
||
Assert.AreEqual(Path.Combine(tempDir, "_dynamicrepository", ".git"), dynamicRepositoryPath); | ||
Assert.IsTrue(gitPreparer.IsDynamicGitRepository); | ||
|
||
using (var repository = new Repository(dynamicRepositoryPath)) | ||
{ | ||
var currentBranch = repository.Head.CanonicalName; | ||
|
||
Assert.IsTrue(currentBranch.EndsWith(expectedBranchName)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void WorksCorrectlyWithLocalRepository() | ||
{ | ||
var tempDir = Path.GetTempPath(); | ||
|
||
var arguments = new Arguments | ||
{ | ||
TargetPath = tempDir | ||
}; | ||
|
||
var gitPreparer = new GitPreparer(arguments); | ||
var dynamicRepositoryPath = gitPreparer.Prepare(); | ||
|
||
Assert.AreEqual(null, dynamicRepositoryPath); | ||
Assert.IsFalse(gitPreparer.IsDynamicGitRepository); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the MergeMessageRegexPattern you should be able to use something like this