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

Commit

Permalink
#46 Add command line parameter to ignore specific projects
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertvanHorrik committed Dec 11, 2014
1 parent 6d5baca commit c96acb8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 17 deletions.
47 changes: 30 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Providers currently being worked on:

It is also possible to specify a custom url provider.

# Using GitLink as command line tool #
# Using GitLink as command line tool

Using GitLink via the command line is very simple:

Expand All @@ -68,44 +68,57 @@ Using GitLink via the command line is very simple:

Below are a few examples.

## Running for the default branch ##
## Running for the default branch

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 ##
## Running for a specific branch

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 ##
## Running for a specific branch and configuration

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 ##
## Running for a specific solution only

Sometimes a repository contains more than 1 solution file. By default, all solutions will be processed. To only process a single solution file, use the *-f* option:

GitLink.exe c:\source\catel -u https://github.com/catel/catel -f Catel.sln

## Ignoreing projects

When specific projects should be ignored, use the *-ignore* option. This option accepts a comma separated list of projects to ignore:

GitLink.exe c:\source\catel -u https://github.com/catel/catel -f Catel.sln -ignore WindowsPhone,WindowsRuntime

**Note that the ignore list uses Contains([ignoredProject]) to ignore items, so when use *Windows*, *WindowsPhone* will be ignored as well**

## Getting help

When you need help about GitLink, use the following command line:

GitLink.exe -help

## Logging to a file ##
## Logging to a file

When you need to log the information to a file, use the following command line:

GitLink.exe c:\source\catel -u https://github.com/catel/catel -b develop -l GitLinkLog.log


# Using GitLink in code #
# Using GitLink 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 ##
## Creating a context

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:

Expand All @@ -122,33 +135,33 @@ 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");
```

## Linking a context ##
## Linking a context

Once a context is created, the *Linker* class can be used to actually link the files:

Linker.Link(context);

# How to get GitLink #
# How to get GitLink

There are three general ways to get GitLink:

## Get it from GitHub ##
## Get it from GitHub

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 ##
## Get it via Chocolatey

If you want to install the tool on your (build) computer, the package is available via <a href="https://chocolatey.org/" target="_blank">Chocolatey</a>. To install, use the following command:

choco install GitLink

## Get it via NuGet ##
## Get it via NuGet

If you want to reference the assembly to use it in code, the recommended way to get it is via <a href="http://www.nuget.org/" target="_blank">NuGet</a>.

**Note that getting GitLink via NuGet will add it as a reference to the project**

# How does it work #
# How does it work

The SrcSrv tool (Srcsrv.dll) enables a client to retrieve the exact version of the source files that were used to build an application. Because the source code for a module can change between versions and over the course of years, it is important to look at the source code as it existed when the version of the module in question was built.

Expand All @@ -157,7 +170,7 @@ For more information, see the <a href="http://msdn.microsoft.com/en-us/library/w
GitLink creates a source index file and updates the PDB file so it will retrieve the files from the Git host file handler.

<a name="projects-using-gitlink"></a>
# Projects using GitLink #
# Projects using GitLink

Below is a list of projects already using GitLink (alphabetically ordered).

Expand Down Expand Up @@ -187,6 +200,6 @@ Are you using GitLink in your projects? Let us know and we will add your project
*Note that you can also create a pull request on this document and add it yourself.*


# Icon #
# Icon

Link by Dominic Whittle from The Noun Project
15 changes: 15 additions & 0 deletions src/GitLink.Tests/ArgumentParserFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ public void CorrectlyParsesUrlAndConfigurationWithDebug()
Assert.IsTrue(context.IsDebug);
}

[TestCase]
public void CorrectlyParsesIgnoredProjects()
{
var context = ArgumentParser.ParseArguments("solutionDirectory -u http://github.com/CatenaLogic/GitLink -debug -c someConfiguration -ignore test1,test2");

Assert.AreEqual("solutionDirectory", context.SolutionDirectory);
Assert.AreEqual("http://github.com/CatenaLogic/GitLink", context.TargetUrl);
Assert.AreEqual("someConfiguration", context.ConfigurationName);
Assert.IsTrue(context.IsDebug);

Assert.AreEqual(2, context.IgnoredProjects.Count);
Assert.AreEqual("test1", context.IgnoredProjects[0]);
Assert.AreEqual("test2", context.IgnoredProjects[1]);
}

[TestCase]
public void ThrowsExceptionForUnknownArgument()
{
Expand Down
7 changes: 7 additions & 0 deletions src/GitLink/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace GitLink
using System;
using System.Collections.Generic;
using System.Linq;
using Catel.Collections;
using Catel.Logging;
using GitLink.Providers;

Expand Down Expand Up @@ -111,6 +112,12 @@ public static Context ParseArguments(List<string> commandLineArguments, IProvide
continue;
}

if (IsSwitch("ignore", name))
{
context.IgnoredProjects.AddRange(value.Split(new []{ ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()));
continue;
}

Log.ErrorAndThrowException<GitLinkException>("Could not parse command line parameter '{0}'.", name);
}

Expand Down
4 changes: 4 additions & 0 deletions src/GitLink/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace GitLink
{
using System;
using System.Collections.Generic;
using Catel;
using Catel.IO;
using Catel.Logging;
Expand All @@ -29,6 +30,7 @@ public Context(IProviderManager providerManager)
Authentication = new Authentication();
ConfigurationName = "Release";
PlatformName = "AnyCPU";
IgnoredProjects = new List<string>();
}

public bool IsHelp { get; set; }
Expand Down Expand Up @@ -70,6 +72,8 @@ public IProvider Provider

public string SolutionFile { get; set; }

public List<string> IgnoredProjects { get; private set; }

public void ValidateContext()
{
if (!string.IsNullOrWhiteSpace(SolutionDirectory))
Expand Down
19 changes: 19 additions & 0 deletions src/GitLink/Extensions/ProjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ public static class ProjectExtensions
{
private static readonly ILog Log = LogManager.GetCurrentClassLogger();

public static bool ShouldBeIgnored(this Project project, IEnumerable<string> projectsToIgnore)
{
Argument.IsNotNull(() => project);

var projectName = GetProjectName(project).ToLower();

foreach (var projectToIgnore in projectsToIgnore)
{
var lowerCaseProjectToIgnore = projectToIgnore.ToLower();

if (projectName.Contains(lowerCaseProjectToIgnore))

This comment has been minimized.

Copy link
@sevoku

sevoku Dec 12, 2014

better:

if (projectName == lowerCaseProjectToIgnore)
{
return true;
}
}

return false;
}

public static string GetProjectName(this Project project)
{
Argument.IsNotNull(() => project);
Expand Down
8 changes: 8 additions & 0 deletions src/GitLink/Linker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ public static int Link(Context context)
var projectCount = projects.Count();
var failedProjects = new List<Project>();
Log.Info("Found '{0}' project(s)", projectCount);
Log.Info(string.Empty);

foreach (var project in projects)
{
try
{
if (project.ShouldBeIgnored(context.IgnoredProjects))
{
Log.Info("Ignoring '{0}'", project.GetProjectName());
Log.Info(string.Empty);
continue;
}

if (context.IsDebug)
{
project.DumpProperties();
Expand Down

0 comments on commit c96acb8

Please sign in to comment.