-
Notifications
You must be signed in to change notification settings - Fork 910
Clone recursively #640
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
Clone recursively #640
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ref: refs/heads/master |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[core] | ||
repositoryformatversion = 0 | ||
filemode = false | ||
bare = true | ||
symlinks = false | ||
ignorecase = true | ||
hideDotFiles = dotGitOnly |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Unnamed repository; edit this file 'description' to name the repository. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# git ls-files --others --exclude-from=.git/info/exclude | ||
# Lines that start with '#' are comments. | ||
# For a project mostly in C, the following would be a good set of | ||
# exclude patterns (uncomment them if you want to use them): | ||
# *.[oa] | ||
# *~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# pack-refs with: peeled fully-peeled | ||
9d4e659e2429c884eb50193880bd09613a8ddba5 refs/heads/master |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
using System.Diagnostics; | ||
using System.Globalization; | ||
using LibGit2Sharp.Core; | ||
using LibGit2Sharp.Core.Handles; | ||
using LibGit2Sharp.Handlers; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
|
@@ -55,10 +57,20 @@ internal Submodule(Repository repo, string name, string path, string url) | |
public virtual string Name { get { return name; } } | ||
|
||
/// <summary> | ||
/// The path of the submodule. | ||
/// The path of the submodule relative to the workdir of the parent repository. | ||
/// </summary> | ||
public virtual string Path { get { return path; } } | ||
|
||
/// <summary> | ||
/// Gets the absolute path to the working directory of the submodule. | ||
/// </summary> | ||
public virtual string WorkingDirectory | ||
{ | ||
get { | ||
return System.IO.Path.Combine(repo.Info.WorkingDirectory, Path); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The URL of the submodule. | ||
/// </summary> | ||
|
@@ -155,5 +167,47 @@ private string DebuggerDisplay | |
"{0} => {1}", Name, Url); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Inits this submodule | ||
/// </summary> | ||
/// <param name="options"></param> | ||
internal void Init(CloneOptions options) | ||
{ | ||
var remoteCallbacks = new RemoteCallbacks(null, options.OnTransferProgress, null, | ||
options.Credentials); | ||
GitRemoteCallbacks gitRemoteCallbacks = remoteCallbacks.GenerateCallbacks(); | ||
|
||
string gitdirPath = System.IO.Path.Combine(System.IO.Path.Combine(repo.Info.Path, "modules"), Path); | ||
string remoteURL = Proxy.git_submodule_resolve_url(repo.Handle, Url); | ||
string fetchRefspec = "+refs/heads/*:refs/remotes/origin/*"; | ||
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now); | ||
|
||
GitCheckoutOpts opts = new GitCheckoutOpts() { | ||
version = 1, | ||
checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_NONE | ||
}; | ||
|
||
using (RepositorySafeHandle subrepo = Proxy.git_repository_init_ext( | ||
WorkingDirectory, gitdirPath, GitRepositoryInitFlags.GIT_REPOSITORY_INIT_NO_DOTGIT_DIR)) | ||
using (RemoteSafeHandle remote = Proxy.git_remote_create_anonymous(subrepo, remoteURL, fetchRefspec)) | ||
{ | ||
Proxy.git_remote_set_callbacks(remote, ref gitRemoteCallbacks); | ||
Proxy.git_clone_into(subrepo, remote, opts, null /* no branch */, signature); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Checks out the HEAD revision | ||
/// </summary> | ||
internal void Update(CloneOptions options) | ||
{ | ||
using (Repository subrepo = new Repository(WorkingDirectory)) | ||
{ | ||
subrepo.Checkout(HeadCommitId.Sha, CheckoutModifiers.None, options.OnCheckoutProgress, null); | ||
// This is required because Checkout() does not actually checkout the files | ||
subrepo.Reset(ResetMode.Hard); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better way than resetting? I think it does not check out the files immediately because the files are already indexed as missing. A solution to the comment above (passing head sha to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's odd. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite understand.
Cloning recursively should be fully automated, just like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, are we talking about the flag passed to the clone API, or the flag passed to the second-pass checkout? I'd assume that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, now I see. I think I tried passing |
||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to specify a commit sha instead of a branch name here? That would save the call to
Update
. If I specify the sha, it tries to check out/refs/heads/(unknown)/[sha]
(or something alike).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for clone. If you wanted to avoid the checkout step, you could just do a fetch here, but there's a bunch of stuff that the clone api is doing that you'd have to do yourself.