|
|
@@ -161,36 +161,36 @@ public sealed class LibGit2GitRepository(
|
|
|
true);
|
|
|
}
|
|
|
|
|
|
- public void Push() {
|
|
|
+ public void Push()
|
|
|
+ {
|
|
|
using Repository repo = OpenRepo();
|
|
|
-
|
|
|
+
|
|
|
Remote remote = GetRemote(repo);
|
|
|
- var refSpec = $"refs/heads/{repo.Head.FriendlyName}";
|
|
|
-
|
|
|
- try {
|
|
|
+ var branch = repo.Head.FriendlyName;
|
|
|
+ var refSpec = $"refs/heads/{branch}:refs/heads/{branch}";
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
repo.Network.Push(
|
|
|
remote,
|
|
|
refSpec,
|
|
|
new PushOptions { CredentialsProvider = _credentials });
|
|
|
}
|
|
|
- catch (LibGit2Sharp.NonFastForwardException) {
|
|
|
+ catch (LibGit2Sharp.NonFastForwardException)
|
|
|
+ {
|
|
|
// remote has commits we don't have
|
|
|
Pull();
|
|
|
-
|
|
|
- // retry push
|
|
|
+
|
|
|
repo.Network.Push(
|
|
|
remote,
|
|
|
refSpec,
|
|
|
new PushOptions { CredentialsProvider = _credentials });
|
|
|
}
|
|
|
-
|
|
|
- if (repo.Head.TrackedBranch is null) {
|
|
|
- Branch remoteBranch = repo.Branches[$"{remote.Name}/{repo.Head.FriendlyName}"];
|
|
|
-
|
|
|
- if (remoteBranch != null) {
|
|
|
- repo.Branches.Update(repo.Head,
|
|
|
- b => b.TrackedBranch = remoteBranch.CanonicalName);
|
|
|
- }
|
|
|
+
|
|
|
+ if (repo.Head.TrackedBranch is null)
|
|
|
+ {
|
|
|
+ repo.Branches.Update(repo.Head,
|
|
|
+ b => b.TrackedBranch = $"refs/remotes/{remote.Name}/{branch}");
|
|
|
}
|
|
|
}
|
|
|
|