git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yann Dirson <ydirson@altern.org>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH 4/4] Add a couple of safety checks to series creation
Date: Thu, 13 Apr 2006 23:44:31 +0200	[thread overview]
Message-ID: <20060413214431.8806.4177.stgit@gandelf.nowhere.earth> (raw)
In-Reply-To: <20060413213819.8806.53300.stgit@gandelf.nowhere.earth>

From: Yann Dirson <ydirson@altern.org>

Check first whether the operation can complete, instead of
bombing out halfway.
---

 stgit/commands/branch.py |    5 +++
 stgit/stack.py           |    7 ++++-
 t/t1000-branch-create.sh |   66 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py
index c4b5945..c95e529 100644
--- a/stgit/commands/branch.py
+++ b/stgit/commands/branch.py
@@ -122,12 +122,15 @@ def func(parser, options, args):
         check_conflicts()
         check_head_top_equal()
 
+        if git.branch_exists(args[0]):
+            raise CmdException, 'Branch "%s" already exists' % args[0]
+        
         tree_id = None
         if len(args) == 2:
             tree_id = git_id(args[1])
 
-        git.create_branch(args[0], tree_id)
         stack.Series(args[0]).init()
+        git.create_branch(args[0], tree_id)
 
         print 'Branch "%s" created.' % args[0]
         return
diff --git a/stgit/stack.py b/stgit/stack.py
index 92407e7..236e67f 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -431,8 +431,13 @@ class Series:
         """
         bases_dir = os.path.join(self.__base_dir, 'refs', 'bases')
 
-        if self.is_initialised():
+        if os.path.exists(self.__patch_dir):
             raise StackException, self.__patch_dir + ' already exists'
+        if os.path.exists(self.__refs_dir):
+            raise StackException, self.__refs_dir + ' already exists'
+        if os.path.exists(self.__base_file):
+            raise StackException, self.__base_file + ' already exists'
+
         os.makedirs(self.__patch_dir)
 
         if not os.path.isdir(bases_dir):
diff --git a/t/t1000-branch-create.sh b/t/t1000-branch-create.sh
new file mode 100755
index 0000000..bee0b1c
--- /dev/null
+++ b/t/t1000-branch-create.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 Yann Dirson
+#
+
+test_description='Branch operations.
+
+Exercises the "stg branch" commands.
+'
+
+. ./test-lib.sh
+
+test_stg_init
+
+test_expect_failure \
+    'Try to create an stgit branch with a spurious refs/patches/ entry' \
+    'find .git -name foo | xargs rm -rf &&
+     touch .git/refs/patches/foo &&
+     stg branch -c foo
+'
+
+test_expect_success \
+    'Check no part of the branch was created' \
+    'test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/patches/foo"
+'
+
+
+test_expect_failure \
+    'Try to create an stgit branch with a spurious patches/ entry' \
+    'find .git -name foo | xargs rm -rf &&
+     touch .git/patches/foo &&
+     stg branch -c foo
+'
+
+test_expect_success \
+    'Check no part of the branch was created' \
+    'test "`find .git -name foo | tee /dev/stderr`" = ".git/patches/foo"
+'
+
+
+test_expect_failure \
+    'Try to create an stgit branch with a spurious refs/bases/ entry' \
+    'find .git -name foo | xargs rm -rf &&
+     touch .git/refs/bases/foo &&
+     stg branch -c foo
+'
+
+test_expect_success \
+    'Check no part of the branch was created' \
+    'test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/bases/foo"
+'
+
+
+# test_expect_failure \
+#     'Try to create an stgit branch with a spurious refs/heads/ entry' \
+#     'find .git -name foo | xargs rm -rf &&
+#      touch .git/refs/heads/foo &&
+#      stg branch -c foo
+# '
+
+# test_expect_success \
+#     'Check no part of the branch was created' \
+#     'test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/heads/foo"
+# '
+
+test_done

      parent reply	other threads:[~2006-04-13 21:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-13 21:38 [PATCH 0/4] Add a testsuite to stgit (take 2) Yann Dirson
2006-04-13 21:44 ` [PATCH 1/4] Add a testsuite framework copied from git-core Yann Dirson
2006-04-13 21:44 ` [PATCH 2/4] Add list of bugs to TODO Yann Dirson
2006-04-13 21:44 ` [PATCH 3/4] Correctly handle refs/patches on series rename Yann Dirson
2006-04-13 21:44 ` Yann Dirson [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=20060413214431.8806.4177.stgit@gandelf.nowhere.earth \
    --to=ydirson@altern.org \
    --cc=catalin.marinas@gmail.com \
    --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).