Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaaman <romain.magny@gmail.com>2013-04-15 18:43:39 +0400
committerSaaman <romain.magny@gmail.com>2013-04-26 16:17:58 +0400
commitbccacb9c2cf9524115e6b6e249951c5bc5be3df2 (patch)
tree09921a1bdbb96e8c5c4478678fccaf2fb77537a8 /LibGit2Sharp/Repository.cs
parent0efaf0d2581411331f15af3ef3f401ce2558b04a (diff)
Teach Checkout() to append to the reflog
When no user information exists in the configuration, a dummy signature is created to value the reflog entry.
Diffstat (limited to 'LibGit2Sharp/Repository.cs')
-rw-r--r--LibGit2Sharp/Repository.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 39cd5f1b..a14a61e3 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -586,11 +586,17 @@ namespace LibGit2Sharp
return Checkout(branch, checkoutOptions, onCheckoutProgress);
}
+ var previousHeadName = Info.IsHeadDetached ? Head.Tip.Sha : Head.Name;
+
Commit commit = LookupCommit(committishOrBranchSpec);
CheckoutTree(commit.Tree, checkoutOptions, onCheckoutProgress);
// Update HEAD.
Refs.UpdateTarget("HEAD", commit.Id.Sha);
+ if (committishOrBranchSpec != "HEAD")
+ {
+ LogCheckout(previousHeadName, commit.Id, committishOrBranchSpec);
+ }
return Head;
}
@@ -633,6 +639,9 @@ namespace LibGit2Sharp
"The tip of branch '{0}' is null. There's nothing to checkout.", branch.Name));
}
+ var branchIsCurrentRepositoryHead = branch.IsCurrentRepositoryHead;
+ var previousHeadName = Info.IsHeadDetached ? Head.Tip.Sha : Head.Name;
+
CheckoutTree(branch.Tip.Tree, checkoutOptions, onCheckoutProgress);
// Update HEAD.
@@ -647,9 +656,29 @@ namespace LibGit2Sharp
Refs.UpdateTarget("HEAD", branch.Tip.Id.Sha);
}
+ if (!branchIsCurrentRepositoryHead)
+ {
+ LogCheckout(previousHeadName, branch);
+ }
+
return Head;
}
+ private void LogCheckout(string previousHeadName, Branch newHead)
+ {
+ LogCheckout(previousHeadName, newHead.Tip.Id, newHead.Name);
+ }
+
+ private void LogCheckout(string previousHeadName, ObjectId newHeadTip, string newHeadSpec)
+ {
+ // Compute reflog message
+ string reflogMessage = string.Format("checkout: moving from {0} to {1}", previousHeadName, newHeadSpec);
+
+ // Log checkout
+ Signature author = Config.BuildSignatureFromGlobalConfiguration(DateTimeOffset.Now, false);
+ Refs.Log(Refs.Head).Append(newHeadTip, author, reflogMessage);
+ }
+
/// <summary>
/// Internal implementation of Checkout that expects the ID of the checkout target
/// to already be in the form of a canonical branch name or a commit ID.