Requirements:
Using libgit2sharp I want to pull (fetch + merge) the last from the remote git branch to my verified local branch , without having to pass any other arguments like user credentials, etc. I'm mainly trying to replicategit pull origin my-remote-branch
More details:
I want to automate some git operations with C #. I just can do what I want by calling git.exe
(if I know the path), for example git.exe --git-dir=my-repo-directory pull origin my-remote-branch
. Please note that here the only external parameters that I have to provide are my-repo-directory
and my-remote-branch
. git gets everything right, such as name, password, email, the current working branch (even if it does not have a remote connection), and git pull just works. I do not need to pass any of these parameters manually. I assume that git gets them from the current git parameters for the repo (from the% HOME% folder?).
Is there any way to simulate this in LibGit2Sharp?
What I tried:
using (var repo = new Repository("my-repo-directory"))
{
PullOptions pullOptions = new PullOptions()
{
MergeOptions = new MergeOptions()
{
FastForwardStrategy = FastForwardStrategy.Default
}
};
MergeResult mergeResult = Commands.Pull(
repo,
new Signature("my name", "my email", DateTimeOffset.Now),
pullOptions
);
}
, there is no tracking branch
. . , , .
, , :
using (var repo = new Repository("my-repo-directory"))
{
var trackingBranch = repo.Branches["remotes/origin/my-remote-branch"];
if (trackingBranch.IsRemote)
{
var branch = repo.Head;
repo.Branches.Update(branch, b => b.TrackedBranch = trackingBranch.CanonicalName);
}
PullOptions pullOptions = new PullOptions()
{
MergeOptions = new MergeOptions()
{
FastForwardStrategy = FastForwardStrategy.Default
}
};
MergeResult mergeResult = Commands.Pull(
repo,
new Signature("my name", "my email", DateTimeOffset.Now),
pullOptions
);
}
: 401
:
git.exe , hardcode git exe. , , .. , libgit2sharp , , git.exe?