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

Commit 1b48431

Browse files
committed
Add branch methods to Repository and fix handler hookups
1 parent 1c27f01 commit 1b48431

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

src/GitHub.Api/Git/IRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,8 @@ public interface IRepository : IEquatable<IRepository>, IDisposable
7575
ITask RemoteAdd(string remote, string url);
7676
ITask RemoteRemove(string remote);
7777
ITask Push(string remote);
78+
ITask DeleteBranch(string branch, bool force);
79+
ITask CreateBranch(string branch, string baseBranch);
80+
ITask SwitchBranch(string branch);
7881
}
7982
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ public ITask SetupRemote(string remote, string remoteUrl)
122122
public ITask DiscardChanges(GitStatusEntry[] gitStatusEntry) => repositoryManager.DiscardChanges(gitStatusEntry);
123123
public ITask RemoteAdd(string remote, string url) => repositoryManager.RemoteAdd(remote, url);
124124
public ITask RemoteRemove(string remote) => repositoryManager.RemoteRemove(remote);
125+
public ITask DeleteBranch(string branch, bool force) => repositoryManager.DeleteBranch(branch, force);
126+
public ITask CreateBranch(string branch, string baseBranch) => repositoryManager.CreateBranch(branch, baseBranch);
127+
public ITask SwitchBranch(string branch) => repositoryManager.SwitchBranch(branch);
125128

126129
public void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent) => cacheContainer.CheckAndRaiseEventsIfCacheNewer(cacheType, cacheUpdateEvent);
127130

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,14 @@ public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)
330330

331331
if (itemsToRevert.Any())
332332
{
333-
task.Then(GitClient.Discard(itemsToRevert));
333+
var next = GitClient.Discard(itemsToRevert);
334+
HookupHandlers(next, true);
335+
task.OnEnd -= HookupEndHandlerWithWatcher;
336+
task.Then(next);
334337
}
335338
}
336339
, () => gitStatusEntries);
337340

338-
339341
return HookupHandlers(task, true);
340342
}
341343

@@ -459,21 +461,37 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
459461
}
460462
};
461463

462-
task.Finally(success =>
464+
if (filesystemChangesExpected)
465+
task.OnEnd += HookupEndHandlerWithWatcher;
466+
else
467+
task.OnEnd += HookupEndHandlerWithoutWatcher;
468+
return task;
469+
}
470+
471+
private void HookupEndHandlerWithWatcher(ITask task, bool success, Exception ex)
472+
{
473+
HookupEndHandler(task, true);
474+
}
475+
476+
private void HookupEndHandlerWithoutWatcher(ITask task, bool success, Exception ex)
477+
{
478+
HookupEndHandler(task, false);
479+
}
480+
481+
private void HookupEndHandler(ITask task, bool filesystemChangesExpected)
482+
{
483+
var isExclusive = task.IsChainExclusive();
484+
if (filesystemChangesExpected)
463485
{
464-
if (filesystemChangesExpected)
465-
{
466-
//Logger.Trace("Ended Operation - Enable Watcher");
467-
watcher.Start();
468-
}
486+
//Logger.Trace("Ended Operation - Enable Watcher");
487+
watcher.Start();
488+
}
469489

470-
if (isExclusive)
471-
{
472-
//Logger.Trace("Ended Operation - Clearing Busy Flag");
473-
IsBusy = false;
474-
}
475-
});
476-
return task;
490+
if (isExclusive)
491+
{
492+
//Logger.Trace("Ended Operation - Clearing Busy Flag");
493+
IsBusy = false;
494+
}
477495
}
478496

479497
private string GetCurrentHead()

0 commit comments

Comments
 (0)