Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GitIntegration.Test/Builders/GitPatchBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void BuildsTheDefaultPatchVector()
"--no-color",
"--src-prefix=a/",
"--dst-prefix=b/",
"--submodule=short",
"-U3",
"--no-renames",
];
Expand Down
48 changes: 48 additions & 0 deletions GitIntegration.Test/Integration/GitSubmoduleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ktsu.GitIntegration.Test;

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -164,6 +165,53 @@
Assert.AreNotEqual(after[0].Sha, after[0].CheckedOutSha);
}

[TestMethod]
[DataRow("log")]
[DataRow("diff")]
public async Task PatchReportsAMovedSubmoduleAsItsGitlinkWhateverDiffSubmoduleSaysAsync(string format)
{
CancellationToken cancellationToken = TestContext.CancellationTokenSource.Token;

Check warning on line 173 in GitIntegration.Test/Integration/GitSubmoduleTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'TestContext.CancellationToken' instead of 'TestContext.CancellationTokenSource.Token'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_GitIntegration&issues=AaDt2ZFEHmxAf3IaaJkM&open=AaDt2ZFEHmxAf3IaaJkM&pullRequest=160
await IntegrationGitFixture.RequireGitAsync(cancellationToken).ConfigureAwait(false);

using TemporaryRepository subDirectory = new();
using TemporaryRepository superDirectory = new();

GitRepository sub = await CreateRepositoryAsync(subDirectory, "s.txt", cancellationToken).ConfigureAwait(false);
GitRepository super = await CreateRepositoryAsync(superDirectory, "m.txt", cancellationToken).ConfigureAwait(false);

await AddSubmoduleAsync(super, sub.LocalPath!, "libs/sub", cancellationToken).ConfigureAwait(false);

// Move the submodule's checkout on by a commit, so the superproject sees its gitlink change.
GitRepository checkout = new()
{
LocalPath = System.IO.Path.Join(superDirectory.RootPath, "libs", "sub").As<AbsoluteDirectoryPath>(),
ProcessRunner = super.ProcessRunner,
};

await IntegrationGitFixture.ConfigureIdentityAsync(checkout, AuthorName, AuthorEmail, cancellationToken)
.ConfigureAwait(false);

superDirectory.WriteFile("libs/sub/s.txt", "two\n");
_ = await checkout.Add().All().ExecuteAsync(cancellationToken).ConfigureAwait(false);
_ = await checkout.Commit("c2".As<GitCommitMessage>()).ExecuteAsync(cancellationToken).ConfigureAwait(false);

// Written into the superproject's own config, which is the nearest scope git reads it from.
_ = await new GitTextBuilder(super.ProcessRunner!, super.LocalPath, "config", "diff.submodule", format)
.ExecuteAsync(cancellationToken).ConfigureAwait(false);

GitPatch patch = await super.Patch().ExecuteAsync(cancellationToken).ConfigureAwait(false);

// "log" left the change out entirely, and "diff" reported libs/sub/s.txt in its place
// (ktsu-dev/GitIntegration#124).
GitFilePatch file = patch.Files.Single();
Assert.AreEqual("libs/sub".As<RelativeFilePath>(), file.Path);

_ = await super.Apply(file.PatchFor(file.Hunks)).ToIndex().ExecuteAsync(cancellationToken).ConfigureAwait(false);

GitPatch staged = await super.Patch().Staged().ExecuteAsync(cancellationToken).ConfigureAwait(false);
Assert.AreEqual("libs/sub".As<RelativeFilePath>(), staged.Files.Single().Path);
}

[TestMethod]
public async Task ReportsAnUninitializedSubmoduleAndThenUpdatesItAsync()
{
Expand Down
6 changes: 6 additions & 0 deletions GitIntegration/Builders/GitPatchBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ protected override void AppendVerbArguments(ICollection<string> arguments)
arguments.Add("--src-prefix=a/");
arguments.Add("--dst-prefix=b/");

// diff.submodule=log prints a moved submodule as a "Submodule sub a..b:" summary with no
// diff --git block, so the change is missing from the patch, and =diff prints the
// submodule's own files as if they were the superproject's, which apply then refuses.
// Only the short form is a gitlink patch that stages (ktsu-dev/GitIntegration#124).
arguments.Add("--submodule=short");

if (_staged)
{
arguments.Add("--cached");
Expand Down
Loading