From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: spearce@spearce.org
Cc: git@vger.kernel.org, Robin Rosenberg <robin.rosenberg@dewire.com>
Subject: [EGIT PATCH 2/3] Add create support to the branch command
Date: Wed, 24 Sep 2008 23:56:22 +0200 [thread overview]
Message-ID: <1222293383-26016-2-git-send-email-robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1222293383-26016-1-git-send-email-robin.rosenberg@dewire.com>
The help string hinted it could create branches, but it was not implemented.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
.../src/org/spearce/jgit/pgm/Branch.java | 38 ++++++++++++++++++--
1 files changed, 35 insertions(+), 3 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 a266244..db0aab8 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
@@ -45,13 +45,16 @@
import java.util.Map.Entry;
import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.ExampleMode;
import org.kohsuke.args4j.Option;
import org.spearce.jgit.lib.Constants;
import org.spearce.jgit.lib.ObjectId;
import org.spearce.jgit.lib.Ref;
import org.spearce.jgit.lib.RefComparator;
import org.spearce.jgit.lib.RefUpdate;
+import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.lib.RefUpdate.Result;
+import org.spearce.jgit.pgm.opt.CmdLineParser;
import org.spearce.jgit.revwalk.RevWalk;
@Command(common = true, usage = "List, create, or delete branches")
@@ -69,6 +72,9 @@
@Option(name = "--delete-force", aliases = { "-D" }, usage = "delete branch (even if not merged)")
private boolean deleteForce = false;
+ @Option(name = "--create-force", aliases = { "-f" }, usage = "force create branch even exists")
+ private boolean createForce = false;
+
@Option(name = "--verbose", aliases = { "-v" }, usage = "be verbose")
private boolean verbose = false;
@@ -87,9 +93,35 @@ protected void run() throws Exception {
if (delete || deleteForce)
delete(deleteForce);
else {
- if (verbose)
- rw = new RevWalk(db);
- list();
+ if (branches.size() > 2)
+ throw die("Too many refs given\n" + new CmdLineParser(this).printExample(ExampleMode.ALL));
+
+ if (branches.size() > 0) {
+ String newHead = branches.get(0);
+ ObjectId startAt;
+ if (branches.size() == 2)
+ startAt = db.resolve(branches.get(1) + "^0");
+ else
+ startAt = db.resolve(Constants.HEAD + "^0");
+
+ String newRefName = newHead;
+ if (!newRefName.startsWith(Constants.R_HEADS))
+ newRefName = Constants.R_HEADS + newRefName;
+ if (!Repository.isValidRefName(newRefName))
+ throw die(String.format("%s is not a valid ref name", newRefName));
+ if (!createForce && db.resolve(newRefName) != null)
+ throw die(String.format("branch %s already exists", newHead));
+ RefUpdate updateRef = db.updateRef(newRefName);
+ updateRef.setNewObjectId(startAt);
+ updateRef.setForceUpdate(createForce);
+ Result update = updateRef.update();
+ if (update == Result.REJECTED)
+ throw die(String.format("Could not create branch %s: %s", newHead, update.toString()));
+ } else {
+ if (verbose)
+ rw = new RevWalk(db);
+ list();
+ }
}
}
--
1.6.0.1.310.gf789d0.dirty
next prev parent reply other threads:[~2008-09-24 21:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-24 21:56 [EGIT PATCH 1/3] Include a print command line usage string utility Robin Rosenberg
2008-09-24 21:56 ` Robin Rosenberg [this message]
2008-09-24 21:56 ` [EGIT PATCH 3/3] Tell the branch dialog how to create a new branch Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1222293383-26016-2-git-send-email-robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).