8000 Recursive clone notifications should report the remote's URL · odedw/libgit2sharp@00e7ead · GitHub
[go: up one dir, main page]

Skip to content

Commit 00e7ead

Browse files
committed
Recursive clone notifications should report the remote's URL
1 parent 873e1c1 commit 00e7ead

File tree

6 files changed

+78
-19
lines changed

6 files changed

+78
-19
lines changed

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ private class CloneCallbackInfo
255255
/// </summary>
256256
public bool CheckoutProgressCalled { get; set; }
257257

258+
/// <summary>
259+
/// The reported remote URL.
260+
/// </summary>
261+
public string RemoteUrl { get; set; }
262+
258263
/// <summary>
259264
/// Was remote ref update called.
260265
/// </summary>
@@ -272,6 +277,9 @@ private class CloneCallbackInfo
272277
/// </summary>
273278
public bool FinishedWorkInRepositoryCalled { get; set; }
274279

280+
/// <summary>
281+
/// The reported recursion depth.
282+
/// </summary>
275283
public int RecursionDepth { get; set; }
276284
}
277285

@@ -282,6 +290,10 @@ public void CanRecursivelyCloneSubmodules()
282290
var scd = BuildSelfCleaningDirectory();
283291
string relativeSubmodulePath = "submodule_target_wd";
284292

293+
// Construct the expected URL the submodule will clone from.
294+
string expectedSubmoduleUrl = Path.Combine(Path.GetDirectoryName(uri.AbsolutePath), relativeSubmodulePath);
295+
expectedSubmoduleUrl = expectedSubmoduleUrl.Replace('\\', '/');
296+
285297
Dictionary<string, CloneCallbackInfo> callbacks = new Dictionary<string, CloneCallbackInfo>();
286298

287299
CloneCallbackInfo currentEntry = null;
@@ -329,6 +341,7 @@ public void CanRecursivelyCloneSubmodules()
329341
currentEntry = new CloneCallbackInfo();
330342
currentEntry.StartingWorkInRepositoryCalled = true;
331343
currentEntry.RecursionDepth = x.RecursionDepth;
344+
currentEntry.RemoteUrl = x.RemoteUrl;
332345
callbacks.Add(x.RepositoryPath, currentEntry);
333346

