From: Robin Rosenberg Date: Wed, 27 May 2009 22:08:54 GMT Subject: [EGIT PATCH 07/10] Set a nice reflog message in the branch command Message-ID: <1243462137-24133-8-git-send-email-robin.rosenberg@dewire.com> In-Reply-To: <1243462137-24133-7-git-send-email-robin.rosenberg@dewire.com> Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/pgm/Branch.java | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-) diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java index 11002f0..dbe297e 100644 --- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java +++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Branch.java @@ -98,12 +98,18 @@ protected void run() throws Exception { if (branches.size() > 0) { String newHead = branches.get(0); - ObjectId startAt; + String startBranch; if (branches.size() == 2) - startAt = db.resolve(branches.get(1) + "^0"); + startBranch = branches.get(1); else - startAt = db.resolve(Constants.HEAD + "^0"); - + startBranch = Constants.HEAD; + Ref startRef = db.getRef(startBranch); + ObjectId startAt = db.resolve(startBranch + "^0"); + if (startRef != null) + startBranch = startRef.getName(); + else + startBranch = startAt.name(); + startBranch = db.shortenRefName(startBranch); String newRefName = newHead; if (!newRefName.startsWith(Constants.R_HEADS)) newRefName = Constants.R_HEADS + newRefName; @@ -114,6 +120,7 @@ protected void run() throws Exception { RefUpdate updateRef = db.updateRef(newRefName); updateRef.setNewObjectId(startAt); updateRef.setForceUpdate(createForce); + updateRef.setRefLogMessage("branch: Created from " + startBranch, false); Result update = updateRef.update(); if (update == Result.REJECTED) throw die(String.format("Could not create branch %s: %s", newHead, update.toString())); -- 1.6.3.dirty