Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In case of reabese of repository with submodules, submodules are left… #1788

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5e36970
enumerate diff lines in patch changeset.
igadmg Mar 31, 2020
d522310
rebase with submodules fixed.
igadmg Apr 6, 2020
0041df5
added Common.props
igadmg Apr 10, 2020
d3893f0
Merge github.com:libgit2/libgit2sharp
igadmg Apr 25, 2020
d8ab449
Exception is thrown if file path is passed as remote to Commands.Fetch
igadmg Apr 25, 2020
8967743
In case of reabese of repository with submodules, submodules are left…
igadmg Apr 25, 2020
2dc649e
Added SubmoduleUpdateOptions to rebase options.
igadmg Jun 4, 2020
64f6962
Update RebaseOptions.cs
igadmg Jun 9, 2020
691f705
Merge branch 'master' of github.com:yatagarasu25/libgit2sharp
igadmg Dec 17, 2020
b0aae85
Merge branch 'master' of github.com:libgit2/libgit2sharp
igadmg Dec 17, 2020
697dadc
Merge branch 'master' of github.com:yatagarasu25/libgit2sharp
igadmg Dec 17, 2020
997fbb2
Merge branch 'master' of github.com:yatagarasu25/libgit2sharp
igadmg Dec 17, 2020
12d28e4
update.
igadmg Dec 17, 2020
e4eaa4e
Update on Command.Pull but it does not work as expected actually.
igadmg Dec 17, 2020
11b3c9b
update.
igadmg Dec 17, 2020
d240985
update.
igadmg Dec 17, 2020
3a8ca30
Merge D:\workspace\libgit2sharp
igadmg Dec 17, 2020
85a21cb
Merge D:\workspace\libgit2sharp
igadmg Dec 17, 2020
b36c410
update.
igadmg Jan 29, 2021
4c7ca57
Merge D:\workspace\GitKeeper\libgit2sharp
igadmg Oct 15, 2021
45df744
Update to netstandard 2.1
igadmg Oct 15, 2021
9b58d4c
Merge remote-tracking branch 'fork/master'
igadmg Mar 10, 2022
1053623
fixed for net472
igadmg Mar 10, 2022
4ff7a44
Update LibGit2Sharp.NativeBinaries to 2.0.315
bording Apr 1, 2022
e097d0b
React to ABI changes
bording Apr 2, 2022
d79fd3b
update
igadmg Jun 14, 2022
0492494
update
igadmg Jun 14, 2022
683880f
update
igadmg Jun 14, 2022
63541e4
Merge remote-tracking branch 'fork/libgit2-update'
igadmg Jun 14, 2022
4eea28e
update
igadmg Jun 14, 2022
158ff02
Merge remote-tracking branch 'fork/libgit2-update'
igadmg Jun 14, 2022
87f6eea
update
igadmg Jun 14, 2022
80ffa03
Merge branch 'master' of github.com:yatagarasu25/libgit2sharp
igadmg Jun 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$(SolutionDir)\Common.props" Condition="Exists('$(SolutionDir)\Common.props')" />

<PropertyGroup>
<TargetFrameworks Condition="'$(TargetFrameworks)'==''">net472;netcoreapp3.1;net6.0</TargetFrameworks>
</PropertyGroup>
Expand Down
23 changes: 19 additions & 4 deletions LibGit2Sharp/Commands/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ public static partial class Commands
/// <param name="repository">The repository.</param>
/// <param name="merger">The signature to use for the merge.</param>
/// <param name="options">The options for fetch and merging.</param>
public static MergeResult Pull(Repository repository, Signature merger, PullOptions options)
public static MergeResult Pull(Repository repository, Signature merger, PullOptions options = null)
{
Ensure.ArgumentNotNull(repository, "repository");
Ensure.ArgumentNotNull(merger, "merger");


options = options ?? new PullOptions();
Branch currentBranch = repository.Head;

if (!currentBranch.IsTracking)
Expand All @@ -34,7 +32,24 @@ public static MergeResult Pull(Repository repository, Signature merger, PullOpti
throw new LibGit2SharpException("No upstream remote for the current branch.");
}

Commands.Fetch(repository, currentBranch.RemoteName, new string[0], options.FetchOptions, null);
return Pull(repository, currentBranch.RemoteName, merger, options);
}

/// <summary>
/// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD.
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="remoteNameOrPath">The remote name or repository path.</param>
/// <param name="merger">The signature to use for the merge.</param>
/// <param name="options">The options for fetch and merging.</param>
public static MergeResult Pull(Repository repository, string remoteNameOrPath, Signature merger, PullOptions options = null)
{
Ensure.ArgumentNotNull(repository, "repository");
Ensure.ArgumentNotNull(merger, "merger");


options = options ?? new PullOptions();
Commands.Fetch(repository, remoteNameOrPath, new string[0], options.FetchOptions, null);
return repository.MergeFetchedRefs(merger, options.MergeOptions);
}
}
Expand Down
18 changes: 18 additions & 0 deletions LibGit2Sharp/ContentChangeLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
public class ContentChangeLine
{
public int OldLineNo;
public int NewLineNo;
public int NumLines;

internal ContentChangeLine(GitDiffLine line)
{
OldLineNo = line.OldLineNo;
NewLineNo = line.NewLineNo;
NumLines = line.NumLines;
}
}
}
44 changes: 32 additions & 12 deletions LibGit2Sharp/ContentChanges.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
Expand All @@ -11,9 +12,10 @@ namespace LibGit2Sharp
/// Holds the changes between two <see cref="Blob"/>s.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class ContentChanges
public class ContentChanges : IEnumerable<ContentChangeLine>
{
private readonly StringBuilder patchBuilder = new StringBuilder();
private readonly List<ContentChangeLine> lines = new List<ContentChangeLine>();

/// <summary>
/// Needed for mocking purposes.
Expand Down Expand Up @@ -106,17 +108,6 @@ private unsafe int LineCallback(git_diff_delta* delta, GitDiffHunk hunk, GitDiff
switch (line.lineOrigin)
{
case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
AddedLines.Add(new Line(line.NewLineNo, decodedContent));
LinesAdded++;
prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin });
break;

case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
DeletedLines.Add(new Line(line.OldLineNo, decodedContent));
LinesDeleted++;
prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin });
break;

case GitDiffLineOrigin.GIT_DIFF_LINE_CONTEXT:
prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin });
break;
Expand All @@ -126,11 +117,40 @@ private unsafe int LineCallback(git_diff_delta* delta, GitDiffHunk hunk, GitDiff
break;
}

AppendGitDiffLine(line, decodedContent);
AppendToPatch(prefix);
AppendToPatch(decodedContent);
return 0;
}

internal void AppendGitDiffLine(GitDiffLine line, string patch)
{
switch (line.lineOrigin)
{
case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
AddedLines.Add(new Line(line.NewLineNo, patch));
LinesAdded++;
lines.Add(new ContentChangeLine(line));
break;

case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
DeletedLines.Add(new Line(line.OldLineNo, patch));
LinesDeleted++;
lines.Add(new ContentChangeLine(line));
break;
}
}

public IEnumerator<ContentChangeLine> GetEnumerator()
{
return lines.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return lines.GetEnumerator();
}

private string DebuggerDisplay
{
get
Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp/Core/GitFetchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal class GitFetchOptions
public bool UpdateFetchHead = true;
public TagFetchMode download_tags;
public GitProxyOptions ProxyOptions;
public RemoteFollowRedirects FollowRedirects;
public GitStrArrayManaged CustomHeaders;
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/Core/GitPushOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal class GitPushOptions
public int PackbuilderDegreeOfParallelism;
public GitRemoteCallbacks RemoteCallbacks;
public GitProxyOptions ProxyOptions;
public RemoteFollowRedirects FollowRedirects;
public GitStrArrayManaged CustomHeaders;
}
}
2 changes: 2 additions & 0 deletions LibGit2Sharp/Core/GitStatusOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal class GitStatusOptions : IDisposable

public IntPtr Baseline = IntPtr.Zero;

public ushort RenameThreshold = 50;

public void Dispose()
{
PathSpec.Dispose();
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Core/GitWorktree.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace LibGit2Sharp.Core
{
Expand Down Expand Up @@ -37,6 +35,8 @@ internal class git_worktree_add_options
public int locked;

public IntPtr @ref = IntPtr.Zero;

public GitCheckoutOpts checkout_options;
}

[StructLayout(LayoutKind.Sequential)]
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static string GetGlobalSettingsNativeLibraryPath()
return Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension());
}

#if NETSTANDARD
#if NETSTANDARD || NET47_OR_GREATER
private static bool TryUseNativeLibrary() => false;
#else
private static bool TryUseNativeLibrary()
Expand Down
3 changes: 2 additions & 1 deletion LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2378,8 +2378,9 @@ public static unsafe RemoteHandle git_remote_lookup(RepositoryHandle repo, strin
git_remote* handle;
int res = NativeMethods.git_remote_lookup(out handle, repo, name);

if (res == (int)GitErrorCode.NotFound && !throwsIfNotFound)
if (!throwsIfNotFound)
{
if (res == (int)GitErrorCode.NotFound || res == (int)GitErrorCode.InvalidSpecification)
return null;
}

Expand Down
10 changes: 10 additions & 0 deletions LibGit2Sharp/Core/RemoteFollowRedirects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace LibGit2Sharp.Core
{
internal enum RemoteFollowRedirects
{
Unspecified = 0,
None = 1,
Initial = 2,
All = 4
}
}
15 changes: 11 additions & 4 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$(SolutionDir)\Common.props" Condition="Exists('$(SolutionDir)\Common.props')" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netcoreapp3.1;net472;net50;net60</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET</Description>
<Company>LibGit2Sharp contributors</Company>
Expand All @@ -16,6 +18,7 @@
<AssemblyOriginatorKeyFile>..\libgit2sharp.snk</AssemblyOriginatorKeyFile>
<PackageIcon>square-logo.png</PackageIcon>
<PackageLicenseFile>App_Readme/LICENSE.md</PackageLicenseFile>
<DelaySign>false</DelaySign>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Expand All @@ -30,9 +33,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="[2.0.315-alpha.0.9]" PrivateAssets="none" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220" PrivateAssets="all" />
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.315" PrivateAssets="none" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
</ItemGroup>

<Import Project="..\Targets\CodeGenerator.targets" />
Expand Down
6 changes: 2 additions & 4 deletions LibGit2Sharp/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,17 @@ private unsafe int PrintCallBack(git_diff_delta* delta, GitDiffHunk hunk, GitDif

case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
linesAdded++;
currentChange.LinesAdded++;
currentChange.AddedLines.Add(new Line(line.NewLineNo, patchPart));
prefix = "+";
break;

case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
linesDeleted++;
currentChange.LinesDeleted++;
currentChange.DeletedLines.Add(new Line(line.OldLineNo, patchPart));
prefix = "-";
break;
}

currentChange.AppendGitDiffLine(line, patchPart);

string formattedOutput = string.Concat(prefix, patchPart);

fullPatchBuilder.Append(formattedOutput);
Expand Down
74 changes: 63 additions & 11 deletions LibGit2Sharp/Rebase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,56 @@ unsafe AnnotatedCommitHandle AnnotatedCommitHandleFromRefHandle(ReferenceHandle
Proxy.git_annotated_commit_from_ref(this.repository.Handle, refHandle);
}

ReferenceHandle RefHandleFrom(Branch b) =>
(b == null) ? null : this.repository.Refs.RetrieveReferencePtr(b.CanonicalName);

ReferenceHandle RefHandleFrom(string name) =>
(name == null) ? null : this.repository.Refs.RetrieveReferencePtr(name);

class RebaseReferenceGuard : IDisposable
{
Reference rf;
Action<Reference> disposeFn;

public RebaseReferenceGuard(Reference rf_, Action<Reference> disposeFn_)
{
rf = rf_;
disposeFn = disposeFn_;
}

public string CanonicalName => rf.CanonicalName;

public void Dispose()
{
disposeFn(rf);
}
}

RebaseReferenceGuard ReferenceFrom(Commit c)
{
if (c == null)
return null;

var rfname = $"refs/rebase/{c.Sha}";
var rf = this.repository.Refs.Resolve<Reference>(rfname);
rf = rf ?? this.repository.Refs.Add(rfname, c.Id);

return new RebaseReferenceGuard(rf, r => { try { this.repository.Refs.Remove(r); } catch { }});
}

public virtual RebaseResult Start(Commit annotated, Commit upstream, Commit onto, Identity committer, RebaseOptions options)
{
Ensure.ArgumentNotNull(upstream, "upstream");

// TODO: Rebase does not work with just references, is that a bug or design feature?
using (var annotatedRef = ReferenceFrom(annotated))
using (var upstreamRef = ReferenceFrom(upstream))
using (var ontoRef = ReferenceFrom(onto))
using (ReferenceHandle annotatedRefPtr = RefHandleFrom(annotatedRef?.CanonicalName))
using (ReferenceHandle upstreamRefPtr = RefHandleFrom(upstreamRef?.CanonicalName))
using (ReferenceHandle ontoRefPtr = RefHandleFrom(ontoRef?.CanonicalName))
return Start(annotatedRefPtr, upstreamRefPtr, ontoRefPtr, committer, options);
}
/// <summary>
/// Start a rebase operation.
/// </summary>
Expand All @@ -82,6 +132,16 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, I
{
Ensure.ArgumentNotNull(upstream, "upstream");

using (ReferenceHandle branchRefPtr = RefHandleFrom(branch))
using (ReferenceHandle upstreamRefPtr = RefHandleFrom(upstream))
using (ReferenceHandle ontoRefPtr = RefHandleFrom(onto))
return Start(branchRefPtr, upstreamRefPtr, ontoRefPtr, committer, options);
}

internal virtual RebaseResult Start(ReferenceHandle annotatedRefPtr, ReferenceHandle upstreamRefPtr, ReferenceHandle ontoRefPtr, Identity committer, RebaseOptions options)
{
Ensure.ArgumentNotNull(upstreamRefPtr, "upstream");

options = options ?? new RebaseOptions();

EnsureNonBareRepo();
Expand All @@ -92,13 +152,6 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, I
this.repository.Info.CurrentOperation);
}

Func<Branch, ReferenceHandle> RefHandleFromBranch = (Branch b) =>
{
return (b == null) ?
null :
this.repository.Refs.RetrieveReferencePtr(b.CanonicalName);
};

using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
{
GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
Expand All @@ -107,10 +160,7 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, I
checkout_options = checkoutOptionsWrapper.Options,
};

using (ReferenceHandle branchRefPtr = RefHandleFromBranch(branch))
using (ReferenceHandle upstreamRefPtr = RefHandleFromBranch(upstream))
using (ReferenceHandle ontoRefPtr = RefHandleFromBranch(onto))
using (AnnotatedCommitHandle annotatedBranchCommitHandle = AnnotatedCommitHandleFromRefHandle(branchRefPtr))
using (AnnotatedCommitHandle annotatedBranchCommitHandle = AnnotatedCommitHandleFromRefHandle(annotatedRefPtr))
using (AnnotatedCommitHandle upstreamRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(upstreamRefPtr))
using (AnnotatedCommitHandle ontoRefAnnotatedCommitHandle = AnnotatedCommitHandleFromRefHandle(ontoRefPtr))
using (RebaseHandle rebaseOperationHandle = Proxy.git_rebase_init(this.repository.Handle,
Expand All @@ -119,6 +169,8 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, I
ontoRefAnnotatedCommitHandle,
gitRebaseOptions))
{
this.repository.Submodules.UpdateAll(options.SubmoduleUpdateOptions);

RebaseResult rebaseResult = RebaseOperationImpl.Run(rebaseOperationHandle,
this.repository,
committer,
Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp/RebaseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public sealed class RebaseOptions : IConvertableToGitCheckoutOpts
/// </summary>
public CheckoutFileConflictStrategy FileConflictStrategy { get; set; }

/// <summary>
/// Submodule update options passed to submodule updates on rebase step.
/// </summary>
public SubmoduleUpdateOptions SubmoduleUpdateOptions { get; set; }

CheckoutCallbacks IConvertableToGitCheckoutOpts.GenerateCallbacks()
{
return CheckoutCallbacks.From(OnCheckoutProgress, OnCheckoutNotify);
Expand Down