334347
return true;
@@ -374,6 +387,7 @@ public void CanRecursivelyCloneSubmodules()
374387
expectedCallbackInfo.Add(workDirPath, new CloneCallbackInfo()
375388
{
376389
RecursionDepth = 0,
390+
RemoteUrl = uri.AbsolutePath,
377391
StartingWorkInRepositoryCalled = true,
378392
FinishedWorkInRepositoryCalled = true,
379393
CheckoutProgressCalled = true,
@@ -383,6 +397,7 @@ public void CanRecursivelyCloneSubmodules()
383397
expectedCallbackInfo.Add(Path.Combine(workDirPath, relativeSubmodulePath), new CloneCallbackInfo()
384398
{
385399
RecursionDepth = 1,
400+
RemoteUrl = expectedSubmoduleUrl,
386401
StartingWorkInRepositoryCalled = true,
387402
FinishedWorkInRepositoryCalled = true,
388403
CheckoutProgressCalled = true,
@@ -395,6 +410,7 @@ public void CanRecursivelyCloneSubmodules()
395410
CloneCallbackInfo entry = null;
396411
Assert.True(callbacks.TryGetValue(kvp.Key, out entry), string.Format("{0} was not found in callbacks.", kvp.Key));
397412

413+
Assert.Equal(kvp.Value.RemoteUrl, entry.RemoteUrl);
398414
Assert.Equal(kvp.Value.RecursionDepth, entry.RecursionDepth);
399415
Assert.Equal(kvp.Value.StartingWorkInRepositoryCalled, entry.StartingWorkInRepositoryCalled);
400416
Assert.Equal(kvp.Value.FinishedWorkInRepositoryCalled, entry.FinishedWorkInRepositoryCalled);

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,12 @@ internal static extern int git_submodule_lookup(
13601360
RepositorySafeHandle repo,
13611361
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath name);
13621362

1363+
[DllImport(libgit2)]
1364+
internal static extern int git_submodule_resolve_url(
1365+
GitBuf buf,
1366+
RepositorySafeHandle repo,
1367+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
1368+
13631369
[DllImport(libgit2)]
13641370
internal static extern int git_submodule_update(
13651371
SubmoduleSafeHandle sm,

LibGit2Sharp/Core/Proxy.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,18 @@ public static SubmoduleSafeHandle git_submodule_lookup(RepositorySafeHandle repo
27702770
}
27712771
}
27722772

2773+
public static string git_submodule_resolve_url(RepositorySafeHandle repo, string url)
2774+
{
2775+
using (ThreadAffinity())
2776+
using (var buf = new GitBuf())
2777+
{
2778+
int res = NativeMethods.git_submodule_resolve_url(buf, repo, url);
2779+
2780+
Ensure.ZeroResult(res);
2781+
return LaxUtf8Marshaler.FromNative(buf.ptr);
2782+
}
2783+
}
2784+
27732785
public static ICollection<TResult> git_submodule_foreach<TResult>(RepositorySafeHandle repo, Func<IntPtr, IntPtr, TResult> resultSelector)
27742786
{
27752787
return git_foreach(resultSelector, c => NativeMethods.git_submodule_foreach(repo, (x, y, p) => c(x, y, p), IntPtr.Zero));

LibGit2Sharp/Handlers.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace LibGit2Sharp.Handlers
4242
/// Delegate definition to indicate that a repository is about to be operated on.
4343
/// (In the context of a recursive operation).
4444
/// </summary>
45-
/// <param name="context"></param>
45+
/// <param name="context">Context on the repository that is being operated on.</param>
4646
/// <returns>true to continue, false to cancel.</returns>
4747
public delegate bool RepositoryOperationStarting(RepositoryOperationContext context);
4848

@@ -51,12 +51,14 @@ namespace LibGit2Sharp.Handlers
5151
/// (In the context of a recursive operation).
5252
/// </summary>
5353
/// <remarks>
54-
/// If an exception is raised when recursing through submodules, and this exception
55-
/// is not bubled through the calling function, then it is reported through this
56-
/// callback.
54+
/// Exceptions that occur as part of recursing through submodules are not thrown up through
55+
/// the calling function. If an exception is raised when recursing through submodules, and
56+
/// this exception is not bubbled through the calling function, then it is reported through
57+
/// this callback.
5758
/// </remarks>
58-
/// <param name="context"></param>
59-
/// <param name="recursiveException"></param>
59+
/// <param name="context">Context on the repository that is being operated on.</param>
60+
/// <param name="recursiveException">The exception that occured as part of working on
61+
/// this repository, if it is not bubbled up through the calling function.</param>
6062
public delegate void RepositoryOperationCompleted(RepositoryOperationContext context, Exception recursiveException);
6163

6264
/// <summary>

LibGit2Sharp/Repository.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@ public static string Discover(string startingPath)
541541
/// <summary>
542542
/// Clone with specified options.
543543
/// </summary>
544+
/// <remarks>
545+
/// Exceptions that occur as part of recursing through submodules are not thrown up through
546+
/// the calling function. If an exception is raised when recursing through submodules, and
547+
/// this exception is not bubbled through the calling function, then it is reported through
548+
/// this callback.
549+
/// </remarks>
544550
/// <param name="sourceUrl">URI for the remote repository</param>
545551
/// <param name="workdirPath">Local path to clone into</param>
546552
/// <param name="options"><see cref="CloneOptions"/> controlling clone behavior</param>
@@ -556,7 +562,7 @@ public static string Clone(string sourceUrl, string workdirPath,
556562

557563
// context variable that contains information on the repository that
558564
// we are cloning.
559-
var context = new RepositoryOperationContext(Path.GetFullPath(workdirPath));
565+
var context = new RepositoryOperationContext(Path.GetFullPath(workdirPath), sourceUrl);
560566

561567
// Notify caller that we are starting to work with the current repository.
562568
bool continueOperation = OnRepositoryOperationStarting(options.RepositoryOperationStarting,
@@ -640,7 +646,13 @@ private static bool RecursivelyCloneSubmodules(CloneOptions options, string repo
640646
{
641647
string fullSubmodulePath = Path.Combine(parentRepoWorkDir, sm.Path);
642648

649+
650+
// Resolve the URL in the .gitmodule file to the one actually used
651+
// to clone
652+
string resolvedUrl = Proxy.git_submodule_resolve_url(repo.Handle, sm.Url);
653+
643654
var context = new RepositoryOperationContext(fullSubmodulePath,
655+
resolvedUrl,
644656
parentRepoWorkDir,
645657
sm.Name,
646658
recursionDepth);

LibGit2Sharp/RepositoryOperationContext.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,53 @@ protected RepositoryOperationContext()
2121
/// Constructor suitable for use on the repository the main
2222
/// operation is being run on (i.e. the super project, not a submodule).
2323
/// </summary>
24-
/// <param name="repositoryPath"></param>
25-
internal RepositoryOperationContext(string repositoryPath)
26-
: this(repositoryPath, string.Empty, string.Empty, 0)
24+
/// <param name="repositoryPath">The path of the repository being operated on.</param>
25+
/// <param name="remoteUrl">The URL that this operation will download from.</param>
26+
internal RepositoryOperationContext(string repositoryPath, string remoteUrl)
27+
: this(repositoryPath, remoteUrl, string.Empty, string.Empty, 0)
2728
{
2829
}
2930

3031
/// <summary>
3132
/// Constructor suitable for use on the sub repositories.
3233
/// </summary>
33-
/// <param name="repositoryPath"></param>
34-
/// <param name="parentRepositoryPath"></param>
35-
/// <param name="submoduleName"></param>
36-
/// <param name="recursionDepth"></param>
37-
internal RepositoryOperationContext(string repositoryPath, string parentRepositoryPath, string submoduleName, int recursionDepth)
34+
/// <param name="repositoryPath">The path of the repository being operated on.</param>
35+
/// <param name="remoteUrl">The URL that this operation will download from.</param>
36+
/// <param name="parentRepositoryPath">The path to the super repository.</param>
37+
/// <param name="submoduleName">The logical name of this submodule.</param>
38+
/// <param name="recursionDepth">The depth of this sub repository from the original super repository.</param>
39+
internal RepositoryOperationContext(string repositoryPath,
40+
string remoteUrl,
41+
string parentRepositoryPath,
42+
string submoduleName, int recursionDepth)
3843
{
3944
RepositoryPath = repositoryPath;
45+
RemoteUrl = remoteUrl;
4046
ParentRepositoryPath = parentRepositoryPath;
4147
SubmoduleName = submoduleName;
4248
RecursionDepth = recursionDepth;
4349
}
4450

51+
/// <summary>
52+
/// Full path to parent repository.
53+
/// </summary>
54+
public virtual string ParentRepositoryPath { get; private set; }
55+
4556
/// <summary>
4657
/// The recursion depth for the current repository. The initial
4758
/// repository is at depth 0.
4859
/// </summary>
4960
public virtual int RecursionDepth { get; private set; }
5061

5162
/// <summary>
52-
/// Full path of the repository.
63+
/// The remote URL this operation will work against, if any.
5364
/// </summary>
54-
public virtual string RepositoryPath { get; private set; }
65+
public virtual string RemoteUrl { get; private set; }
5566

5667
/// <summary>
57-
/// Full path to parent repository.
68+
/// Full path of the repository.
5869
/// </summary>
59-
public virtual string ParentRepositoryPath { get; private set; }
70+
public virtual string RepositoryPath { get; private set; }
6071

6172
/// <summary>
6273
/// If this is a submodule, the submodules name in the parent repository.

0 commit comments

Comments
 (0)
0