diff --git a/NextVersion.txt b/NextVersion.txt new file mode 100644 index 0000000..359a5b9 --- /dev/null +++ b/NextVersion.txt @@ -0,0 +1 @@ +2.0.0 \ No newline at end of file diff --git a/README.md b/README.md index ee71ace..a2461ff 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,59 @@ -GitHubLink +GitLink ========== -![GitHubLink](design/logo/logo_64.png) +![GitLink](design/logo/logo_64.png) -GitHubLink let's users step through your code hosted on GitHub! **Help making .NET open source projects more accessible by enabling this for your .NET projects, it's just a single additional step in your build**. See the list of [projects using GitHubLink](#ProjectsUsingGitHubLink). +GitLink let's users step through your code hosted on GitHub! **Help make .NET open source projects more accessible by enabling this for your .NET projects, it's just a single additional step in your build**. See the list of [projects using GitLink](#projects-using-gitlink). -GitHubLink makes symbol servers obsolete which saves you both time with uploading source files with symbols and the user no longer has to specify custom symbol servers (such as symbolsource.org). +-- -![Stepping through external source code](doc/images/GitHubLink_example.gif) +**Important note** +*GitLink* was formerly named *GitHubLink*. By adding support to more Git hosting services the name seemed not covering the whole package. Note that the old GitHubLink packages on NuGet and Chocolatey will no long be updated / maintained. -This application is based on the SourceLink project. SourceLink requires FAKE to run and not everyone likes to write code in F#. GitHubLink is a wrapper around SourceLink specifically written to be easily used from any build system (locally or a build server) and in any .NET language. It also provides new features such as standard integration with GitHub and the possibility to use remote repositories. GitHubLink is available as console application and can be referenced as assembly to be used in other .NET assemblies. +-- -The advantage of GitHubLink is that it is fully customized for GitHub. It also works with GitHub urls so it **does not require a local git repository to work**. This makes it perfectly usable in continuous integration servers such as Continua CI. +GitLink makes symbol servers obsolete which saves you both time with uploading source files with symbols and the user no longer has to specify custom symbol servers (such as symbolsource.org). + +![Stepping through external source code](doc/images/GitLink_example.gif) + + +This application is based on the SourceLink project. SourceLink requires FAKE to run and not everyone likes to write code in F#. GitLink is a wrapper around SourceLink specifically written to be easily used from any build system (locally or a build server) and in any .NET language. It also provides new features such as standard integration with GitHub and BitBucket and the possibility to use remote repositories. GitLink is available as console application and can be referenced as assembly to be used in other .NET assemblies. + +The advantage of GitLink is that it is fully customized for Git. It also works with GitHub or BitBucket urls so it **does not require a local git repository to work**. This makes it perfectly usable in continuous integration servers such as Continua CI. Updating all the pdb files is very fast. A solution with over 85 projects will be handled in less than 30 seconds. -When using GitHubLink, the user no longer has to specify symbol servers. He/she only has to enable the support for source servers in Visual Studio as shown in the image below: +When using GitLink, the user no longer has to specify symbol servers. He/she only has to enable the support for source servers in Visual Studio as shown in the image below: ![Enabling source server support](doc/images/visualstudio_enablesourceserversupport.png) -# Using GitHubLink as command line tool # +**Note that Visual Studio 2012 needs to run elevated in order to download the source server files due to a bug in Visual Studio 2012.** + +# Supported git providers + +GitLink supports the following providers out of the box (will auto-detect based on the url): -Using GitHubLink via the command line is very simple: +* BitBucket +* GitHub + +Providers currently being worked on: + +* Assembla +* Beanstalk +* CloudForge +* Codebase +* FogCreek +* Planio +* ProjectLocker +* RhodeCode +* Unfuddle + +It is also possible to specify a custom url provider. + +# Using GitLink as command line tool # + +Using GitLink via the command line is very simple: 1. Build the software (in release mode with pdb files enabled) 2. Run the console application with the right command line parameters @@ -31,53 +62,57 @@ Below are a few examples. ## Running for the default branch ## - GitHubLink.exe c:\source\catel -u https://github.com/catel/catel + GitLink.exe c:\source\catel -u https://github.com/catel/catel This will use the default branch (which is in most cases **master**). You can find out the default branch by checking what branch is loaded by default on the GitHub page. ## Running for a specific branch ## - GitHubLink.exe c:\source\catel -u https://github.com/catel/catel -b develop + GitLink.exe c:\source\catel -u https://github.com/catel/catel -b develop This will use the develop branch. ## Running for a specific branch and configuration ## - GitHubLink.exe c:\source\catel -u https://github.com/catel/catel -b develop -c debug + GitLink.exe c:\source\catel -u https://github.com/catel/catel -b develop -c debug This will use the develop branch and the debug configuration. ## Getting help ## -When you need help about GitHubLink, use the following command line: +When you need help about GitLink, use the following command line: - GitHubLink.exe -help + GitLink.exe -help ## Logging to a file ## When you need to log the information to a file, use the following command line: - GitHubLink.exe c:\source\catel -u https://github.com/catel/catel -b develop -l GitHubLinkLog.log + GitLink.exe c:\source\catel -u https://github.com/catel/catel -b develop -l GitLinkLog.log -# Using GitHubLink in code # +# Using GitLink in code # -GitHubLink is built with 2 usages in mind: command line and code reference. Though most people will use the command line version, it is possible to reference the executable and use the logic in code. +GitLink is built with 2 usages in mind: command line and code reference. Though most people will use the command line version, it is possible to reference the executable and use the logic in code. The command line implementation uses the same available API. ## Creating a context ## -To link files to a GitHub project, a context must be created. The command line version does this by using the *ArgumentParser* class. It is also possible to create a context from scratch as shown in the example below: +To link files to a Git project, a context must be created. The command line version does this by using the *ArgumentParser* class. It is also possible to create a context from scratch as shown in the example below: - var context = new GitHubLink.Context(); - context.SolutionDirectory = @"c:\source\catel"; - context.TargetUrl = "https://github.com/catel/catel"; - context.TargetBranch = "develop"; +```csharp +var context = new GitLink.Context(); +context.SolutionDirectory = @"c:\source\catel"; +context.TargetUrl = "https://github.com/catel/catel"; +context.TargetBranch = "develop"; +``` It is possible to create a context based on command line arguments: - var context = ArgumentParser.Parse(@"c:\source\catel -u https://github.com/catel/catel -b develop"); +```csharp +var context = ArgumentParser.Parse(@"c:\source\catel -u https://github.com/catel/catel -b develop"); +``` ## Linking a context ## @@ -85,25 +120,25 @@ Once a context is created, the *Linker* class can be used to actually link the f Linker.Link(context); -# How to get GitHubLink # +# How to get GitLink # -There are three general ways to get GitHubLink:. +There are three general ways to get GitLink:. ## Get it from GitHub ## -The releases will be available as separate executable download on the [releases tab](https://github.com/GeertvanHorrik/GitHubLink/releases) of the project. +The releases will be available as separate executable download on the [releases tab](https://github.com/CatenaLogic/GitLink/releases) of the project. ## Get it via Chocolatey ## If you want to install the tool on your (build) computer, the package is available via Chocolatey. To install, use the following command: - cinst GitHubLink + choco install GitLink ## Get it via NuGet ## If you want to reference the assembly to use it in code, the recommended way to get it is via NuGet. -**Note that getting GitHubLink via NuGet will add it as a reference to the project** +**Note that getting GitLink via NuGet will add it as a reference to the project** # How does it work # @@ -111,23 +146,30 @@ The SrcSrv tool (Srcsrv.dll) enables a client to retrieve the exact version of t For more information, see the official documentation of SrcSrv. -GitHubLink creates a source index file and updates the PDB file so it will retrieve the files from the GitHub file handler. +GitLink creates a source index file and updates the PDB file so it will retrieve the files from the Git host file handler. - -# Projects using GitHubLink # + +# Projects using GitLink # -Below is a list of projects already using GitHubLink (alphabetically ordered). +Below is a list of projects already using GitLink (alphabetically ordered). - Catel - eXpand -- GitHubLink -- Orchestra - -Are you using GitHubLink in your projects? Let us know and we will add your project to the list. +- GitLink +- Orc.CsvHelper +- Orc.FilterBuilder +- Orc.ProjectManagement +- Orc.Sort +- Orchestra +- Romantic Web +- xUnit.net +- xUnit.net Visual Studio Runner + +Are you using GitLink in your projects? Let us know and we will add your project to the list. *Note that you can also create a pull request on this document and add it yourself.* # Icon # -Link by Dominic Whittle from The Noun Project \ No newline at end of file +Link by Dominic Whittle from The Noun Project diff --git a/deployment/Chocolatey/template/GitHubLink.nuspec b/deployment/Chocolatey/template/GitHubLink.nuspec deleted file mode 100644 index 1a820b5..0000000 --- a/deployment/Chocolatey/template/GitHubLink.nuspec +++ /dev/null @@ -1,24 +0,0 @@ - - - - githublink - [VERSION] - GitHubLink - GeertvanHorrik - - - GitHubLink let's users step through your code hosted on GitHub! This makes symbol servers obsolete which saves you both time - with uploading source files with symbols and the user no longer has to specify custom symbol servers (such as symbolsource.org). - - - - - - source symbol symbols server sourcelink github stepping debugging - - en-US - https://github.com/GeertvanHorrik/GitHubLink/ - https://github.com/GeertvanHorrik/GitHubLink/blob/develop/LICENSE - https://raw.githubusercontent.com/GeertvanHorrik/GitHubLink/develop/design/logo/logo_64.png - - \ No newline at end of file diff --git a/deployment/Chocolatey/template/GitHubLink/GitHubLink.nuspec b/deployment/Chocolatey/template/GitHubLink/GitHubLink.nuspec new file mode 100644 index 0000000..906a7cd --- /dev/null +++ b/deployment/Chocolatey/template/GitHubLink/GitHubLink.nuspec @@ -0,0 +1,27 @@ + + + + githublink + [VERSION] + GitHubLink + GeertvanHorrik + + + ** Note: this is a maintenance package, GitHubLink is replaced by GitLink ** + + + + + + source symbol symbols server sourcelink github bitbucket git stepping debugging + + en-US + https://github.com/CatenaLogic/GitLink/ + https://github.com/CatenaLogic/GitLink/blob/develop/LICENSE + https://raw.githubusercontent.com/CatenaLogic/GitLink/develop/design/logo/logo_64.png + + + + + + \ No newline at end of file diff --git a/deployment/Chocolatey/template/GitLink/GitLink.nuspec b/deployment/Chocolatey/template/GitLink/GitLink.nuspec new file mode 100644 index 0000000..1def9ce --- /dev/null +++ b/deployment/Chocolatey/template/GitLink/GitLink.nuspec @@ -0,0 +1,24 @@ + + + + gitlink + [VERSION] + GitLink + GeertvanHorrik + + + GitLink let's users step through your code hosted on any Git hosting service! This makes symbol servers obsolete which saves you both time + with uploading source files with symbols and the user no longer has to specify custom symbol servers (such as symbolsource.org). + + + + + + gitlink githublinksource symbol symbols server sourcelink github bitbucket git stepping debugging + + en-US + https://github.com/CatenaLogic/GitLink/ + https://github.com/CatenaLogic/GitLink/blob/develop/LICENSE + https://raw.githubusercontent.com/CatenaLogic/GitLink/develop/design/logo/logo_64.png + + \ No newline at end of file diff --git a/deployment/Chocolatey/template/GitLink/tools/chocolateyInstall.ps1 b/deployment/Chocolatey/template/GitLink/tools/chocolateyInstall.ps1 new file mode 100644 index 0000000..b0defc6 --- /dev/null +++ b/deployment/Chocolatey/template/GitLink/tools/chocolateyInstall.ps1 @@ -0,0 +1,2 @@ +Generate-BinFile "ghl" "$packageFolder\Tools\GitLink.exe" +Write-ChocolateySuccess "GitLink" \ No newline at end of file diff --git a/deployment/Chocolatey/template/GitLink/tools/chocolateyUninstall.ps1 b/deployment/Chocolatey/template/GitLink/tools/chocolateyUninstall.ps1 new file mode 100644 index 0000000..8850bbb --- /dev/null +++ b/deployment/Chocolatey/template/GitLink/tools/chocolateyUninstall.ps1 @@ -0,0 +1,3 @@ +Remove-BinFile "gl" "$packageFolder\Tools\GitLink.exe" +Remove-BinFile "GitLink" "$packageFolder\Tools\GitLink.exe" +Write-ChocolateySuccess "GitLink" \ No newline at end of file diff --git a/deployment/Chocolatey/template/tools/chocolateyInstall.ps1 b/deployment/Chocolatey/template/tools/chocolateyInstall.ps1 deleted file mode 100644 index 59909b5..0000000 --- a/deployment/Chocolatey/template/tools/chocolateyInstall.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -Generate-BinFile "ghl" "$packageFolder\Tools\GitHubLink.exe" -Write-ChocolateySuccess "GitHubLink" \ No newline at end of file diff --git a/deployment/Chocolatey/template/tools/chocolateyUninstall.ps1 b/deployment/Chocolatey/template/tools/chocolateyUninstall.ps1 deleted file mode 100644 index 1becdf7..0000000 --- a/deployment/Chocolatey/template/tools/chocolateyUninstall.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -Remove-BinFile "ghl" "$packageFolder\Tools\GitHubLink.exe" -Remove-BinFile "GitHubLink" "$packageFolder\Tools\GitHubLink.exe" -Write-ChocolateySuccess "GitHubLink" \ No newline at end of file diff --git a/deployment/FinalBuilder/GitHubLink.CreatePackages.fbp7 b/deployment/FinalBuilder/GitLink.CreatePackages.fbp7 similarity index 74% rename from deployment/FinalBuilder/GitHubLink.CreatePackages.fbp7 rename to deployment/FinalBuilder/GitLink.CreatePackages.fbp7 index 279bf03..26d6cb3 100644 Binary files a/deployment/FinalBuilder/GitHubLink.CreatePackages.fbp7 and b/deployment/FinalBuilder/GitLink.CreatePackages.fbp7 differ diff --git a/deployment/NuGet/template/GitHubLink.nuspec b/deployment/NuGet/template/GitHubLink.nuspec deleted file mode 100644 index 1a820b5..0000000 --- a/deployment/NuGet/template/GitHubLink.nuspec +++ /dev/null @@ -1,24 +0,0 @@ - - - - githublink - [VERSION] - GitHubLink - GeertvanHorrik - - - GitHubLink let's users step through your code hosted on GitHub! This makes symbol servers obsolete which saves you both time - with uploading source files with symbols and the user no longer has to specify custom symbol servers (such as symbolsource.org). - - - - - - source symbol symbols server sourcelink github stepping debugging - - en-US - https://github.com/GeertvanHorrik/GitHubLink/ - https://github.com/GeertvanHorrik/GitHubLink/blob/develop/LICENSE - https://raw.githubusercontent.com/GeertvanHorrik/GitHubLink/develop/design/logo/logo_64.png - - \ No newline at end of file diff --git a/deployment/NuGet/template/GitHubLink/GitHubLink.nuspec b/deployment/NuGet/template/GitHubLink/GitHubLink.nuspec new file mode 100644 index 0000000..5d1ff8e --- /dev/null +++ b/deployment/NuGet/template/GitHubLink/GitHubLink.nuspec @@ -0,0 +1,27 @@ + + + + githublink + [VERSION] + GitHubLink + GeertvanHorrik + + + ** Note: this is a maintenance package, GitHubLink is replaced by GitLink ** + + + + + + source symbol symbols server sourcelink github bitbucket git stepping debugging + + en-US + https://github.com/CatenaLogic/GitLink/ + https://github.com/CatenaLogic/GitLink/blob/develop/LICENSE + https://raw.githubusercontent.com/CatenaLogic/GitLink/develop/design/logo/logo_64.png + + + + + + \ No newline at end of file diff --git a/deployment/NuGet/template/GitLink/GitLink.nuspec b/deployment/NuGet/template/GitLink/GitLink.nuspec new file mode 100644 index 0000000..f232d93 --- /dev/null +++ b/deployment/NuGet/template/GitLink/GitLink.nuspec @@ -0,0 +1,24 @@ + + + + gitlink + [VERSION] + GitLink + GeertvanHorrik + + + GitLink let's users step through your code hosted on any Git hosting service! This makes symbol servers obsolete which saves you both time + with uploading source files with symbols and the user no longer has to specify custom symbol servers (such as symbolsource.org). + + + + + + gitlink githublink source symbol symbols server sourcelink github bitbucket git stepping debugging + + en-US + https://github.com/CatenaLogic/GitLink/ + https://github.com/CatenaLogic/GitLink/blob/develop/LICENSE + https://raw.githubusercontent.com/CatenaLogic/GitLink/develop/design/logo/logo_64.png + + \ No newline at end of file diff --git a/doc/Integration tests.md b/doc/Integration tests.md new file mode 100644 index 0000000..cd3831b --- /dev/null +++ b/doc/Integration tests.md @@ -0,0 +1,19 @@ +# Setting up the solution for integration tests + +GitLink has integration tests for multiple repositories. It uses NUnit and decorates the integration tests with the *Explicit* attribute to prevent it running in a CI build. + +## Cloning the test repositories + +GitLink uses the following remote repositories to test whether it works with actual repositories. + +* https://bitbucket.org/CatenaLogic/GitLinkTestRepro +* https://github.com/CatenaLogic/GitLinkTestRepro + +Below is a table with the expected remote repositories and the expected locations on disk: + +* BitBucket => C:\Source\GitLinkTestRepro_BitBucket +* GitHub => C:\Source\GitLinkTestRepro_GitHub + +## Running the explicit integration tests + +It is required to explicitly run the integration tests that should work now. \ No newline at end of file diff --git a/doc/history.txt b/doc/history.txt index 281ecf4..f4afdcc 100644 --- a/doc/history.txt +++ b/doc/history.txt @@ -1,5 +1,5 @@ -GitHubLink history -================== +GitLink history +=============== (+) Added (*) Changed @@ -8,7 +8,7 @@ GitHubLink history For more information about issues or new feature requests, please visit: -Project website: https://github.com/GeertvanHorrik/GitHubLink +Project website: https://github.com/CatenaLogic/GitLink/ ********************************************************** diff --git a/doc/images/GitHubLink_example.gif b/doc/images/GitLink_example.gif similarity index 100% rename from doc/images/GitHubLink_example.gif rename to doc/images/GitLink_example.gif diff --git a/lib/repositories.config b/lib/repositories.config index 7a2ef9b..cd1a1b1 100644 --- a/lib/repositories.config +++ b/lib/repositories.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file diff --git a/src/GitHubLink.Test/Extensions/StringExtensionsFacts.github.cs b/src/GitHubLink.Test/Extensions/StringExtensionsFacts.github.cs deleted file mode 100644 index 3098d38..0000000 --- a/src/GitHubLink.Test/Extensions/StringExtensionsFacts.github.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - - -namespace GitHubLink.Test.Extensions -{ - using Microsoft.VisualStudio.TestTools.UnitTesting; - - public class StringExtensionsFacts - { - [TestClass] - public class TheGetGitHubCompanyNameMethod - { - [TestMethod] - public void ReturnsValidCompany() - { - var company = StringExtensions.GetGitHubCompanyName("https://github.com/GeertvanHorrik/GitHubLink"); - - Assert.AreEqual("GeertvanHorrik", company); - } - } - - [TestClass] - public class TheGetGitHubCompanyUrlMethod - { - [TestMethod] - public void ReturnsValidUrl() - { - var company = StringExtensions.GetGitHubCompanyUrl("https://github.com/GeertvanHorrik/GitHubLink"); - - Assert.AreEqual("https://github.com/GeertvanHorrik", company); - } - } - - [TestClass] - public class TheGetGitHubProjectNameMethod - { - [TestMethod] - public void ReturnsValidProject() - { - var project = StringExtensions.GetGitHubProjectName("https://github.com/GeertvanHorrik/GitHubLink"); - - Assert.AreEqual("GitHubLink", project); - } - } - - [TestClass] - public class TheGetGitHubProjectUrlMethod - { - [TestMethod] - public void ReturnsValidUrl() - { - var company = StringExtensions.GetGitHubProjectUrl("https://github.com/GeertvanHorrik/GitHubLink"); - - Assert.AreEqual("https://github.com/GeertvanHorrik/GitHubLink", company); - } - - [TestMethod] - public void ReturnsValidUrlWhenGitIsAppended() - { - var company = StringExtensions.GetGitHubProjectUrl("https://github.com/GeertvanHorrik/GitHubLink.git"); - - Assert.AreEqual("https://github.com/GeertvanHorrik/GitHubLink", company); - } - } - - [TestClass] - public class TheGetGitHubRawUrlMethod - { - [TestMethod] - public void ReturnsValidUrl() - { - var company = StringExtensions.GetGitHubRawUrl("https://github.com/GeertvanHorrik/GitHubLink"); - - Assert.AreEqual("https://raw.github.com/GeertvanHorrik/GitHubLink", company); - } - } - } -} \ No newline at end of file diff --git a/src/GitHubLink.Test/packages.config b/src/GitHubLink.Test/packages.config deleted file mode 100644 index e098751..0000000 --- a/src/GitHubLink.Test/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/GitHubLink/Context.cs b/src/GitHubLink/Context.cs deleted file mode 100644 index cc8c4c6..0000000 --- a/src/GitHubLink/Context.cs +++ /dev/null @@ -1,63 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - - -namespace GitHubLink -{ - using System; - using System.IO; - using Catel.Logging; - - public class Context - { - private static readonly ILog Log = LogManager.GetCurrentClassLogger(); - - private readonly Lazy _tempDirectory = new Lazy(() => - { - var tempDirectory = Path.Combine(Path.GetTempPath(), "SourceLink", Guid.NewGuid().ToString()); - Directory.CreateDirectory(tempDirectory); - - return tempDirectory; - }); - - public Context() - { - ConfigurationName = "Release"; - } - - public bool IsHelp { get; set; } - public string LogFile { get; set; } - - public string SolutionDirectory { get; set; } - public string ConfigurationName { get; set; } - - public string TempDirectory - { - get { return _tempDirectory.Value; } - } - - public string TargetUrl { get; set; } - public string TargetBranch { get; set; } - - public void ValidateContext() - { - if (string.IsNullOrEmpty(SolutionDirectory)) - { - Log.ErrorAndThrowException("Solution directory is missing"); - } - - if (string.IsNullOrEmpty(ConfigurationName)) - { - Log.ErrorAndThrowException("Configuration name is missing"); - } - - if (string.IsNullOrEmpty(TargetUrl)) - { - Log.ErrorAndThrowException("Target url is missing"); - } - } - } -} \ No newline at end of file diff --git a/src/GitHubLink/Extensions/StringExtensions.git.cs b/src/GitHubLink/Extensions/StringExtensions.git.cs deleted file mode 100644 index 9d5f16b..0000000 --- a/src/GitHubLink/Extensions/StringExtensions.git.cs +++ /dev/null @@ -1,27 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - - -namespace GitHubLink -{ - using System.Linq; - using Catel; - using LibGit2Sharp; - - public static partial class StringExtensions - { - public static string GetLatestCommitShaOfCurrentBranch(this string repositoryDirectory) - { - Argument.IsNotNull(() => repositoryDirectory); - - using (var repository = new Repository(repositoryDirectory)) - { - var lastCommit = repository.Commits.First(); - return lastCommit.Sha; - } - } - } -} \ No newline at end of file diff --git a/src/GitHubLink/Extensions/StringExtensions.github.cs b/src/GitHubLink/Extensions/StringExtensions.github.cs deleted file mode 100644 index 2ea9abf..0000000 --- a/src/GitHubLink/Extensions/StringExtensions.github.cs +++ /dev/null @@ -1,78 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - - -namespace GitHubLink -{ - using System; - using Catel; - - public static partial class StringExtensions - { - public static string GetGitHubCompanyName(this string url) - { - Argument.IsNotNullOrWhitespace(() => url); - - url = url.Replace(GitHubLinkEnvironment.GitHubUrl, string.Empty); - var splittedUrl = url.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - if (splittedUrl.Length != 2) - { - return null; - } - - return splittedUrl[0]; - } - - public static string GetGitHubProjectName(this string url) - { - Argument.IsNotNullOrWhitespace(() => url); - - url = url.Replace(GitHubLinkEnvironment.GitHubUrl, string.Empty); - var splittedUrl = url.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - if (splittedUrl.Length != 2) - { - return null; - } - - var projectName = splittedUrl[1]; - if (projectName.EndsWith(".git")) - { - projectName = projectName.Substring(0, projectName.Length - ".git".Length); - } - - return projectName; - } - - public static string GetGitHubProjectUrl(this string url) - { - Argument.IsNotNullOrWhitespace(() => url); - - var companyUrl = GetGitHubCompanyUrl(url); - var project = GetGitHubProjectName(url); - - return string.Format("{0}/{1}", companyUrl, project); - } - - public static string GetGitHubCompanyUrl(this string url) - { - Argument.IsNotNullOrWhitespace(() => url); - - var company = GetGitHubCompanyName(url); - - return string.Format("{0}/{1}", GitHubLinkEnvironment.GitHubUrl, company); - } - - public static string GetGitHubRawUrl(this string url) - { - Argument.IsNotNullOrWhitespace(() => url); - - var company = GetGitHubCompanyName(url); - var project = GetGitHubProjectName(url); - - return string.Format("{0}/{1}/{2}", GitHubLinkEnvironment.GitHubRawUrl, company, project); - } - } -} \ No newline at end of file diff --git a/src/GitHubLink/Git/GitPreparer.cs b/src/GitHubLink/Git/GitPreparer.cs deleted file mode 100644 index df87c2a..0000000 --- a/src/GitHubLink/Git/GitPreparer.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - - -namespace GitHubLink.Git -{ - using System.IO; - using Catel; - using Catel.Logging; - using LibGit2Sharp; - - public class GitPreparer - { - private static readonly ILog Log = LogManager.GetCurrentClassLogger(); - - private readonly Context _context; - - public GitPreparer(Context context) - { - Argument.IsNotNull(() => context); - - _context = context; - } - - public string Prepare() - { - var gitPath = _context.TempDirectory; - - if (!string.IsNullOrWhiteSpace(_context.TargetUrl)) - { - gitPath = GetGitInfoFromUrl(); - } - - return GitDirFinder.TreeWalkForGitDir(gitPath); - } - - private string GetGitInfoFromUrl() - { - var gitDirectory = Path.Combine(_context.TempDirectory, ".git"); - if (Directory.Exists(gitDirectory)) - { - Log.Info("Deleting existing .git folder from '{0}' to force new checkout from url", gitDirectory); - - DeleteHelper.DeleteGitRepository(gitDirectory); - } - - Log.Info("Retrieving git info from url '{0}'", _context.TargetUrl); - - var cloneOptions = new CloneOptions - { - Checkout = false, - IsBare = true - }; - - Repository.Clone(_context.TargetUrl, gitDirectory, cloneOptions); - - if (!string.IsNullOrWhiteSpace(_context.TargetBranch)) - { - // Normalize (download branches) before using the branch - GitHelper.NormalizeGitDirectory(gitDirectory); - - using (var repository = new Repository(gitDirectory)) - { - var targetBranchName = string.Format("refs/heads/{0}", _context.TargetBranch); - if (!string.Equals(repository.Head.CanonicalName, targetBranchName)) - { - Log.Info("Switching to branch '{0}'", _context.TargetBranch); - - repository.Refs.UpdateTarget("HEAD", targetBranchName); - } - } - } - - return gitDirectory; - } - } -} \ No newline at end of file diff --git a/src/GitHubLink/Helpers/ProjectHelper.cs b/src/GitHubLink/Helpers/ProjectHelper.cs deleted file mode 100644 index dce8667..0000000 --- a/src/GitHubLink/Helpers/ProjectHelper.cs +++ /dev/null @@ -1,28 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. -// -// -------------------------------------------------------------------------------------------------------------------- - - -namespace GitHubLink -{ - using System.Collections.Generic; - using Catel; - using Microsoft.Build.Evaluation; - - public static class ProjectHelper - { - public static Project LoadProject(string projectName, string configurationName) - { - Argument.IsNotNullOrWhitespace(() => projectName); - Argument.IsNotNullOrWhitespace(() => configurationName); - - var collections = new Dictionary(); - collections["Configuration"] = configurationName; - - var project = new Project(projectName, collections, null); - return project; - } - } -} \ No newline at end of file diff --git a/src/GitHubLink/costura32/git2-06d772d.dll b/src/GitHubLink/costura32/git2-06d772d.dll deleted file mode 100644 index 1ceb3b2..0000000 Binary files a/src/GitHubLink/costura32/git2-06d772d.dll and /dev/null differ diff --git a/src/GitHubLink/costura64/git2-06d772d.dll b/src/GitHubLink/costura64/git2-06d772d.dll deleted file mode 100644 index 639b55e..0000000 Binary files a/src/GitHubLink/costura64/git2-06d772d.dll and /dev/null differ diff --git a/src/GitHubLink/packages.config b/src/GitHubLink/packages.config deleted file mode 100644 index 5124e42..0000000 --- a/src/GitHubLink/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/GitLink.Test/ApprovalTestsConfig.cs b/src/GitLink.Test/ApprovalTestsConfig.cs new file mode 100644 index 0000000..7967abb --- /dev/null +++ b/src/GitLink.Test/ApprovalTestsConfig.cs @@ -0,0 +1,10 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +using ApprovalTests.Reporters; + +[assembly: UseReporter(typeof(DiffReporter))] \ No newline at end of file diff --git a/src/GitHubLink.Test/ArgumentParserFacts.cs b/src/GitLink.Test/ArgumentParserFacts.cs similarity index 63% rename from src/GitHubLink.Test/ArgumentParserFacts.cs rename to src/GitLink.Test/ArgumentParserFacts.cs index 235b6a3..850a843 100644 --- a/src/GitHubLink.Test/ArgumentParserFacts.cs +++ b/src/GitLink.Test/ArgumentParserFacts.cs @@ -5,29 +5,29 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink.Test +namespace GitLink.Test { using Catel.Test; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using NUnit.Framework; - [TestClass] + [TestFixture] public class ArgumentParserFacts { - [TestMethod] + [TestCase] public void ThrowsExceptionForEmptyParameters() { - ExceptionTester.CallMethodAndExpectException(() => ArgumentParser.ParseArguments(string.Empty)); + ExceptionTester.CallMethodAndExpectException(() => ArgumentParser.ParseArguments(string.Empty)); } - [TestMethod] + [TestCase] public void CorrectlyParsesSolutionDirectory() { - var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/GeertvanHorrik/GitHubLink"); + var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/CatenaLogic/GitLink"); Assert.AreEqual("solutionDirectory", context.SolutionDirectory); } - [TestMethod] + [TestCase] public void CorrectlyParsesLogFilePath() { var context = ArgumentParser.ParseArguments("solutionDirectory -l logFilePath"); @@ -36,7 +36,7 @@ public void CorrectlyParsesLogFilePath() Assert.AreEqual("logFilePath", context.LogFile); } - [TestMethod] + [TestCase] public void CorrectlyParsesHelp() { var context = ArgumentParser.ParseArguments("-h"); @@ -44,36 +44,36 @@ public void CorrectlyParsesHelp() Assert.IsTrue(context.IsHelp); } - [TestMethod] + [TestCase] public void CorrectlyParsesUrlAndBranchName() { - var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/GeertvanHorrik/GitHubLink -b somebranch"); + var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/CatenaLogic/GitLink -b somebranch"); Assert.AreEqual("solutionDirectory", context.SolutionDirectory); - Assert.AreEqual("http://github.com/GeertvanHorrik/GitHubLink", context.TargetUrl); + Assert.AreEqual("http://github.com/CatenaLogic/GitLink", context.TargetUrl); Assert.AreEqual("somebranch", context.TargetBranch); } - [TestMethod] + [TestCase] public void CorrectlyParsesUrlAndConfiguration() { - var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/GeertvanHorrik/GitHubLink -c someConfiguration"); + var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/CatenaLogic/GitLink -c someConfiguration"); Assert.AreEqual("solutionDirectory", context.SolutionDirectory); - Assert.AreEqual("http://github.com/GeertvanHorrik/GitHubLink", context.TargetUrl); + Assert.AreEqual("http://github.com/CatenaLogic/GitLink", context.TargetUrl); Assert.AreEqual("someConfiguration", context.ConfigurationName); } - [TestMethod] + [TestCase] public void ThrowsExceptionForInvalidNumberOfArguments() { - ExceptionTester.CallMethodAndExpectException(() => ArgumentParser.ParseArguments("solutionDirectory -l logFilePath extraArg")); + ExceptionTester.CallMethodAndExpectException(() => ArgumentParser.ParseArguments("solutionDirectory -l logFilePath extraArg")); } - [TestMethod] + [TestCase] public void ThrowsExceptionForUnknownArgument() { - ExceptionTester.CallMethodAndExpectException(() => ArgumentParser.ParseArguments("solutionDirectory -x logFilePath")); + ExceptionTester.CallMethodAndExpectException(() => ArgumentParser.ParseArguments("solutionDirectory -x logFilePath")); } } } \ No newline at end of file diff --git a/src/GitHubLink.Test/ContextFacts.cs b/src/GitLink.Test/ContextFacts.cs similarity index 62% rename from src/GitHubLink.Test/ContextFacts.cs rename to src/GitLink.Test/ContextFacts.cs index fb142d1..094d7a8 100644 --- a/src/GitHubLink.Test/ContextFacts.cs +++ b/src/GitLink.Test/ContextFacts.cs @@ -5,67 +5,68 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink.Test +namespace GitLink.Test { using Catel.Test; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using GitLink.Providers; + using NUnit.Framework; public class ContextFacts { - [TestClass] + [TestFixture] public class TheDefaultValues { - [TestMethod] + [TestCase] public void SetsRightDefaultValues() { - var context = new Context(); + var context = new Context(new ProviderManager()); Assert.AreEqual("Release", context.ConfigurationName); Assert.IsFalse(context.IsHelp); } } - [TestClass] + [TestFixture] public class TheValidateContextMethod { - [TestMethod] + [TestCase] public void ThrowsExceptionForMissingSolutionDirectory() { - var context = new Context(); + var context = new Context(new ProviderManager()); - ExceptionTester.CallMethodAndExpectException(() => context.ValidateContext()); + ExceptionTester.CallMethodAndExpectException(() => context.ValidateContext()); } - [TestMethod] + [TestCase] public void ThrowsExceptionForMissingConfigurationName() { - var context = new Context + var context = new Context(new ProviderManager()) { - SolutionDirectory = @"c:\source\githublink", + SolutionDirectory = @"c:\source\GitLink", ConfigurationName = string.Empty }; - ExceptionTester.CallMethodAndExpectException(() => context.ValidateContext()); + ExceptionTester.CallMethodAndExpectException(() => context.ValidateContext()); } - [TestMethod] + [TestCase] public void ThrowsExceptionForMissingTargetUrl() { - var context = new Context + var context = new Context(new ProviderManager()) { - SolutionDirectory = @"c:\source\githublink", + SolutionDirectory = @"c:\source\GitLink", }; - ExceptionTester.CallMethodAndExpectException(() => context.ValidateContext()); + ExceptionTester.CallMethodAndExpectException(() => context.ValidateContext()); } - [TestMethod] + [TestCase] public void SucceedsForValidContext() { - var context = new Context + var context = new Context(new ProviderManager()) { - SolutionDirectory = @"c:\source\githublink", - TargetUrl = "https://github.com/geertvanhorrik/githublink" + SolutionDirectory = @"c:\source\GitLink", + TargetUrl = "https://github.com/CatenaLogic/GitLink", }; // should not throw diff --git a/src/GitHubLink.Test/Extensions/ContextExtensionsFacts.cs b/src/GitLink.Test/Extensions/ContextExtensionsFacts.cs similarity index 71% rename from src/GitHubLink.Test/Extensions/ContextExtensionsFacts.cs rename to src/GitLink.Test/Extensions/ContextExtensionsFacts.cs index 449ee19..2f9842a 100644 --- a/src/GitHubLink.Test/Extensions/ContextExtensionsFacts.cs +++ b/src/GitLink.Test/Extensions/ContextExtensionsFacts.cs @@ -5,34 +5,35 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink.Test.Extensions +namespace GitLink.Test.Extensions { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using GitLink.Providers; + using NUnit.Framework; public class ContextExtensionsFacts { - [TestClass] + [TestFixture] public class TheGetRelativePathMethod { - [TestMethod] + [TestCase] public void ReturnsRelativePathWithDirectoryDownwards() { - var context = new Context + var context = new Context(new ProviderManager()) { - SolutionDirectory = @"c:\source\githublink" + SolutionDirectory = @"c:\source\GitLink" }; - var relativePath = context.GetRelativePath(@"c:\source\githublink\src\subdir1\somefile.cs"); + var relativePath = context.GetRelativePath(@"c:\source\GitLink\src\subdir1\somefile.cs"); Assert.AreEqual(@"src\subdir1\somefile.cs", relativePath); } - [TestMethod] + [TestCase] public void ReturnsRelativePathWithDirectoryUpwards() { - var context = new Context + var context = new Context(new ProviderManager()) { - SolutionDirectory = @"c:\source\githublink" + SolutionDirectory = @"c:\source\GitLink" }; var relativePath = context.GetRelativePath(@"c:\source\catel\src\subdir1\somefile.cs"); diff --git a/src/GitHubLink.Test/GitHubLink.Test.csproj b/src/GitLink.Test/GitLink.Test.csproj similarity index 75% rename from src/GitHubLink.Test/GitHubLink.Test.csproj rename to src/GitLink.Test/GitLink.Test.csproj index 7e8ba52..b86987c 100644 --- a/src/GitHubLink.Test/GitHubLink.Test.csproj +++ b/src/GitLink.Test/GitLink.Test.csproj @@ -6,8 +6,8 @@ {ED2B9579-59D2-40F2-BC5E-F4DC3DAB9A56} Library Properties - GitHubLink.Test - GitHubLink.Test + GitLink.Test + GitLink.Test v4.5 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -35,11 +35,21 @@ 4 + + ..\..\lib\ApprovalTests.3.0.7\lib\net40\ApprovalTests.dll + + + ..\..\lib\ApprovalUtilities.3.0.7\lib\net35\ApprovalUtilities.dll + False - ..\..\lib\Catel.Core.3.9.0.1404200146-beta\lib\net45\Catel.Core.dll + ..\..\lib\Catel.Core.4.0.0-unstable0497\lib\net45\Catel.Core.dll + + + ..\..\lib\NUnit.2.6.3\lib\nunit.framework.dll + @@ -47,28 +57,35 @@ - - - - - + + - + + + + + + + - + {d68add77-913f-46d2-9a4f-5cc71c4718d8} - GitHubLink + GitLink + + + + diff --git a/src/GitLink.Test/GlobalInitialization.cs b/src/GitLink.Test/GlobalInitialization.cs new file mode 100644 index 0000000..c0bf1c4 --- /dev/null +++ b/src/GitLink.Test/GlobalInitialization.cs @@ -0,0 +1,21 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +using Catel.Logging; +using NUnit.Framework; + +[SetUpFixture] +public class GlobalInitialization +{ + [SetUp] + public static void SetUp() + { +#if DEBUG + LogManager.AddDebugListener(true); +#endif + } +} \ No newline at end of file diff --git a/src/GitLink.Test/IntegrationTests/BitBucketIntegration.CorrectlyUpdatesPdbFiles.approved.txt b/src/GitLink.Test/IntegrationTests/BitBucketIntegration.CorrectlyUpdatesPdbFiles.approved.txt new file mode 100644 index 0000000..903912c --- /dev/null +++ b/src/GitLink.Test/IntegrationTests/BitBucketIntegration.CorrectlyUpdatesPdbFiles.approved.txt @@ -0,0 +1,9 @@ +SRCSRV: ini ------------------------------------------------ +VERSION=2 +SRCSRV: variables ------------------------------------------ +SRCSRVVERCTRL=https +SRCSRVTRG=https://bitbucket.org/CatenaLogic/GitLinkTestRepro/raw/af48c72ad1dd98204ee9b409ca0ba9f34cf8e52e/%var2% +SRCSRV: source files --------------------------------------- +C:\Source\GitLinkTestRepro_BitBucket\src\CSharpTestLibrary\Class1.cs*src/CSharpTestLibrary/Class1.cs +C:\Source\GitLinkTestRepro_BitBucket\src\CSharpTestLibrary\Properties\AssemblyInfo.cs*src/CSharpTestLibrary/Properties/AssemblyInfo.cs +SRCSRV: end ------------------------------------------------ diff --git a/src/GitLink.Test/IntegrationTests/BitBucketIntegration.cs b/src/GitLink.Test/IntegrationTests/BitBucketIntegration.cs new file mode 100644 index 0000000..1361f56 --- /dev/null +++ b/src/GitLink.Test/IntegrationTests/BitBucketIntegration.cs @@ -0,0 +1,31 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Test.IntegrationTests +{ + using NUnit.Framework; + + [TestFixture, Explicit] + public class BitBucketIntegration : IntegrationTestBase + { + public const string Url = "https://bitbucket.org/CatenaLogic/GitLinkTestRepro"; + public const string Directory = @"C:\Source\GitLinkTestRepro_BitBucket"; + + [Test] + public void CorrectlyUpdatesPdbFiles() + { + const string directory = Directory; + const string configurationName = "Release"; + + var result = RunGitLink(directory, Url, "master", configurationName); + + Assert.AreEqual(0, result); + + VerifyUpdatedPdbs(directory, configurationName); + } + } +} \ No newline at end of file diff --git a/src/GitLink.Test/IntegrationTests/GitHubIntegration.CorrectlyUpdatesPdbFiles.approved.txt b/src/GitLink.Test/IntegrationTests/GitHubIntegration.CorrectlyUpdatesPdbFiles.approved.txt new file mode 100644 index 0000000..12d2de8 --- /dev/null +++ b/src/GitLink.Test/IntegrationTests/GitHubIntegration.CorrectlyUpdatesPdbFiles.approved.txt @@ -0,0 +1,9 @@ +SRCSRV: ini ------------------------------------------------ +VERSION=2 +SRCSRV: variables ------------------------------------------ +SRCSRVVERCTRL=https +SRCSRVTRG=https://raw.github.com/CatenaLogic/GitLinkTestRepro/8f1bebc3b06afc67e06d9c482f5871a3cbc1f001/%var2% +SRCSRV: source files --------------------------------------- +C:\Source\GitLinkTestRepro_GitHub\src\CSharpTestLibrary\Class1.cs*src/CSharpTestLibrary/Class1.cs +C:\Source\GitLinkTestRepro_GitHub\src\CSharpTestLibrary\Properties\AssemblyInfo.cs*src/CSharpTestLibrary/Properties/AssemblyInfo.cs +SRCSRV: end ------------------------------------------------ diff --git a/src/GitLink.Test/IntegrationTests/GitHubIntegration.cs b/src/GitLink.Test/IntegrationTests/GitHubIntegration.cs new file mode 100644 index 0000000..caff986 --- /dev/null +++ b/src/GitLink.Test/IntegrationTests/GitHubIntegration.cs @@ -0,0 +1,31 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Test.IntegrationTests +{ + using NUnit.Framework; + + [TestFixture, Explicit] + public class GitHubIntegration : IntegrationTestBase + { + public const string Url = "https://github.com/CatenaLogic/GitLinkTestRepro"; + public const string Directory = @"C:\Source\GitLinkTestRepro_GitHub"; + + [Test] + public void CorrectlyUpdatesPdbFiles() + { + const string directory = Directory; + const string configurationName = "Release"; + + var result = RunGitLink(directory, Url, "master", configurationName); + + Assert.AreEqual(0, result); + + VerifyUpdatedPdbs(directory, configurationName); + } + } +} \ No newline at end of file diff --git a/src/GitLink.Test/IntegrationTests/IntegrationTestBase.cs b/src/GitLink.Test/IntegrationTests/IntegrationTestBase.cs new file mode 100644 index 0000000..d1dfcf1 --- /dev/null +++ b/src/GitLink.Test/IntegrationTests/IntegrationTestBase.cs @@ -0,0 +1,121 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Test.IntegrationTests +{ + using System; + using System.Diagnostics; + using System.IO; + using ApprovalTests; + using Catel.Logging; + using Catel.Reflection; + using GitLink.Providers; + using Microsoft.Win32; + + public class IntegrationTestBase + { + private static readonly ILog Log = LogManager.GetCurrentClassLogger(); + + protected void PrepareTestSolution(string directory, string configurationName) + { + if (!Directory.Exists(directory)) + { + throw new Exception(string.Format("Please make sure to clone the repository to '{0}'", directory)); + } + + var outputDirectory = Path.Combine(directory, "output"); + if (Directory.Exists(outputDirectory)) + { + Log.Info("Deleting directory '{0}'", outputDirectory); + + Directory.Delete(outputDirectory, true); + } + + Log.Info("Building project at '{0}'", directory); + + var msBuildDirectory = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0", "MSBuildToolsPath", string.Empty); + var msBuildFileName = Path.Combine(msBuildDirectory, "msbuild.exe"); + var solutionFileName = Path.Combine(directory, "src", "TestSolution.sln"); + var arguments = string.Format("{0} /p:Configuration={1}", solutionFileName, configurationName); + + var processStartInfo = new ProcessStartInfo(msBuildFileName, arguments); + processStartInfo.Arguments = arguments; + processStartInfo.UseShellExecute = true; + processStartInfo.CreateNoWindow = true; + + var process = Process.Start(processStartInfo); + process.WaitForExit(); + } + + protected int RunGitLink(string directory, string repositoryUrl, string branchName, string configurationName) + { + PrepareTestSolution(directory, configurationName); + + var context = new Context(new ProviderManager()) + { + SolutionDirectory = directory, + TargetUrl = repositoryUrl, + TargetBranch = branchName + }; + + return Linker.Link(context); + } + + protected void VerifyUpdatedPdbs(string directory, string configurationName) + { + var outputDirectoryBase = Path.Combine(directory, "output", configurationName); + + VerifyUpdatedPdb(outputDirectoryBase, "CSharpTestLibrary", true); + VerifyUpdatedPdb(outputDirectoryBase, "CPlusPlusTestLibrary"); + VerifyUpdatedPdb(outputDirectoryBase, "FSharpTestLibrary"); + VerifyUpdatedPdb(outputDirectoryBase, "VisualBasicTestLibrary"); + } + + private void VerifyUpdatedPdb(string outputDirectoryBase, string name, bool verifySrcSrv = false) + { + var pdbFileName = Path.Combine(outputDirectoryBase, name, string.Format("{0}.pdb", name)); + + if (verifySrcSrv) + { + // Required for Approvals + var pdbSrcSrvFileName = string.Format("{0}.srcsrv", pdbFileName); + var pdbSrcSrvTxtFileName = string.Format("{0}.txt", pdbSrcSrvFileName); + File.Copy(pdbSrcSrvFileName, pdbSrcSrvTxtFileName, true); + + Approvals.VerifyFile(pdbSrcSrvTxtFileName); + } + + var containsVariables = false; + var containsControl = false; + var containsServer = false; + + var pdbContents = File.ReadAllLines(pdbFileName); + foreach (var pdbContent in pdbContents) + { + if (pdbContent.Contains("SRCSRV: variables")) + { + containsVariables = true; + } + + if (pdbContent.Contains("SRCSRVVERCTRL=")) + { + containsControl = true; + } + + if (pdbContent.Contains("SRCSRVTRG=")) + { + containsServer = true; + } + } + + if (!containsVariables || !containsControl || !containsServer) + { + throw new Exception("Generated pdb file is invalid"); + } + } + } +} \ No newline at end of file diff --git a/src/GitHubLink.Test/Properties/AssemblyInfo.cs b/src/GitLink.Test/Properties/AssemblyInfo.cs similarity index 94% rename from src/GitHubLink.Test/Properties/AssemblyInfo.cs rename to src/GitLink.Test/Properties/AssemblyInfo.cs index ae52f25..2f7a90b 100644 --- a/src/GitHubLink.Test/Properties/AssemblyInfo.cs +++ b/src/GitLink.Test/Properties/AssemblyInfo.cs @@ -12,11 +12,11 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("GitHubLink.Test")] +[assembly: AssemblyTitle("GitLink.Test")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("GitHubLink.Test")] +[assembly: AssemblyProduct("GitLink.Test")] [assembly: AssemblyCopyright("Copyright © 2014")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/src/GitLink.Test/Providers/BitBucketProviderFacts.cs b/src/GitLink.Test/Providers/BitBucketProviderFacts.cs new file mode 100644 index 0000000..4d8e67c --- /dev/null +++ b/src/GitLink.Test/Providers/BitBucketProviderFacts.cs @@ -0,0 +1,86 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Test.Providers +{ + using GitLink.Providers; + using NUnit.Framework; + + public class BitBucketProviderFacts + { + [TestFixture] + public class TheBitBucketProviderInitialization + { + [TestCase] + public void ReturnsValidInitialization() + { + var provider = new BitBucketProvider(); + var valid = provider.Initialize("https://bitbucket.org/CatenaLogic/GitLink"); + + Assert.IsTrue(valid); + } + + [TestCase] + public void ReturnsInValidInitialization() + { + var provider = new BitBucketProvider(); + var valid = provider.Initialize("https://github.com/CatenaLogic/GitLink"); + + Assert.IsFalse(valid); + } + + [TestFixture] + public class TheBitBucketProviderProperties + { + [TestCase] + public void ReturnsValidCompany() + { + var provider = new BitBucketProvider(); + provider.Initialize("https://bitbucket.org/CatenaLogic/GitLink"); + + Assert.AreEqual("CatenaLogic", provider.CompanyName); + } + + [TestCase] + public void ReturnsValidCompanyUrl() + { + var provider = new BitBucketProvider(); + provider.Initialize("https://bitbucket.org/CatenaLogic/GitLink"); + + Assert.AreEqual("https://bitbucket.org/CatenaLogic", provider.CompanyUrl); + } + + [TestCase] + public void ReturnsValidProject() + { + var provider = new BitBucketProvider(); + provider.Initialize("https://bitbucket.org/CatenaLogic/GitLink"); + + Assert.AreEqual("GitLink", provider.ProjectName); + } + + [TestCase] + public void ReturnsValidProjectUrl() + { + var provider = new BitBucketProvider(); + provider.Initialize("https://bitbucket.org/CatenaLogic/GitLink"); + + Assert.AreEqual("https://bitbucket.org/CatenaLogic/GitLink", provider.ProjectUrl); + } + + [TestCase] + public void ReturnsValidRawGitUrl() + { + var provider = new BitBucketProvider(); + provider.Initialize("https://bitbucket.org/CatenaLogic/GitLink"); + + Assert.AreEqual("https://bitbucket.org/CatenaLogic/GitLink/raw", provider.RawGitUrl); + } + } + } + } +} \ No newline at end of file diff --git a/src/GitLink.Test/Providers/GitHubProviderFacts.cs b/src/GitLink.Test/Providers/GitHubProviderFacts.cs new file mode 100644 index 0000000..2b2a582 --- /dev/null +++ b/src/GitLink.Test/Providers/GitHubProviderFacts.cs @@ -0,0 +1,86 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Test.Providers +{ + using GitLink.Providers; + using NUnit.Framework; + + public class GitHubProviderFacts + { + [TestFixture] + public class TheGitHubProviderInitialization + { + [TestCase] + public void ReturnsValidInitialization() + { + var provider = new GitHubProvider(); + var valid = provider.Initialize("https://github.com/CatenaLogic/GitLink"); + + Assert.IsTrue(valid); + } + + [TestCase] + public void ReturnsInValidInitialization() + { + var provider = new GitHubProvider(); + var valid = provider.Initialize("https://bitbucket.org/CatenaLogic/GitLink"); + + Assert.IsFalse(valid); + } + } + + [TestFixture] + public class TheGitHubProviderProperties + { + [TestCase] + public void ReturnsValidCompany() + { + var provider = new GitHubProvider(); + provider.Initialize("https://github.com/CatenaLogic/GitLink"); + + Assert.AreEqual("CatenaLogic", provider.CompanyName); + } + + [TestCase] + public void ReturnsValidCompanyUrl() + { + var provider = new GitHubProvider(); + provider.Initialize("https://github.com/CatenaLogic/GitLink"); + + Assert.AreEqual("https://github.com/CatenaLogic", provider.CompanyUrl); + } + + [TestCase] + public void ReturnsValidProject() + { + var provider = new GitHubProvider(); + provider.Initialize("https://github.com/CatenaLogic/GitLink"); + + Assert.AreEqual("GitLink", provider.ProjectName); + } + + [TestCase] + public void ReturnsValidProjectUrl() + { + var provider = new GitHubProvider(); + provider.Initialize("https://github.com/CatenaLogic/GitLink"); + + Assert.AreEqual("https://github.com/CatenaLogic/GitLink", provider.ProjectUrl); + } + + [TestCase] + public void ReturnsValidRawGitUrl() + { + var provider = new GitHubProvider(); + provider.Initialize("https://github.com/CatenaLogic/GitLink"); + + Assert.AreEqual("https://raw.github.com/CatenaLogic/GitLink", provider.RawGitUrl); + } + } + } +} \ No newline at end of file diff --git a/src/GitLink.Test/Providers/ProviderManagerFacts.cs b/src/GitLink.Test/Providers/ProviderManagerFacts.cs new file mode 100644 index 0000000..b1c3612 --- /dev/null +++ b/src/GitLink.Test/Providers/ProviderManagerFacts.cs @@ -0,0 +1,38 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Test.Providers +{ + using System; + using GitLink.Providers; + using NUnit.Framework; + + public class ProviderManagerFacts + { + [TestFixture] + public class TheProviderGetProviderMethod + { + [TestCase("https://bitbucket.org/CatenaLogic/GitLink", typeof(BitBucketProvider))] + [TestCase("https://github.com/CatenaLogic/GitLink", typeof(GitHubProvider))] + [TestCase("", null)] + public void ReturnsRightProvider(string url, Type expectedType) + { + var providerManager = new ProviderManager(); + var provider = providerManager.GetProvider(url); + + if (expectedType == null) + { + Assert.IsNull(provider); + } + else + { + Assert.IsInstanceOf(expectedType, provider); + } + } + } + } +} \ No newline at end of file diff --git a/src/GitLink.Test/packages.config b/src/GitLink.Test/packages.config new file mode 100644 index 0000000..c8550e6 --- /dev/null +++ b/src/GitLink.Test/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/GitHubLink.sln b/src/GitLink.sln similarity index 82% rename from src/GitHubLink.sln rename to src/GitLink.sln index f4b7fef..d58c36c 100644 --- a/src/GitHubLink.sln +++ b/src/GitLink.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30324.0 +VisualStudioVersion = 12.0.30723.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubLink", "GitHubLink\GitHubLink.csproj", "{D68ADD77-913F-46D2-9A4F-5CC71C4718D8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitLink", "GitLink\GitLink.csproj", "{D68ADD77-913F-46D2-9A4F-5CC71C4718D8}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A6694C2C-1A8A-49F0-B404-1BBB4D081808}" EndProject @@ -15,23 +15,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{16B74389-D64 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deployment", "deployment", "{99836492-466A-44E3-A92B-72CE3744F61C}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{F3BABD63-7726-4219-BF31-13CF05EE3BD7}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{88214CBE-4B92-4E22-8854-CC21543EE703}" ProjectSection(SolutionItems) = preProject ..\doc\history.txt = ..\doc\history.txt EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{4FBE79F3-A1F1-4107-AA8C-DCB241880EDE}" - ProjectSection(SolutionItems) = preProject - ..\tools\NuGet\NuGet.exe = ..\tools\NuGet\NuGet.exe - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{A5FCE4FA-083A-4814-B38C-2AED9C37647F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{D435DFD9-F741-4FCA-A65A-28B7D251983D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHubLink.Test", "GitHubLink.Test\GitHubLink.Test.csproj", "{ED2B9579-59D2-40F2-BC5E-F4DC3DAB9A56}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitLink.Test", "GitLink.Test\GitLink.Test.csproj", "{ED2B9579-59D2-40F2-BC5E-F4DC3DAB9A56}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{2A773B1D-106C-4583-8021-9AC0BB3E5408}" EndProject @@ -39,19 +32,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "design", "design", "{0A177E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FinalBuilder", "FinalBuilder", "{8EABCB0D-E792-4700-BDF9-E488CF2AB4A2}" ProjectSection(SolutionItems) = preProject - ..\deployment\FinalBuilder\GitHubLink.CreatePackages.fbp7 = ..\deployment\FinalBuilder\GitHubLink.CreatePackages.fbp7 + ..\deployment\FinalBuilder\GitLink.CreatePackages.fbp7 = ..\deployment\FinalBuilder\GitLink.CreatePackages.fbp7 EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Chocolatey", "Chocolatey", "{9765817D-03DD-4879-8A43-CB3086B6743F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "template", "template", "{BEEC31FD-7021-47BA-AB54-A5B4C7C23F7E}" ProjectSection(SolutionItems) = preProject - ..\deployment\Chocolatey\template\GitHubLink.nuspec = ..\deployment\Chocolatey\template\GitHubLink.nuspec + ..\deployment\Chocolatey\template\GitLink.nuspec = ..\deployment\Chocolatey\template\GitLink.nuspec EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "template", "template", "{75559B70-907C-4375-A44B-8195B5027B3C}" ProjectSection(SolutionItems) = preProject - ..\deployment\NuGet\template\GitHubLink.nuspec = ..\deployment\NuGet\template\GitHubLink.nuspec + ..\deployment\NuGet\template\GitLink.nuspec = ..\deployment\NuGet\template\GitLink.nuspec EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{5BC2D5A6-10B0-425B-BAB3-5AB3DFDC24B2}" @@ -92,7 +85,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {D68ADD77-913F-46D2-9A4F-5CC71C4718D8} = {A5FCE4FA-083A-4814-B38C-2AED9C37647F} - {4FBE79F3-A1F1-4107-AA8C-DCB241880EDE} = {F3BABD63-7726-4219-BF31-13CF05EE3BD7} {A5FCE4FA-083A-4814-B38C-2AED9C37647F} = {A6694C2C-1A8A-49F0-B404-1BBB4D081808} {D435DFD9-F741-4FCA-A65A-28B7D251983D} = {A6694C2C-1A8A-49F0-B404-1BBB4D081808} {ED2B9579-59D2-40F2-BC5E-F4DC3DAB9A56} = {D435DFD9-F741-4FCA-A65A-28B7D251983D} diff --git a/src/GitHubLink.sln.DotSettings b/src/GitLink.sln.DotSettings similarity index 100% rename from src/GitHubLink.sln.DotSettings rename to src/GitLink.sln.DotSettings diff --git a/src/GitHubLink/ArgumentParser.cs b/src/GitLink/ArgumentParser.cs similarity index 74% rename from src/GitHubLink/ArgumentParser.cs rename to src/GitLink/ArgumentParser.cs index 04720c4..fddcae5 100644 --- a/src/GitHubLink/ArgumentParser.cs +++ b/src/GitLink/ArgumentParser.cs @@ -5,12 +5,13 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink +namespace GitLink { using System; using System.Collections.Generic; using System.Linq; using Catel.Logging; + using GitLink.Providers; public static class ArgumentParser { @@ -18,21 +19,22 @@ public static class ArgumentParser public static Context ParseArguments(string commandLineArguments) { - return ParseArguments(commandLineArguments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList()); + return ParseArguments(commandLineArguments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(), + new ProviderManager()); } public static Context ParseArguments(params string[] commandLineArguments) { - return ParseArguments(commandLineArguments.ToList()); + return ParseArguments(commandLineArguments.ToList(), new ProviderManager()); } - public static Context ParseArguments(List commandLineArguments) + public static Context ParseArguments(List commandLineArguments, IProviderManager providerManager) { - var context = new Context(); + var context = new Context(providerManager); if (commandLineArguments.Count == 0) { - Log.ErrorAndThrowException("Invalid number of arguments"); + Log.ErrorAndThrowException("Invalid number of arguments"); } var firstArgument = commandLineArguments.First(); @@ -44,7 +46,7 @@ public static Context ParseArguments(List commandLineArguments) if (commandLineArguments.Count < 3) { - Log.ErrorAndThrowException("Invalid number of arguments"); + Log.ErrorAndThrowException("Invalid number of arguments"); } context.SolutionDirectory = firstArgument; @@ -82,7 +84,18 @@ public static Context ParseArguments(List commandLineArguments) continue; } - Log.ErrorAndThrowException("Could not parse command line parameter '{0}'.", name); + if (IsSwitch("s", name)) + { + context.ShaHash = value; + continue; + } + + Log.ErrorAndThrowException("Could not parse command line parameter '{0}'.", name); + } + + if (!string.IsNullOrEmpty(context.TargetUrl)) + { + context.Provider = providerManager.GetProvider(context.TargetUrl); } return context; @@ -107,7 +120,7 @@ private static void EnsureArgumentsEvenCount(IEnumerable commandLineArgu { if (namedArguments.Count.IsOdd()) { - Log.ErrorAndThrowException("Could not parse arguments: '{0}'.", string.Join(" ", commandLineArguments)); + Log.ErrorAndThrowException("Could not parse arguments: '{0}'.", string.Join(" ", commandLineArguments)); } } diff --git a/src/GitLink/Authentication.cs b/src/GitLink/Authentication.cs new file mode 100644 index 0000000..4cb9ce8 --- /dev/null +++ b/src/GitLink/Authentication.cs @@ -0,0 +1,23 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink +{ + using System; + + public class Authentication + { + public Authentication() + { + Username = Environment.GetEnvironmentVariable("GITLINK_REMOTE_USERNAME"); + Password = Environment.GetEnvironmentVariable("GITLINK_REMOTE_PASSWORD"); + } + + public string Password { get; set; } + public string Username { get; set; } + } +} \ No newline at end of file diff --git a/src/GitLink/Context.cs b/src/GitLink/Context.cs new file mode 100644 index 0000000..573a87a --- /dev/null +++ b/src/GitLink/Context.cs @@ -0,0 +1,87 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink +{ + using Catel; + using Catel.Logging; + using Providers; + + public class Context + { + private static readonly ILog Log = LogManager.GetCurrentClassLogger(); + + private readonly IProviderManager _providerManager; + private IProvider _provider; + + public Context(IProviderManager providerManager) + { + Argument.IsNotNull(() => providerManager); + + _providerManager = providerManager; + + Authentication = new Authentication(); + ConfigurationName = "Release"; + } + + public bool IsHelp { get; set; } + + public string LogFile { get; set; } + + public string SolutionDirectory { get; set; } + + public string ConfigurationName { get; set; } + + public Authentication Authentication { get; private set; } + + public IProvider Provider + { + get + { + if (_provider == null) + { + _provider = _providerManager.GetProvider(TargetUrl); + } + + return _provider; + } + set + { + _provider = value; + } + } + + public string TargetUrl { get; set; } + + public string TargetBranch { get; set; } + + public string ShaHash { get; set; } + + public void ValidateContext() + { + if (string.IsNullOrEmpty(SolutionDirectory)) + { + Log.ErrorAndThrowException("Solution directory is missing"); + } + + if (string.IsNullOrEmpty(ConfigurationName)) + { + Log.ErrorAndThrowException("Configuration name is missing"); + } + + if (string.IsNullOrEmpty(TargetUrl)) + { + Log.ErrorAndThrowException("Target url is missing"); + } + + if (Provider == null) + { + Log.ErrorAndThrowException("Cannot determine git provider"); + } + } + } +} \ No newline at end of file diff --git a/src/GitHubLink/Exceptions/GitHubLinkException.cs b/src/GitLink/Exceptions/GitLinkException.cs similarity index 68% rename from src/GitHubLink/Exceptions/GitHubLinkException.cs rename to src/GitLink/Exceptions/GitLinkException.cs index 054ebd0..de98ae2 100644 --- a/src/GitHubLink/Exceptions/GitHubLinkException.cs +++ b/src/GitLink/Exceptions/GitLinkException.cs @@ -1,17 +1,17 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink +namespace GitLink { using System; - public class GitHubLinkException : Exception + public class GitLinkException : Exception { - public GitHubLinkException(string message) + public GitLinkException(string message) : base(message) { } diff --git a/src/GitLink/Extensions/BinaryReaderExtensions.cs b/src/GitLink/Extensions/BinaryReaderExtensions.cs new file mode 100644 index 0000000..43ba1ac --- /dev/null +++ b/src/GitLink/Extensions/BinaryReaderExtensions.cs @@ -0,0 +1,41 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Text; + using Catel; + + public static class BinaryReaderExtensions + { + public static Guid ReadGuid(this BinaryReader binaryReader) + { + Argument.IsNotNull(() => binaryReader); + + return new Guid(binaryReader.ReadBytes(16)); + } + + public static string ReadCString(this BinaryReader binaryReader) + { + Argument.IsNotNull(() => binaryReader); + + var list = new List(); + + var b = binaryReader.ReadByte(); + while (b != '\0') + { + list.Add(b); + b = binaryReader.ReadByte(); + } + + return Encoding.UTF8.GetString(list.ToArray()); + } + } +} \ No newline at end of file diff --git a/src/GitHubLink/Extensions/ContextExtensions.cs b/src/GitLink/Extensions/ContextExtensions.cs similarity index 97% rename from src/GitHubLink/Extensions/ContextExtensions.cs rename to src/GitLink/Extensions/ContextExtensions.cs index 6ff89e2..94a2d82 100644 --- a/src/GitHubLink/Extensions/ContextExtensions.cs +++ b/src/GitLink/Extensions/ContextExtensions.cs @@ -5,7 +5,7 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink +namespace GitLink { using Catel; using Catel.IO; diff --git a/src/GitHubLink/Extensions/IntExtensions.cs b/src/GitLink/Extensions/IntExtensions.cs similarity index 96% rename from src/GitHubLink/Extensions/IntExtensions.cs rename to src/GitLink/Extensions/IntExtensions.cs index d3e4fc7..0fa8ced 100644 --- a/src/GitHubLink/Extensions/IntExtensions.cs +++ b/src/GitLink/Extensions/IntExtensions.cs @@ -5,7 +5,7 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink +namespace GitLink { public static class ExtensionMethods { diff --git a/src/GitHubLink/Extensions/PdbExtensions.cs b/src/GitLink/Extensions/PdbExtensions.cs similarity index 83% rename from src/GitHubLink/Extensions/PdbExtensions.cs rename to src/GitLink/Extensions/PdbExtensions.cs index 2c12095..bb63ef7 100644 --- a/src/GitHubLink/Extensions/PdbExtensions.cs +++ b/src/GitLink/Extensions/PdbExtensions.cs @@ -5,13 +5,13 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink +namespace GitLink { using System; using System.Collections.Generic; using System.Linq; using Catel; - using SourceLink; + using Pdb; public static class PdbExtensions { @@ -21,14 +21,14 @@ public static Dictionary VerifyPdbFiles(this PdbFile pdbFile, IE var missing = new Dictionary(StringComparer.OrdinalIgnoreCase); var actualFileChecksums = (from x in files - select new KeyValuePair(Hex.encode(Crypto.hashesMD5(new[] { x }).First().Item1), x)).ToDictionary(x => x.Value, x => x.Key); + select new KeyValuePair(Hex.Encode(Crypto.GetMd5HashForFiles(new[] { x }).First().Item1), x)).ToDictionary(x => x.Value, x => x.Key); foreach (var checksumInfo in pdbFile.GetChecksums()) { var file = checksumInfo.Key; var checksum = checksumInfo.Value; - if (!actualFileChecksums.ContainsKey(checksum)) + if (!actualFileChecksums.ContainsValue(checksum)) { missing[file] = checksum; } @@ -45,7 +45,7 @@ public static Dictionary GetChecksums(this PdbFile pdbFile) foreach (var file in pdbFile.GetFiles()) { - checksums.Add(file.Item1, Hex.encode(file.Item2)); + checksums.Add(file.Item1, Hex.Encode(file.Item2)); } return checksums; @@ -68,20 +68,20 @@ public static IEnumerable> GetFiles(this PdbFile pdbFile) continue; } - int num = value.Stream; + var num = value.Stream; var name = value.Name.Substring(FileIndicator.Length); var bytes = pdbFile.ReadStreamBytes(num); - if (bytes.Length != 72) + if (bytes.Length != 88) { continue; } // Get last 16 bytes for checksum - byte[] buffer = new byte[16]; - for (int i = 0; i < 16; i++) + var buffer = new byte[16]; + for (int i = 72; i < 88; i++) { - buffer[i] = bytes[i]; + buffer[i-72] = bytes[i]; } results.Add(new Tuple(name, buffer)); diff --git a/src/GitHubLink/Extensions/ProjectExtensions.cs b/src/GitLink/Extensions/ProjectExtensions.cs similarity index 92% rename from src/GitHubLink/Extensions/ProjectExtensions.cs rename to src/GitLink/Extensions/ProjectExtensions.cs index 3007999..93c09bc 100644 --- a/src/GitHubLink/Extensions/ProjectExtensions.cs +++ b/src/GitLink/Extensions/ProjectExtensions.cs @@ -5,7 +5,7 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink +namespace GitLink { using System; using System.Collections.Generic; @@ -14,7 +14,7 @@ namespace GitHubLink using Catel; using Catel.Logging; using Microsoft.Build.Evaluation; - using SourceLink; + using Pdb; public static class ProjectExtensions { @@ -54,21 +54,21 @@ public static void CreateSrcSrv(this Project project, string rawUrl, string revi var srcsrvFile = GetOutputSrcSrvFile(project); - File.WriteAllBytes(srcsrvFile, SrcSrv.create(rawUrl, revision, paths.Select(x => new Tuple(x.Key, x.Value)))); + File.WriteAllBytes(srcsrvFile, SrcSrv.Create(rawUrl, revision, paths.Select(x => new Tuple(x.Key, x.Value)))); } public static IEnumerable GetCompilableItems(this Project project) { Argument.IsNotNull(() => project); - return project.Items.Where(x => string.Equals(x.ItemType, "Compile")); + return project.Items.Where(x => string.Equals(x.ItemType, "Compile") || string.Equals(x.ItemType, "ClCompile") || string.Equals(x.ItemType, "ClInclude")); } public static Dictionary VerifyPdbFiles(this Project project, IEnumerable files) { Argument.IsNotNull(() => project); - using (var pdb = new PdbFile(Path.ChangeExtension(project.GetOutputFile(), ".pdb"))) + using (var pdb = new GitLink.Pdb.PdbFile(Path.ChangeExtension(project.GetOutputFile(), ".pdb"))) { return pdb.VerifyPdbFiles(files); } diff --git a/src/GitHubLink/Extensions/ProjectItemExtensions.cs b/src/GitLink/Extensions/ProjectItemExtensions.cs similarity index 98% rename from src/GitHubLink/Extensions/ProjectItemExtensions.cs rename to src/GitLink/Extensions/ProjectItemExtensions.cs index 8162987..38393e6 100644 --- a/src/GitHubLink/Extensions/ProjectItemExtensions.cs +++ b/src/GitLink/Extensions/ProjectItemExtensions.cs @@ -5,7 +5,7 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink +namespace GitLink { using Catel; using Catel.IO; diff --git a/src/GitLink/Extensions/StringExtensions.cs b/src/GitLink/Extensions/StringExtensions.cs new file mode 100644 index 0000000..835f9d6 --- /dev/null +++ b/src/GitLink/Extensions/StringExtensions.cs @@ -0,0 +1,30 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink +{ + public static class StringExtensions + { + 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 IsPullRequest(this string branchName) + { + return branchName.Contains("pull/") || branchName.Contains("pull-requests/") || branchName.Contains("pr/"); + } + } +} \ No newline at end of file diff --git a/src/GitHubLink/FodyWeavers.xml b/src/GitLink/FodyWeavers.xml similarity index 83% rename from src/GitHubLink/FodyWeavers.xml rename to src/GitLink/FodyWeavers.xml index f4da8b5..3735571 100644 --- a/src/GitHubLink/FodyWeavers.xml +++ b/src/GitLink/FodyWeavers.xml @@ -3,9 +3,8 @@ Catel.Core - FSharp.Core LibGit2Sharp - SourceLink + \ No newline at end of file diff --git a/src/GitHubLink/Git/GitDirFinder.cs b/src/GitLink/Git/GitDirFinder.cs similarity index 97% rename from src/GitHubLink/Git/GitDirFinder.cs rename to src/GitLink/Git/GitDirFinder.cs index 92a98fd..58c77ff 100644 --- a/src/GitHubLink/Git/GitDirFinder.cs +++ b/src/GitLink/Git/GitDirFinder.cs @@ -5,7 +5,7 @@ // -------------------------------------------------------------------------------------------------------------------- -namespace GitHubLink.Git +namespace GitLink.Git { using System.IO; using LibGit2Sharp; diff --git a/src/GitLink/Git/GitPreparer.cs b/src/GitLink/Git/GitPreparer.cs new file mode 100644 index 0000000..eb82830 --- /dev/null +++ b/src/GitLink/Git/GitPreparer.cs @@ -0,0 +1,132 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Git +{ + using System; + using System.IO; + using System.Linq; + using System.Runtime.Remoting.Messaging; + using Catel; + using Catel.Logging; + using LibGit2Sharp; + + public class GitPreparer : IRepositoryPreparer + { + private static readonly ILog Log = LogManager.GetCurrentClassLogger(); + + public bool IsPreparationRequired(Context context) + { + Argument.IsNotNull(() => context); + + var gitPath = GitDirFinder.TreeWalkForGitDir(context.SolutionDirectory); + return string.IsNullOrEmpty(gitPath); + } + + public string Prepare(Context context) + { + Argument.IsNotNull(() => context); + + var gitDirectory = Path.Combine(Path.GetTempPath(), "GitLink", Guid.NewGuid().ToString()); + Directory.CreateDirectory(gitDirectory); + + if (!string.IsNullOrWhiteSpace(context.TargetUrl)) + { + gitDirectory = GetGitInfoFromUrl(context, gitDirectory); + } + + return GitDirFinder.TreeWalkForGitDir(gitDirectory); + } + + private string GetGitInfoFromUrl(Context context, string gitDirectory) + { + gitDirectory = Path.Combine(gitDirectory, ".git"); + if (Directory.Exists(gitDirectory)) + { + Log.Info("Deleting existing .git folder from '{0}' to force new checkout from url", gitDirectory); + + DeleteHelper.DeleteGitRepository(gitDirectory); + } + + Log.Info("Retrieving git info from url '{0}'", context.TargetUrl); + + Credentials credentials = null; + var authentication = context.Authentication; + if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password)) + { + Log.Info("Setting up credentials using name '{0}'", authentication.Username); + + credentials = new UsernamePasswordCredentials + { + Username = authentication.Username, + Password = authentication.Password + }; + } + + var cloneOptions = new CloneOptions + { + Checkout = false, + IsBare = true, + CredentialsProvider = (url, username, supportedTypes) => credentials + }; + + Repository.Clone(context.TargetUrl, gitDirectory, cloneOptions); + + if (!string.IsNullOrWhiteSpace(context.TargetBranch)) + { + using (var repository = new Repository(gitDirectory)) + { + Reference newHead = null; + + var localReference = GetLocalReference(repository, context.TargetBranch); + if (localReference != null) + { + newHead = localReference; + } + + if (newHead == null) + { + var remoteReference = GetRemoteReference(repository, context.TargetBranch, context.TargetUrl); + if (remoteReference != null) + { + repository.Network.Fetch(context.TargetUrl, new[] + { + string.Format("{0}:{1}", remoteReference.CanonicalName, context.TargetBranch) + }); + + newHead = repository.Refs[string.Format("refs/heads/{0}", context.TargetBranch)]; + } + } + + if (newHead != null) + { + Log.Info("Switching to branch '{0}'", context.TargetBranch); + + repository.Refs.UpdateTarget(repository.Refs.Head, newHead); + } + } + } + + return gitDirectory; + } + + private static Reference GetLocalReference(Repository repository, string branchName) + { + var targetBranchName = branchName.GetCanonicalBranchName(); + + return repository.Refs.FirstOrDefault(localRef => string.Equals(localRef.CanonicalName, targetBranchName)); + } + + private static DirectReference GetRemoteReference(Repository repository, string branchName, string repositoryUrl) + { + var targetBranchName = branchName.GetCanonicalBranchName(); + var remoteReferences = repository.Network.ListReferences(repositoryUrl); + + return remoteReferences.FirstOrDefault(remoteRef => string.Equals(remoteRef.CanonicalName, targetBranchName)); + } + } +} \ No newline at end of file diff --git a/src/GitLink/Git/Interfaces/IRepositoryPreparer.cs b/src/GitLink/Git/Interfaces/IRepositoryPreparer.cs new file mode 100644 index 0000000..c296df0 --- /dev/null +++ b/src/GitLink/Git/Interfaces/IRepositoryPreparer.cs @@ -0,0 +1,15 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2014 - 2014 CatenaLogic. All rights reserved. +// +// -------------------------------------------------------------------------------------------------------------------- + + +namespace GitLink.Git +{ + public interface IRepositoryPreparer + { + bool IsPreparationRequired(Context context); + string Prepare(Context context); + } +} \ No newline at end of file diff --git a/src/GitHubLink/GitHubLink.csproj b/src/GitLink/GitLink.csproj similarity index 68% rename from src/GitHubLink/GitHubLink.csproj rename to src/GitLink/GitLink.csproj index f25b82d..7262f55 100644 --- a/src/GitHubLink/GitHubLink.csproj +++ b/src/GitLink/GitLink.csproj @@ -7,18 +7,18 @@ {D68ADD77-913F-46D2-9A4F-5CC71C4718D8} Exe Properties - GitHubLink - GitHubLink + GitLink + GitLink v4.5 512 - 50d7f892 + 9be2d35b true full false - ..\..\output\debug\GitHubLink\ + ..\..\output\debug\GitLink\ DEBUG;TRACE prompt 4 @@ -30,7 +30,7 @@ pdbonly true - ..\..\output\release\GitHubLink\ + ..\..\output\release\GitLink\ TRACE prompt 4 @@ -40,7 +40,7 @@ - GitHubLink.Program + GitLink.Program Resources\Icons\Logo.ico @@ -48,22 +48,20 @@ False - ..\..\lib\Catel.Core.3.9.0.1404200146-beta\lib\net45\Catel.Core.dll + ..\..\lib\Catel.Core.4.0.0-unstable0497\lib\net45\Catel.Core.dll - - True + + ..\..\lib\Catel.Fody.2.3.0-unstable0031\lib\portable-net4+sl4+wp7+win8+wpa81+MonoAndroid14+MonoTouch40\Catel.Fody.Attributes.dll - - ..\..\lib\LibGit2Sharp.0.17.0.0\lib\net35\LibGit2Sharp.dll - True + + False + ..\..\lib\LibGit2Sharp.0.19.0.0\lib\net40\LibGit2Sharp.dll - - ..\..\lib\SourceLink.0.3.5-a1402171459-a1cba03d\lib\net45\SourceLink.dll - + @@ -75,17 +73,18 @@ Properties\SolutionAssemblyInfo.cs + + - - - - + + + @@ -93,17 +92,31 @@ + + + + + + + + + + + + + + + + - - Designer @@ -112,12 +125,12 @@ - + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - +