Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 403c7c2

Browse files
authored
Merge pull request #762 from github-for-unity/fixes/discard-fails
Fix discarding when repo path != project path
2 parents 4596bde + 8a36740 commit 403c7c2

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void RestartRepository()
271271

272272
repositoryManager?.Dispose();
273273

274-
repositoryManager = Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, Environment.FileSystem, Environment.RepositoryPath);
274+
repositoryManager = Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, Environment.RepositoryPath);
275275
repositoryManager.Initialize();
276276
Environment.Repository.Initialize(repositoryManager, TaskManager);
277277
repositoryManager.Start();

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class RepositoryManager : IRepositoryManager
100100
private readonly IGitConfig config;
101101
private readonly IGitClient gitClient;
102102
private readonly IRepositoryPathConfiguration repositoryPaths;
103-
private readonly IFileSystem fileSystem;
104103
private readonly CancellationToken token;
105104
private readonly IRepositoryWatcher watcher;
106105

@@ -118,13 +117,12 @@ class RepositoryManager : IRepositoryManager
118117
public event Action<CacheType> DataNeedsRefreshing;
119118

120119
public RepositoryManager(IGitConfig gitConfig,
121-
IRepositoryWatcher repositoryWatcher, IGitClient gitClient,
122-
IFileSystem fileSystem,
120+
IRepositoryWatcher repositoryWatcher,
121+
IGitClient gitClient,
123122
CancellationToken token,
124123
IRepositoryPathConfiguration repositoryPaths)
125124
{
126125
this.repositoryPaths = repositoryPaths;
127-
this.fileSystem = fileSystem;
128126
this.token = token;
129127
this.gitClient = gitClient;
130128
this.watcher = repositoryWatcher;
@@ -140,7 +138,7 @@ public RepositoryManager(IGitConfig gitConfig,
140138
}
141139

142140
public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IGitClient gitClient,
143-
IFileSystem fileSystem, NPath repositoryRoot)
141+
NPath repositoryRoot)
144142
{
145143
var repositoryPathConfiguration = new RepositoryPathConfiguration(repositoryRoot);
146144
string filePath = repositoryPathConfiguration.DotGitConfig;
@@ -149,7 +147,7 @@ public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager
149147
var repositoryWatcher = new RepositoryWatcher(platform, repositoryPathConfiguration, taskManager.Token);
150148

151149
return new RepositoryManager(gitConfig, repositoryWatcher,
152-
gitClient, fileSystem,
150+
gitClient,
153151
taskManager.Token, repositoryPathConfiguration);
154152
}
155153

@@ -302,14 +300,14 @@ public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)
302300
ActionTask<GitStatusEntry[]> task = null;
303301
task = new ActionTask<GitStatusEntry[]>(token, (_, entries) =>
304302
{
305-
var itemsToDelete = new List<string>();
303+
var itemsToDelete = new List<NPath>();
306304
var itemsToRevert = new List<string>();
307305

308306
foreach (var gitStatusEntry in gitStatusEntries)
309307
{
310308
if (gitStatusEntry.status == GitFileStatus.Added || gitStatusEntry.status == GitFileStatus.Untracked)
311309
{
312-
itemsToDelete.Add(gitStatusEntry.path);
310+
itemsToDelete.Add(gitStatusEntry.path.ToNPath().MakeAbsolute());
313311
}
314312
else
315313
{
@@ -321,7 +319,7 @@ public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)
321319
{
322320
foreach (var itemToDelete in itemsToDelete)
323321
{
324-
fileSystem.FileDelete(itemToDelete);
322+
itemToDelete.DeleteIfExists();
325323
}
326324
}
327325

src/tests/IntegrationTests/BaseIntegrationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
110110
DotGitHead = DotGitPath.Combine("HEAD");
111111
DotGitConfig = DotGitPath.Combine("config");
112112

113-
RepositoryManager = GitHub.Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, Environment.FileSystem, repoPath);
113+
RepositoryManager = GitHub.Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, repoPath);
114114
RepositoryManager.Initialize();
115115

116116
onRepositoryManagerCreated?.Invoke(RepositoryManager);

0 commit comments

Comments
 (0)