8000 Move operations that work on an existing rebase into Rebase namespace · SinghVarun/libgit2sharp@f5963ad · GitHub
[go: up one dir, main page]

Skip to content

Commit f5963ad

Browse files
committed
Move operations that work on an existing rebase into Rebase namespace
1 parent e6091de commit f5963ad

File tree

5 files changed

+58
-62
lines changed

5 files changed

+58
-62
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void CanContinueRebase()
114114

115115
Assert.True(repo.Index.IsFullyMerged);
116116

117-
RebaseResult continuedRebaseResult = repo.CurrentRebaseOperation.Continue(Constants.Signature, options);
117+
RebaseResult continuedRebaseResult = repo.RebaseOperation.Continue(Constants.Signature, options);
118118

119119
Assert.NotNull(continuedRebaseResult);
120120
Assert.Equal(RebaseStatus.Complete, continuedRebaseResult.Status);
@@ -155,7 +155,7 @@ public void CanQueryRebaseOperation()
155155
Assert.Equal(0, rebaseResult.CompletedStepCount);
156156
Assert.Equal(3, rebaseResult.TotalStepCount);
157157

158-
RebaseStepInfo info = repo.CurrentRebaseOperation.CurrentStepInfo;
158+
RebaseStepInfo info = repo.RebaseOperation.GetCurrentStepInfo();
159159
Assert.Equal(0, info.StepIndex);
160160
Assert.Equal(3, info.TotalStepCount);
161161
Assert.Equal(RebaseStepOperation.Pick, info.Type);
@@ -187,7 +187,7 @@ public void CanAbortRebase()
187187
Assert.Equal(0, rebaseResult.CompletedStepCount);
188188
Assert.Equal(3, rebaseResult.TotalStepCount);
189189

190-
repo.CurrentRebaseOperation.Abort(Constants.Signature);
190+
repo.RebaseOperation.Abort(Constants.Signature);
191191
Assert.False(repo.RetrieveStatus().IsDirty);
192192
Assert.True(repo.Index.IsFullyMerged);
193193
Assert.Equal(CurrentOperation.None, repo.Info.CurrentOperation);
@@ -223,7 +223,7 @@ public void RebaseWhileAlreadyRebasingThrows()
223223
}
224224

225225
[Fact]
226-
public void CurrentRebaseOperationIsNullWhenNotRebasing()
226+
public void CurrentStepInfoIsNullWhenNotRebasing()
227227
{
228228
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
229229
var path = Repository.Init(scd.DirectoryPath);
@@ -232,12 +232,13 @@ public void CurrentRebaseOperationIsNullWhenNotRebasing()
232232
ConstructRebaseTestRepository(repo);
233233
repo.Checkout(topicBranch1Name);
234234

235-
Assert.Null(repo.CurrentRebaseOperation);
235+
Assert.Null(repo.RebaseOperation.GetCurrentStepInfo());
236236
}
237237
}
238238

239239
private void ConstructRebaseTestRepository(Repository repo)
240240
{
241+
// Constructs a graph that looks like:
241242
// * -- * -- * (modifications to c.txt)
242243
// / |
243244
// / T2
@@ -256,8 +257,6 @@ private void ConstructRebaseTestRepository(Repository repo)
256257

257258
string filePathA = "a.txt";
258259
const string fileContentA1 = "A1";
259-
// const string fileContentA2 = "A2";
260-
// const string fileContentA3 = "A3";
261260

262261
string filePathB = "b.txt";
263262
const string fileContentB1 = "B1";

LibGit2Sharp/Core/Proxy.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,7 @@ public static void git_rebase_abort(
17061706
RebaseSafeHandle rebase,
17071707
Signature signature)
17081708
{
1709+
Ensure.ArgumentNotNull(rebase, "rebase");
17091710
Ensure.ArgumentNotNull(signature, "signature");
17101711

17111712
using (ThreadAffinity())
@@ -1716,16 +1717,17 @@ public static void git_rebase_abort(
17161717
}
17171718

17181719
public static void git_rebase_finish(
1719-
RebaseSafeHandle repo,
1720+
RebaseSafeHandle rebase,
17201721
Signature signature,
17211722
GitRebaseOptions options)
17221723
{
1724+
Ensure.ArgumentNotNull(rebase, "rebase");
17231725
Ensure.ArgumentNotNull(signature, "signature");
17241726

17251727
using (ThreadAffinity())
17261728
using (var signatureHandle = signature.BuildHandle())
17271729
{
1728-
int result = NativeMethods.git_rebase_finish(repo, signatureHandle, ref options);
1730+
int result = NativeMethods.git_rebase_finish(rebase, signatureHandle, ref options);
17291731
Ensure.ZeroResult(result);
17301732
}
17311733
}

LibGit2Sharp/IRepository.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,9 @@ public interface IRepository : IDisposable
235235
RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signature committer, RebaseOptions options);
236236

237237
/// <summary>
238-
/// Get the current rebase operation in progress (if any).
239-
/// Currently only returns for rebase merge. If a rebase merge
240-
/// operation is not progress, returns null.
238+
/// Access to Rebase functionality.
241239
/// </summary>
242-
RebaseOperation CurrentRebaseOperation { get; }
240+
Rebase RebaseOperation { get; }
243241

244242
/// <summary>
245243
/// Merge the reference that was recently fetched. This will merge

LibGit2Sharp/RebaseOperation.cs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ public enum RebaseStepOperation
4949
/// <summary>
5050
/// Encapsulates a rebase operation.
5151
/// </summary>
52-
public class RebaseOperation
52+
public class Rebase
5353
{
5454
internal readonly Repository repository;
5555

5656
/// <summary>
5757
/// Needed for mocking purposes.
5858
/// </summary>
59-
protected RebaseOperation()
59+
protected Rebase()
6060
{ }
6161

62-
internal RebaseOperation(Repository repo)
62+
internal Rebase(Repository repo)
6363
{
6464
10000 this.repository = repo;
6565
}
@@ -80,21 +80,21 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
8080
{
8181
rebase = Proxy.git_rebase_open(repository.Handle);
8282

83-
// Get information on the current step
84-
int currentStepIndex = Proxy.git_rebase_operation_current(rebase);
85-
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebase);
86-
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebase, currentStepIndex);
87-
88-
GitOid id = Proxy.git_rebase_commit(rebase, null, committer);
89-
9083
// Report that we just completed the step
9184
if (options.RebaseStepCompleted != null)
9285
{
86+
// Get information on the current step
87+
int currentStepIndex = Proxy.git_rebase_operation_current(rebase);
88+
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebase);
89+
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebase, currentStepIndex);
90+
9391
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
9492
new ObjectId(gitRebasestepInfo.id),
9593
LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo.exec),
9694
currentStepIndex,
9795
totalStepCount);
96+
97+
GitOid id = Proxy.git_rebase_commit(rebase, null, committer);
9898
options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, new ObjectId(id)));
9999
}
100100

