Skip to content

Commit 6090ea9

Browse files
new "IncludeRepos" config option, backup only the repos in this list
Fixes #64
1 parent 5c3e3ea commit 6090ea9

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using ScmBackup.Configuration;
2+
using ScmBackup.Hosters;
3+
using ScmBackup.Tests.Hosters;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using Xunit;
9+
10+
namespace ScmBackup.Tests
11+
{
12+
public class IncludingHosterApiCallerTests
13+
{
14+
ConfigSource source;
15+
IncludingHosterApiCaller sut;
16+
17+
public IncludingHosterApiCallerTests()
18+
{
19+
this.source = new ConfigSource { Title = "foo" };
20+
21+
var repos = new List<HosterRepository>();
22+
repos.Add(new HosterRepository("foo.bar", "bar", "http://clone", ScmType.Git));
23+
repos.Add(new HosterRepository("foo.baz", "baz", "http://clone", ScmType.Git));
24+
25+
var caller = new FakeHosterApiCaller();
26+
caller.Lists.Add(this.source, repos);
27+
28+
this.sut = new IncludingHosterApiCaller(caller);
29+
}
30+
31+
[Fact]
32+
public void IncludesRepo()
33+
{
34+
this.source.IncludeRepos = new List<string> { "bar" };
35+
36+
var list = this.sut.GetRepositoryList(this.source);
37+
38+
Assert.Single(list);
39+
Assert.Equal("bar", list.First().ShortName);
40+
}
41+
42+
[Fact]
43+
public void BackupsEverythingWhenNotSet()
44+
{
45+
// don't set this.source.IncludeRepos
46+
47+
var list = this.sut.GetRepositoryList(this.source);
48+
49+
Assert.Equal(2, list.Count);
50+
}
51+
}
52+
}

src/ScmBackup/CompositionRoot/Bootstrapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ select Lifestyle.Singleton.CreateRegistration(type, container)
107107

108108
container.RegisterInstance<IHosterApiCaller>(new HosterApiCaller(hosterFactory));
109109
container.RegisterDecorator<IHosterApiCaller, IgnoringHosterApiCaller>();
110+
container.RegisterDecorator<IHosterApiCaller, IncludingHosterApiCaller>();
110111
container.RegisterDecorator<IHosterApiCaller, LoggingHosterApiCaller>();
111112

112113
container.RegisterInstance<IHosterBackupMaker>(new HosterBackupMaker(hosterFactory));

src/ScmBackup/Configuration/ConfigSource.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ internal class ConfigSource
4040
/// </summary>
4141
public List<string> IgnoreRepos { get; set; }
4242

43+
44+
/// <summary>
45+
/// list of repository names which should be included in the backup, all others will be ignored!
46+
/// </summary>
47+
public List<string> IncludeRepos { get; set; }
48+
4349
/// <summary>
4450
/// password for authentication
4551
/// </summary>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using ScmBackup.Configuration;
2+
using ScmBackup.Hosters;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace ScmBackup
7+
{
8+
internal class IncludingHosterApiCaller : IHosterApiCaller
9+
{
10+
private readonly IHosterApiCaller caller;
11+
12+
public IncludingHosterApiCaller(IHosterApiCaller caller)
13+
{
14+
this.caller = caller;
15+
}
16+
17+
public List<HosterRepository> GetRepositoryList(ConfigSource source)
18+
{
19+
var list = this.caller.GetRepositoryList(source);
20+
21+
if (source.IncludeRepos != null && source.IncludeRepos.Any())
22+
{
23+
list.RemoveAll(l => !source.IncludeRepos.Contains(l.ShortName));
24+
}
25+
26+
return list;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)