Add a testsuite to stgit (take 3), and more
cover Add a testsuite to stgit (take 3), and more
This new revision of my testsuite patches include:
- cleanup of the repo-initialization stuff in test-lib.sh: now test_create_repo creates an empty commit to start with, so that HEAD points to an existing master branch. This makes test_stg_init useless, rather let tests can "stg init" directly.
- steal the git t/README as well, and adapt it. Proposes a numbering convention for stgit testcases.
- activation and refining of the testcase which I had left commented out in t1000, and a fix for the bug it shows
- fix for a nasty caching issue in stg clone, and associated test
- 2 testcases showing problems with detection of applied patches in "push" after a pull when our patches were integrated upstream. No fix here, though, so you'll see t1200 and t1201 failing.
And not directly related to the testsuite:
- more bugs listed in TODO
- support for per-user templates for mail and export, in ~/.stgit/templates
Signature · 4 lines
Yann Dirson <[email protected]> | Debian-related: <[email protected]> | Support Debian GNU/Linux: | Freedom, Power, Stability, Gratis http://ydirson.free.fr/ | Check <http://www.debian.org/>
PATCH 1/9 Add a testsuite framework copied from git-core
See git's t/README for details on how to use this framework.
There is no integration yet in the toplevel Makefile, I'll let python masters take care of this. Use "make -C t" to run the tests for now.
A patch-naming policy should be defined for stgit, since the git one does not apply.
---
TODO | 2 - t/Makefile | 25 ++++++ t/README | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/t0000-dummy.sh | 17 ++++ t/test-lib.sh | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 456 insertions(+), 1 deletions(-)
TODO +1 -1
@@ -6,7 +6,7 @@ The TODO list until 1.0: - debian package support - man page - code execution allowed from templates -- regression tests +- more regression tests - release 1.0
t/Makefile new file +25 -0
@@ -0,0 +1,25 @@ +# Run tests +# +# Copyright (c) 2005 Junio C Hamano +# + +#GIT_TEST_OPTS=--verbose --debug +SHELL_PATH ?= $(SHELL) +TAR ?= $(TAR) + +# Shell quote; +SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) + +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) + +all: $(T) clean + +$(T): + @echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) + +clean: + rm -fr trash + +.PHONY: $(T) clean +.NOPARALLEL: +
t/README new file +210 -0
210 lines not on this page · raw message
t/t0000-dummy.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/sh +# +# Copyright (c) 2006 Yann Dirson +# + +test_description='Dummy test. + +Only to test the testing environment. +' + +. ./test-lib.sh + +test_expect_success \ + 'check stgit can be run' \ + 'stg version' + +test_done
t/test-lib.sh new file +203 -0
203 lines not on this page · raw message
PATCH 2/9 Add list of bugs to TODO
In reply to Yann DirsonSince there is no formal place to register bugs, other than the git ml, I have added a couple of them, some of them already mentionned on the ml but still around.
---
TODO | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
TODO +15 -0
@@ -7,6 +7,7 @@ The TODO list until 1.0: - man page - code execution allowed from templates - more regression tests +- stg help should probably pipe through the $PAGER - release 1.0
@@ -17,3 +18,17 @@ The future, when time allows or if someo synchronising with other patches (diff format or in other repositories) - write bash-completion script for the StGIT commands +- support for branches with / in names + (ml: "Handle branch names with slashes") +- "pull" argument should default to a sane value, "origin" is wrong in + many cases + +Bugs: + +- the following commands break in subdirs: + - refresh (ml: "Running StGIT in subdirectories") +- "stg show" on empty patch shows previous patch +- "stg add" is accepted when no patch is applied, then any push says + one must refresh first, which is obviously wrong +- "stg add" on files already added should print a notice, so that the + user can catch a possible typo
PATCH 3/9 Add a couple of safety checks to series creation
In reply to Yann Dirson- we must check first whether the operation can complete, instead of bombing out halfway. That means checking that nothing will prevent the creation of stgit data (note that calling is_initialised() is not enough, as it does not catch a bogus file), which is tested by the 3 first couple of testcases, and fixed in stack.py
- creating the git branch unconditionally before knowing whether creation of the stgit stuff can be completed is a problem as well:
being atomic would be much much better. To emulate atomicity (which comeds in the next patch), this patch does a somewhat dirty hack to branch.py: we first attempt to create the stgit stuff, and if that succeeds, we create the git branch: it is much easier to do at first a quick check that the latter will succeed. Testcase 7/8 ensure that such a safety check has not been forgotten.
- when git already reports a problem with that head we would like to create, we should catch it. Testcase 9/10 creates such a situation, and the fix to git.py allows to catch the error spit out by git-rev-parse. I cannot tell why the stderr lines were not included by the Popen3 object.
---
stgit/commands/branch.py | 5 ++- stgit/git.py | 4 ++ stgit/stack.py | 7 +++- t/t1000-branch-create.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-)
stgit/commands/branch.py +4 -1
@@ -126,8 +126,11 @@ def func(parser, options, args): if len(args) == 2: tree_id = git_id(args[1]) - git.create_branch(args[0], tree_id) + if git.branch_exists(args[0]): + raise CmdException, 'Branch "%s" already exists' % args[0] + stack.Series(args[0]).init() + git.create_branch(args[0], tree_id) print 'Branch "%s" created.' % args[0] return
stgit/git.py +3 -1
@@ -272,9 +272,11 @@ def rev_parse(git_id): def branch_exists(branch): """Existence check for the named branch """ - for line in _output_lines(['git-rev-parse', '--symbolic', '--all']): + for line in _output_lines('git-rev-parse --symbolic --all 2>&1'): if line.strip() == branch: return True + if re.compile('[ |/]'+branch+' ').search(line): + raise GitException, 'Bogus branch: %s' % line return False def create_branch(new_branch, tree_id = None):
stgit/stack.py +6 -1
@@ -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):
t/t1000-branch-create.sh new file +82 -0
82 lines not on this page · raw message
PATCH 4/9 Make branch creation atomic
In reply to Yann DirsonThis patch adds an optional create_at parameter to Series.init(), to pass a git.branch_create() parameter if we want it to be called. This parameter can be None, so the test for False has to be explicit.
---
stgit/commands/branch.py | 6 +----- stgit/stack.py | 8 +++++--- 2 files changed, 6 insertions(+), 8 deletions(-)
stgit/commands/branch.py +1 -5
@@ -125,12 +125,8 @@ def func(parser, options, args): tree_id = None if len(args) == 2: tree_id = git_id(args[1]) - - if git.branch_exists(args[0]): - raise CmdException, 'Branch "%s" already exists' % args[0] - stack.Series(args[0]).init() - git.create_branch(args[0], tree_id) + stack.Series(args[0]).init(create_at = tree_id) print 'Branch "%s" created.' % args[0] return
stgit/stack.py +5 -3
@@ -426,7 +426,7 @@ class Series: """ return os.path.isdir(self.__patch_dir) - def init(self): + def init(self, create_at=False): """Initialises the stgit series """ bases_dir = os.path.join(self.__base_dir, 'refs', 'bases')
@@ -438,6 +438,9 @@ class Series: if os.path.exists(self.__base_file): raise StackException, self.__base_file + ' already exists' + if (create_at!=False): + git.create_branch(self.__name, create_at) + os.makedirs(self.__patch_dir) if not os.path.isdir(bases_dir):
@@ -509,8 +512,7 @@ class Series: """Clones a series """ base = read_string(self.get_base_file()) - git.create_branch(target_series, tree_id = base) - Series(target_series).init() + Series(target_series).init(create_at = base) new_series = Series(target_series) # generate an artificial description file
PATCH 5/9 Correctly handle refs/patches on series rename
In reply to Yann DirsonWhen renaming a series, the refs/patches dir was not moved, and by chance a new one was created by the repository-upgrade code, but that left the old one behind as cruft (which the safety checks added in a former patch now detects).
Also adds a regression test to assert that nothing by the old name is left behind.
---
stgit/stack.py | 2 ++ t/t1001-branch-rename.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 0 deletions(-)
stgit/stack.py +2 -0
@@ -505,6 +505,8 @@ class Series: os.rename(self.__series_dir, to_stack.__series_dir) if os.path.exists(self.__base_file): os.rename(self.__base_file, to_stack.__base_file) + if os.path.exists(self.__refs_dir): + os.rename(self.__refs_dir, to_stack.__refs_dir) self.__init__(to_name)
t/t1001-branch-rename.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/sh +# +# Copyright (c) 2006 Yann Dirson +# + +test_description='Branch renames. + +Exercises branch renaming commands. +' + +. ./test-lib.sh + +test_expect_success \ + 'Create an stgit branch from scratch' \ + 'stg init && + stg branch -c foo && + stg new p1 -m "p1" +' + +test_expect_failure \ + 'Rename the current stgit branch' \ + 'stg branch -r foo bar +' + +test_expect_success \ + 'Rename an stgit branch' \ + 'stg branch -c buz && + stg branch -r foo bar && + test -z `find .git -name foo | tee /dev/stderr` +' + +test_done
PATCH 6/9 Fix a seriously bad interaction between .git caching and repo cloning
In reply to Yann DirsonTestcase 2 exhibits a problem with caching the location of .git while cloning a repository. Since basedir.get() is called before the clone is built, a value may get stored in the cache if we are within a git-controlled tree already. Then when constructing the object for the clone, a bogus .git is used, which can lead, when running tests in t/trash, to corruption of the stgit .git repository.
Testcase 1 does not show any problem by chance, because since we have a ./.git prepared for use by the testsuite, value ".git" get cached, and it happens that this value will be still valid after chdir'ing into the newborn clone.
Clearing the cache at the appropriate place fixes the problem.
---
stgit/basedir.py | 6 ++++++ stgit/commands/clone.py | 3 +++ t/t1100-clone-under.sh | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 0 deletions(-)
stgit/basedir.py +6 -0
@@ -42,3 +42,9 @@ def get(): __base_dir = __output('git-rev-parse --git-dir 2> /dev/null') return __base_dir + +def clear_cache(): + """Clear the cached location of .git + """ + global __base_dir + __base_dir = None
stgit/commands/clone.py +3 -0
@@ -51,6 +51,9 @@ def func(parser, options, args): os.chdir(local_dir) git.checkout(tree_id = 'HEAD') + # be sure to forget any cached value for .git, since we're going + # to work on a brand new repository + basedir.clear_cache() stack.Series().init() print 'done'
t/t1100-clone-under.sh new file +36 -0
@@ -0,0 +1,36 @@ +#!/bin/sh +# +# Copyright (c) 2006 Yann Dirson +# + +test_description='Check cloning in a repo subdir + +Check that "stg clone" works in a subdir of a git tree. +This ensures (to some point) that a clone within a tree does +not corrupt the enclosing repo. + +This test must be run before any tests making use of clone. +' + +. ./test-lib.sh + +# Here we are in a repo, we have a ./.git +# Do not get rid of it, or a bug may bite out stgit repo hard + +# Need a repo to clone +test_create_repo foo + +test_expect_success \ + 'stg clone right inside a git tree' \ + "stg clone foo bar" + +# now work in a subdir +mkdir sub +mv foo sub +cd sub + +test_expect_success \ + 'stg clone deeper under a git tree' \ + "stg clone foo bar" + +test_done
PATCH 7/9 Test that pulls a patch creating a file that got modified afterwards
In reply to Yann DirsonThis demonstrates an issue wite has bitten me more than once: the stg branch adds a file in one patch, and modifies it in a later patch; then all patches get integrated in upstream tree, and at "stg pull" time, stgit believes there is a conflict, even one the patches are exactly the same.
"stg push" apparently does not consider patches one by one, or it would have noticed that the patches were "already applied". It reports:
Pushing patch "p1"...Error: File "file2" added in branches but different The merge failed during "push". Use "refresh" after fixing the conflicts stg push: GIT index merging failed (possible conflicts)
---
t/t1200-push-modified.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-)
t/t1200-push-modified.sh new file +51 -0
@@ -0,0 +1,51 @@ +#!/bin/sh +# +# Copyright (c) 2006 Yann Dirson +# + +test_description='Exercise pushing patches applied upstream. + +Especially, consider the case of a patch that adds a file, +while a subsequent one modifies it. +' + +. ./test-lib.sh + +# don't need this repo, but better not drop it, see t1100 +#rm -rf .git + +# Need a repo to clone +test_create_repo foo + +test_expect_success \ + 'Clone tree and setup changes' \ + "stg clone foo bar && + (cd bar && stg new p1 -m p1 + printf 'a\nc\n' > file && stg add file && stg refresh && + stg new p2 -m p2 + printf 'a\nb\nc\n' > file && stg refresh + ) +" + +test_expect_success \ + 'Port those patches to orig tree' \ + "(cd foo && + GIT_DIR=../bar/.git git-format-patch --stdout bases/master..HEAD | + git-am -3 -k + ) +" + +test_expect_success \ + 'Pull to sync with parent, preparing for the problem' \ + "(cd bar && stg pop --all && + stg pull + ) +" + +test_expect_success \ + 'Now attempt to push those patches applied upstream' \ + "(cd bar && stg push --all + ) +" + +test_done
PATCH 8/9 Exercise "stg pull" on patches just appending lines.
In reply to Yann DirsonIt indeed reveals a problem in "push": appended lines are appended again, as the already-applied patch is not detected.
---
t/t1201-pull-trailing.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-)
t/t1201-pull-trailing.sh new file +48 -0
@@ -0,0 +1,48 @@ +#!/bin/sh +# +# Copyright (c) 2006 Yann Dirson +# + +test_description='test + +' + +. ./test-lib.sh + +# don't need this repo, but better not drop it, see t1100 +#rm -rf .git + +# Need a repo to clone +test_create_repo foo + +test_expect_success \ + 'Setup and clone tree, and setup changes' \ + "(cd foo && + printf 'a\nb\n' > file && git add file && git commit -m . + ) && + stg clone foo bar && + (cd bar && stg new p1 -m p1 + printf 'c\n' >> file && stg refresh + ) +" + +test_expect_success \ + 'Port those patches to orig tree' \ + "(cd foo && + GIT_DIR=../bar/.git git-format-patch --stdout bases/master..HEAD | + git-am -3 -k + ) +" + +test_expect_success \ + 'Pull those patches applied upstream' \ + "(cd bar && stg pull + ) +" + +test_expect_success \ + 'Check that all went well' \ + "diff -u foo/file bar/file +" + +test_done
PATCH 9/9 Look for templates in ~/.stgit/templates as well
In reply to Yann DirsonThis can be quite useful to avoid adding one's sig again and again to ever covermail, and to use a patchmail template that insert Signed-off-by lines, for those of us who prefer this to adding them to commits.
Also make sure to use os.path.join() instead of hardcoded slashes.
---
stgit/commands/export.py | 9 ++++++--- stgit/commands/mail.py | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-)
stgit/commands/export.py +6 -3
@@ -31,8 +31,9 @@ usage = """%prog [options] [<dir>] Export the applied patches into a given directory (defaults to 'patches') in a standard unified GNU diff format. A template file -(defaulting to '.git/patchexport.tmpl or -/usr/share/stgit/templates/patchexport.tmpl') can be used for the +(defaulting to '.git/patchexport.tmpl' or +'~/.stgit/templates/patchexport.tmpl' or +'/usr/share/stgit/templates/patchexport.tmpl') can be used for the patch format. The following variables are supported in the template file:
@@ -145,8 +146,10 @@ def func(parser, options, args): patch_tmpl_list = [] patch_tmpl_list += [os.path.join(basedir.get(), 'patchexport.tmpl'), + os.path.join(os.path.expanduser('~'), '.stgit', 'templates', + 'patchexport.tmpl'), os.path.join(sys.prefix, - 'share/stgit/templates/patchexport.tmpl')] + 'share', 'stgit', 'templates', 'patchexport.tmpl')] tmpl = '' for patch_tmpl in patch_tmpl_list: if os.path.isfile(patch_tmpl):
stgit/commands/mail.py +12 -6
@@ -30,16 +30,18 @@ usage = """%prog [options] [<patch> [<pa Send a patch or a range of patches (defaulting to the applied patches) by e-mail using the 'smtpserver' configuration option. The From address and the e-mail format are generated from the template file -passed as argument to '--template' (defaulting to .git/patchmail.tmpl -or /usr/share/stgit/templates/patchmail.tmpl). The To/Cc/Bcc addresses +passed as argument to '--template' (defaulting to +'.git/patchmail.tmpl' or '~/.stgit/templates/patchmail.tmpl' or or +'/usr/share/stgit/templates/patchmail.tmpl'). The To/Cc/Bcc addresses can either be added to the template file or passed via the corresponding command line options. A preamble e-mail can be sent using the '--cover' and/or '--edit' options. The first allows the user to specify a file to be used as a template. The latter option will invoke the editor on the specified -file (defaulting to .git/covermail.tmpl or -/usr/share/stgit/templates/covermail.tmpl). +file (defaulting to '.git/covermail.tmpl' or +'~/.stgit/templates/covermail.tmpl' or +'/usr/share/stgit/templates/covermail.tmpl'). All the subsequent e-mails appear as replies to the first e-mail sent (either the preamble or the first patch). E-mails can be seen as
@@ -444,8 +446,10 @@ def func(parser, options, args): tfile_list = [options.cover] else: tfile_list = [os.path.join(basedir.get(), 'covermail.tmpl'), + os.path.join(os.path.expanduser('~'), '.stgit', 'templates', + 'covermail.tmpl'), os.path.join(sys.prefix, - 'share/stgit/templates/covermail.tmpl')] + 'share', 'stgit', 'templates', 'covermail.tmpl')] tmpl = None for tfile in tfile_list:
@@ -476,8 +480,10 @@ def func(parser, options, args): tfile_list = [options.template] else: tfile_list = [os.path.join(basedir.get(), 'patchmail.tmpl'), + os.path.join(os.path.expanduser('~'), '.stgit', 'templates', + 'patchmail.tmpl'), os.path.join(sys.prefix, - 'share/stgit/templates/patchmail.tmpl')] + 'share', 'stgit', 'templates', 'patchmail.tmpl')] tmpl = None for tfile in tfile_list: if os.path.isfile(tfile):