Skip to content

Commit 100de68

Browse files
committed
fix target path not being respected
1 parent f4174ec commit 100de68

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591</NoWarn>
5-
<Version>0.6.2</Version>
5+
<Version>0.6.3</Version>
66
<Description>A tool to help synchronizing specific files and folders across GitHub hosted repositories.</Description>
77
<PackageTags>GitHub</PackageTags>
88
<SignAssembly>false</SignAssembly>

src/GitHubSync/ManualSyncItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
public class ManualSyncItem
44
{
55
public string Path { get; set; }
6+
public string Target { get; set; }
67
}
78
}

src/GitHubSync/RepoSync.cs

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public void AddOrRemoveSourceItem(bool toBeAdded, TreeEntryTargetType type, stri
7171

7272
manualSyncItems.Add(new ManualSyncItem
7373
{
74-
Path = path
74+
Path = path,
75+
Target = target
7576
});
7677
}
7778

@@ -192,30 +193,51 @@ void ProcessItem(string item, List<SyncItem> itemsToSync, RepositoryInfo source)
192193
var parts = new Parts(
193194
$"{source.Owner}/{source.Repository}",
194195
TreeEntryTargetType.Blob, source.Branch, item);
195-
var isManualSyncItem = manualSyncItems.Any(x => item.StartsWith(x.Path, StringComparison.OrdinalIgnoreCase));
196-
if (syncMode == SyncMode.IncludeAllByDefault)
196+
var localManualSyncItems = manualSyncItems.Where(x => item == x.Path).ToList();
197+
var isManualSyncItem = localManualSyncItems.Any();
198+
if (isManualSyncItem)
197199
{
198-
itemsToSync.Add(new SyncItem
200+
foreach (var manualSyncItem in localManualSyncItems)
199201
{
200-
Parts = parts,
201-
ToBeAdded = !isManualSyncItem,
202-
Target = null
203-
});
202+
switch (syncMode)
203+
{
204+
case SyncMode.IncludeAllByDefault:
205+
itemsToSync.Add(new SyncItem
206+
{
207+
Parts = parts,
208+
ToBeAdded = false,
209+
Target = manualSyncItem?.Target
210+
});
211+
continue;
212+
case SyncMode.ExcludeAllByDefault:
213+
itemsToSync.Add(new SyncItem
214+
{
215+
Parts = parts,
216+
ToBeAdded = true,
217+
Target = manualSyncItem?.Target
218+
});
219+
continue;
220+
}
221+
}
204222
return;
205223
}
206-
207-
if (syncMode == SyncMode.ExcludeAllByDefault)
224+
switch (syncMode)
208225
{
209-
itemsToSync.Add(new SyncItem
210-
{
211-
Parts = parts,
212-
ToBeAdded = isManualSyncItem,
213-
Target = null
214-
});
215-
return;
226+
case SyncMode.IncludeAllByDefault:
227+
itemsToSync.Add(new SyncItem
228+
{
229+
Parts = parts,
230+
ToBeAdded = true,
231+
});
232+
return;
233+
case SyncMode.ExcludeAllByDefault:
234+
itemsToSync.Add(new SyncItem
235+
{
236+
Parts = parts,
237+
ToBeAdded = false,
238+
});
239+
return;
216240
}
217-
218-
throw new ArgumentOutOfRangeException(nameof(syncMode), $"Sync mode '{syncMode}' is not supported");
219241
}
220242

221243
public async Task<IReadOnlyList<UpdateResult>> Sync(SyncOutput syncOutput = SyncOutput.CreatePullRequest)

src/Tests/RepoSyncTests.SyncPrExcludeAllByDefault.approved.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
Title: 'GitHubSync update',
33
Body: 'This is an automated synchronization PR.\r\n\r\nThe following source template repositories were used:\r\n* SimonCropp/GitHubSync.TestRepository\r\n',
44
Commits: 1,
5-
Additions: 1,
6-
ChangedFiles: 1,
5+
Additions: 2,
6+
ChangedFiles: 2,
77
State: 'open',
88
Target: 'SyncPrExcludeAllByDefault',
99
Files: [
10+
{
11+
FileName: 'nested/sourceFile.txt',
12+
Status: 'added'
13+
},
1014
{
1115
FileName: 'sourceFile.txt',
1216
Status: 'added'

src/Tests/RepoSyncTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public async Task SyncPrExcludeAllByDefault()
3030
await using var repoContext = await TempRepoContext.Create(Context.MethodName);
3131
repoSync.AddSourceRepository(new RepositoryInfo(credentials, "SimonCropp", "GitHubSync.TestRepository", "source"));
3232
repoSync.AddBlob("sourceFile.txt");
33+
repoSync.AddSourceItem(TreeEntryTargetType.Blob,"sourceFile.txt", "nested/sourceFile.txt");
3334
repoSync.AddTargetRepository(new RepositoryInfo(credentials, "SimonCropp", "GitHubSync.TestRepository", repoContext.TempBranchName));
3435

3536
var sync = await repoSync.Sync();

0 commit comments

Comments
 (0)