@@ -140,30 +140,32 @@ public virtual void Skip()
140140
/// <summary>
141141
/// The info on the current step.
142142
/// </summary>
143-
public virtual RebaseStepInfo CurrentStepInfo
143+
public virtual RebaseStepInfo GetCurrentStepInfo()
144144
{
145-
get
145+
if (repository.Info.CurrentOperation != LibGit2Sharp.CurrentOperation.RebaseMerge)
146146
{
147-
RebaseSafeHandle rebaseHandle = null;
147+
return null;
148+
}
148149

149-
try
150-
{
151-
rebaseHandle = Proxy.git_rebase_open(repository.Handle);
152-
int currentStepIndex = Proxy.git_rebase_operation_current(rebaseHandle);
153-
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseHandle);
154-
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebaseHandle, currentStepIndex);
155-
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
156-
gitRebasestepInfo.id,
157-
LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo.exec),
158-
currentStepIndex,
159-
totalStepCount);
160-
return stepInfo;
161-
}
162-
finally
163-
{
164-
rebaseHandle.SafeDispose();
165-
rebaseHandle = null;
166-
}
150+
RebaseSafeHandle rebaseHandle = null;
151+
152+
try
153+
{
154+
rebaseHandle = Proxy.git_rebase_open(repository.Handle);
155+
int currentStepIndex = Proxy.git_rebase_operation_current(rebaseHandle);
156+
int totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseHandle);
157+
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebaseHandle, currentStepIndex);
158+
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
159+
gitRebasestepInfo.id,
160+
LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo.exec),
161+
currentStepIndex,
162+
totalStepCount);
163+
return stepInfo;
164+
}
165+
finally
166+
{
167+
rebaseHandle.SafeDispose();
168+
rebaseHandle = null;
167169
}
168170
}
169171
}

LibGit2Sharp/Repository.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public sealed class Repository : IRepository
3232
private readonly NoteCollection notes;
3333
private readonly Lazy<ObjectDatabase> odb;
3434
private readonly Lazy<Network> network;
35+
private readonly Lazy<Rebase> rebaseOperation;
3536
private readonly Stack<IDisposable> toCleanup = new Stack<IDisposable>();
3637
private readonly Ignore ignore;
3738
private readonly SubmoduleCollection submodules;
@@ -117,6 +118,7 @@ public Repository(string path, RepositoryOptions options = null)
117118
notes = new NoteCollection(this);
118119
ignore = new Ignore(this);
119120
network = new Lazy<Network>(() => new Network(this));
121+
rebaseOperation = new Lazy<Rebase>(() => new Rebase(this));
120122
pathCase = new Lazy<PathCase>(() => new PathCase(this));
121123
submodules = new SubmoduleCollection(this);
122124

@@ -257,6 +259,17 @@ public Network Network
257259
}
258260
}
259261

262+
/// <summary>
263+
/// Provides access to network functionality for a repository.
264+
/// </summary>
265+
public Rebase RebaseOperation
266+
{
267+
get
268+
{
269+
return rebaseOperation.Value;
270+
}
271+
}
272+
260273
/// <summary>
261274
/// Gets the database.
262275
/// </summary>
@@ -1166,24 +1179,6 @@ public RebaseResult Rebase(Branch branch, Branch upstream, Branch onto, Signatur
11661179
}
11671180
}
11681181

1169-
/// <summary>
1170-
/// Get the current rebase operation in progress (if any).
1171-
/// Currently only returns for rebase merge. If a rebase merge
1172-
/// operation is not progress, returns null.
1173-
/// </summary>
1174-
public RebaseOperation CurrentRebaseOperation
1175-
{
1176-
get
1177-
{
1178-
if (Info.CurrentOperation == LibGit2Sharp.CurrentOperation.RebaseMerge)
1179-
{
1180-
return new RebaseOperation(this);
1181-
}
1182-
1183-
return null;
1184-
}
1185-
}
1186-
11871182
/// <summary>
11881183
/// Revert the specified commit.
11891184
/// <para>

0 commit comments

Comments
 (0)
0