Skip to content

Commit 722ac26

Browse files
committed
Rebase operations in a bare repository should throw
1 parent 4dffa40 commit 722ac26

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,21 @@ public void CanRebaseHandlePatchAlreadyApplied()
539539
}
540540
}
541541

542+
[Fact]
543+
public void RebasingInBareRepositoryThrows()
544+
{
545+
string path = SandboxBareTestRepo();
546+
using (var repo = new Repository(path))
547+
{
548+
Branch rebaseUpstreamBranch = repo.Branches["refs/heads/test"];
549+
550+
Assert.NotNull(rebaseUpstreamBranch);
551+
Assert.Throws<BareRepositoryException>(() => repo.Rebase.Start(null, rebaseUpstreamBranch, null, Constants.Identity, new RebaseOptions()));
552+
Assert.Throws<BareRepositoryException>(() => repo.Rebase.Continue(Constants.Identity, new RebaseOptions()));
553+
Assert.Throws<BareRepositoryException>(() => repo.Rebase.Abort());
554+
}
555+
}
556+
542557
private void ConstructRebaseTestRepository(Repository repo)
543558
{
544559
// Constructs a graph that looks like:

LibGit2Sharp/Rebase.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, I
7979

8080
options = options ?? new RebaseOptions();
8181

82+
EnsureNonBareRepo();
83+
8284
if (this.repository.Info.CurrentOperation != CurrentOperation.None)
8385
{
8486
throw new LibGit2SharpException(string.Format(
@@ -140,6 +142,8 @@ public virtual RebaseResult Continue(Identity committer, RebaseOptions options)
140142

141143
options = options ?? new RebaseOptions();
142144

145+
EnsureNonBareRepo();
146+
143147
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
144148
{
145149
GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
@@ -201,6 +205,8 @@ public virtual void Abort(RebaseOptions options)
201205
{
202206
options = options ?? new RebaseOptions();
203207

208+
EnsureNonBareRepo();
209+
204210
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
205211
{
206212
GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
@@ -243,5 +249,13 @@ public virtual RebaseStepInfo GetCurrentStepInfo()
243249
return stepInfo;
244250
}
245251
}
252+
253+
private void EnsureNonBareRepo()
254+
{
255+
if (this.repository.Info.IsBare)
256+
{
257+
throw new BareRepositoryException("Rebase operations in a bare repository are not supported.");
258+
}
259+
}
246260
}
247261
}

0 commit comments

Comments
 (0)