From: "Shawn O. Pearce" <spearce@spearce.org>
To: Charles O'Farrell <charleso@charleso.org>
Cc: git@vger.kernel.org
Subject: Re: [JGIT PATCH 1/4] Ensured that RefUpdate cannot delete current branch
Date: Fri, 22 Aug 2008 16:22:26 -0700 [thread overview]
Message-ID: <20080822232226.GP3483@spearce.org> (raw)
In-Reply-To: <1219445147-6801-2-git-send-email-charleso@charleso.org>
Charles O'Farrell <charleso@charleso.org> wrote:
> If attempted it will return a REJECTED_CURRENT_BRANCH Result.
> @@ -323,6 +330,9 @@ public Result update(final RevWalk walk) throws IOException {
> * @throws IOException
> */
> public Result delete() throws IOException {
> + if (name.substring(Constants.R_HEADS.length()).equals(
> + db.getRepository().getBranch()))
> + return Result.REJECTED_CURRENT_BRANCH;
> try {
> return updateImpl(new RevWalk(db.getRepository()),
> new DeleteStore());
I'm squashing this into the patch, as I think its a safer (and
faster) way to evaluate what the current branch is. We have a
cache in RefDatabase showing the current value of HEAD. We also
don't look at .git/head-name, which happens during a bisection.
But I also don't think we want to mess around with this test if
we are dealing with refs/remotes or refs/tags. Really it is only
refs/heads/ that should typically appear in HEAD, so we only need
to guard against that case. If the user knows enough to make HEAD
point at something else, maybe they will also know enough to not
delete the damn thing out from under themselves. If we did fix it
to test for all refs, its just a matter of removing the first if.
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
index aa2cecb..77dada0 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
@@ -330,9 +330,12 @@ public Result update(final RevWalk walk) throws IOException {
* @throws IOException
*/
public Result delete() throws IOException {
- if (name.substring(Constants.R_HEADS.length()).equals(
- db.getRepository().getBranch()))
- return Result.REJECTED_CURRENT_BRANCH;
+ if (name.startsWith(Constants.R_HEADS)) {
+ final Ref head = db.readRef(Constants.HEAD);
+ if (head != null && name.equals(head.getName()))
+ return Result.REJECTED_CURRENT_BRANCH;
+ }
+
try {
return updateImpl(new RevWalk(db.getRepository()),
new DeleteStore());
--
Shawn.
prev parent reply other threads:[~2008-08-22 23:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-22 22:45 [JGIT PATCH 0/4] Branch deletion testing and bug fixes Charles O'Farrell
2008-08-22 22:45 ` [JGIT PATCH 1/4] Ensured that RefUpdate cannot delete current branch Charles O'Farrell
2008-08-22 22:45 ` [JGIT PATCH 2/4] Fixed bug where RefUpdate didn't delete identical HEAD branch Charles O'Farrell
2008-08-22 22:45 ` [JGIT PATCH 3/4] Added test for RefUpdate branch deletion Charles O'Farrell
2008-08-22 22:45 ` [JGIT PATCH 4/4] Added extra javadoc for delete to significant RefUpdate results Charles O'Farrell
2008-08-22 23:26 ` [JGIT PATCH 3/4] Added test for RefUpdate branch deletion Shawn O. Pearce
2008-08-22 23:28 ` Robin Rosenberg
2008-08-22 23:31 ` Shawn O. Pearce
2008-08-22 23:22 ` Shawn O. Pearce [this message]
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=20080822232226.GP3483@spearce.org \
--to=spearce@spearce.org \
--cc=charleso@charleso.org \
--cc=git@vger.kernel.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).