* [PATCH] stgit: fix clone @ 2006-01-11 22:19 Pavel Roskin 2006-01-11 22:39 ` Chuck Lever 0 siblings, 1 reply; 6+ messages in thread From: Pavel Roskin @ 2006-01-11 22:19 UTC (permalink / raw) To: Catalin Marinas, git "stg clone" is currently broken: $ stg clone http://homepage.ntlworld.com/cmarinas/stgit.git stg clone: git-rev-parse --git-dir failed This happens with current git. "git-rev-parse --git-dir" doesn't work in an empty directory. The patch avoids running "git-rev-parse --git-dir" when the requested command doesn't assume existence of git repository. Signed-off-by: Pavel Roskin <proski@gnu.org> --- Warning: this is my first non-trivial patch to StGIT and the first patch to a Python program. diff --git a/stgit/git.py b/stgit/git.py index a7b1c3f..0e63f69 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -82,13 +82,16 @@ __commits = dict() # Functions # -def get_base_dir(): +def get_base_dir(assume_top = False): """Different start-up variables read from the environment """ if 'GIT_DIR' in os.environ: return os.environ['GIT_DIR'] else: - return _output_one_line('git-rev-parse --git-dir') + if assume_top: + return '.git' + else: + return _output_one_line('git-rev-parse --git-dir') def get_commit(id_hash): """Commit objects factory. Save/look-up them in the __commits diff --git a/stgit/stack.py b/stgit/stack.py index 8b7c296..1c080b3 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -263,7 +263,7 @@ class Series: self.__name = git.get_head_file() if self.__name: - base_dir = git.get_base_dir() + base_dir = git.get_base_dir(assume_top = (name == 'master')) self.__patch_dir = os.path.join(base_dir, 'patches', self.__name) self.__base_file = os.path.join(base_dir, 'refs', 'bases', -- Regards, Pavel Roskin ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] stgit: fix clone 2006-01-11 22:19 [PATCH] stgit: fix clone Pavel Roskin @ 2006-01-11 22:39 ` Chuck Lever 2006-01-11 22:47 ` Chuck Lever 0 siblings, 1 reply; 6+ messages in thread From: Chuck Lever @ 2006-01-11 22:39 UTC (permalink / raw) To: Pavel Roskin; +Cc: Catalin Marinas, git [-- Attachment #1: Type: text/plain, Size: 2047 bytes --] hi pavel- exactly where does the clone operation fail? is it at the checkout step? seems to me the "git clone" script should create an environment where "git-rev-parse --git-dir" ought to work correctly. Pavel Roskin wrote: > "stg clone" is currently broken: > > $ stg clone http://homepage.ntlworld.com/cmarinas/stgit.git > stg clone: git-rev-parse --git-dir failed > > This happens with current git. "git-rev-parse --git-dir" doesn't work > in an empty directory. The patch avoids running "git-rev-parse > --git-dir" when the requested command doesn't assume existence of git > repository. > > Signed-off-by: Pavel Roskin <proski@gnu.org> > > --- > Warning: this is my first non-trivial patch to StGIT and the first patch > to a Python program. > > diff --git a/stgit/git.py b/stgit/git.py > index a7b1c3f..0e63f69 100644 > --- a/stgit/git.py > +++ b/stgit/git.py > @@ -82,13 +82,16 @@ __commits = dict() > # Functions > # > > -def get_base_dir(): > +def get_base_dir(assume_top = False): > """Different start-up variables read from the environment > """ > if 'GIT_DIR' in os.environ: > return os.environ['GIT_DIR'] > else: > - return _output_one_line('git-rev-parse --git-dir') > + if assume_top: > + return '.git' > + else: > + return _output_one_line('git-rev-parse --git-dir') > > def get_commit(id_hash): > """Commit objects factory. Save/look-up them in the __commits > diff --git a/stgit/stack.py b/stgit/stack.py > index 8b7c296..1c080b3 100644 > --- a/stgit/stack.py > +++ b/stgit/stack.py > @@ -263,7 +263,7 @@ class Series: > self.__name = git.get_head_file() > > if self.__name: > - base_dir = git.get_base_dir() > + base_dir = git.get_base_dir(assume_top = (name == 'master')) > self.__patch_dir = os.path.join(base_dir, 'patches', > self.__name) > self.__base_file = os.path.join(base_dir, 'refs', 'bases', > > [-- Attachment #2: cel.vcf --] [-- Type: text/x-vcard, Size: 451 bytes --] begin:vcard fn:Chuck Lever n:Lever;Charles org:Network Appliance, Incorporated;Open Source NFS Client Development adr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA email;internet:cel@citi.umich.edu title:Member of Technical Staff tel;work:+1 734 763-4415 tel;fax:+1 734 763 4434 tel;home:+1 734 668-1089 x-mozilla-html:FALSE url:http://troy.citi.umich.edu/u/cel/ version:2.1 end:vcard ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] stgit: fix clone 2006-01-11 22:39 ` Chuck Lever @ 2006-01-11 22:47 ` Chuck Lever 2006-01-12 11:54 ` Catalin Marinas 0 siblings, 1 reply; 6+ messages in thread From: Chuck Lever @ 2006-01-11 22:47 UTC (permalink / raw) To: cel; +Cc: Pavel Roskin, Catalin Marinas, git [-- Attachment #1: Type: text/plain, Size: 482 bytes --] Chuck Lever wrote: > hi pavel- > > exactly where does the clone operation fail? is it at the checkout step? > > seems to me the "git clone" script should create an environment where > "git-rev-parse --git-dir" ought to work correctly. oops. i see it now. stgit/main.py does a special stack.Series('master') just for the clone command. it really shouldn't do this -- the crt_series.init() in the clone command ought to be fixed to do this properly. catalin, do you agree? [-- Attachment #2: cel.vcf --] [-- Type: text/x-vcard, Size: 451 bytes --] begin:vcard fn:Chuck Lever n:Lever;Charles org:Network Appliance, Incorporated;Open Source NFS Client Development adr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA email;internet:cel@citi.umich.edu title:Member of Technical Staff tel;work:+1 734 763-4415 tel;fax:+1 734 763 4434 tel;home:+1 734 668-1089 x-mozilla-html:FALSE url:http://troy.citi.umich.edu/u/cel/ version:2.1 end:vcard ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] stgit: fix clone 2006-01-11 22:47 ` Chuck Lever @ 2006-01-12 11:54 ` Catalin Marinas 2006-01-12 14:51 ` Chuck Lever 2006-01-13 5:24 ` Pavel Roskin 0 siblings, 2 replies; 6+ messages in thread From: Catalin Marinas @ 2006-01-12 11:54 UTC (permalink / raw) To: cel; +Cc: Pavel Roskin, git [-- Attachment #1: Type: text/plain, Size: 994 bytes --] On 11/01/06, Chuck Lever <cel@citi.umich.edu> wrote: > Chuck Lever wrote: > > seems to me the "git clone" script should create an environment where > > "git-rev-parse --git-dir" ought to work correctly. > > stgit/main.py does a special stack.Series('master') just for the clone > command. it really shouldn't do this -- the crt_series.init() in the > clone command ought to be fixed to do this properly. If the stack.Series() doesn't get a parameter, it will try to get the default branch using 'git-symbolic-ref HEAD'. Any command run outside a tree (and which doesn't have the -h option) would fail. The clone command is the only one allowed to run outside a tree and that's why I passed a default branch name. This is to avoid the creation of another stack.Series() object later when the git tree was cloned. See the attached patch for a different fix and let me know if there are any issues with it. I should probably release 0.8.1 with the fixed bugs. -- Catalin [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: clone-fix.diff --] [-- Type: text/x-patch; name="clone-fix.diff", Size: 4168 bytes --] Fix the clone command failure From: Catalin Marinas <catalin.marinas@gmail.com> The clone command fails because there is no GIT tree available, which is wrong. The patch fixes the Series.__init__() function and also creates a new Series object in clone.py once a GIT tree was initialised. Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com> --- stgit/commands/clone.py | 2 +- stgit/main.py | 18 ++++++++---------- stgit/stack.py | 30 ++++++++++++++++-------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/stgit/commands/clone.py b/stgit/commands/clone.py index f4e3f6b..9ad76a6 100644 --- a/stgit/commands/clone.py +++ b/stgit/commands/clone.py @@ -51,6 +51,6 @@ def func(parser, options, args): os.chdir(local_dir) git.checkout(tree_id = 'HEAD') - crt_series.init() + stack.Series().init() print 'done' diff --git a/stgit/main.py b/stgit/main.py index b84d91d..2336a43 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -150,16 +150,14 @@ def main(): option_list = command.options) options, args = parser.parse_args() try: - # 'clone' doesn't expect an already initialised GIT tree - if cmd == 'clone': - stgit.commands.common.crt_series = stack.Series('master') - elif hasattr(options, 'branch') and options.branch: - stgit.commands.common.crt_series = stack.Series(options.branch) - else: - stgit.commands.common.crt_series = stack.Series() - # the line below is a simple way to avoid an exception when - # stgit is run outside an initialised tree - setattr(command, 'crt_series', stgit.commands.common.crt_series) + # 'clone' doesn't expect an already initialised GIT tree. A Series + # object will be created after the GIT tree is cloned + if cmd != 'clone': + if hasattr(options, 'branch') and options.branch: + command.crt_series = stack.Series(options.branch) + else: + command.crt_series = stack.Series() + stgit.commands.common.crt_series = command.crt_series command.func(parser, options, args) except (IOError, CmdException, stack.StackException, git.GitException), \ diff --git a/stgit/stack.py b/stgit/stack.py index 8b7c296..c2adeb9 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -257,21 +257,23 @@ class Series: def __init__(self, name = None): """Takes a series name as the parameter. """ - if name: - self.__name = name - else: - self.__name = git.get_head_file() - - if self.__name: + try: + if name: + self.__name = name + else: + self.__name = git.get_head_file() base_dir = git.get_base_dir() - self.__patch_dir = os.path.join(base_dir, 'patches', - self.__name) - self.__base_file = os.path.join(base_dir, 'refs', 'bases', - self.__name) - self.__applied_file = os.path.join(self.__patch_dir, 'applied') - self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied') - self.__current_file = os.path.join(self.__patch_dir, 'current') - self.__descr_file = os.path.join(self.__patch_dir, 'description') + except git.GitException, ex: + raise StackException, 'GIT tree not initialised: %s' % ex + + self.__patch_dir = os.path.join(base_dir, 'patches', + self.__name) + self.__base_file = os.path.join(base_dir, 'refs', 'bases', + self.__name) + self.__applied_file = os.path.join(self.__patch_dir, 'applied') + self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied') + self.__current_file = os.path.join(self.__patch_dir, 'current') + self.__descr_file = os.path.join(self.__patch_dir, 'description') def get_branch(self): """Return the branch name for the Series object ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] stgit: fix clone 2006-01-12 11:54 ` Catalin Marinas @ 2006-01-12 14:51 ` Chuck Lever 2006-01-13 5:24 ` Pavel Roskin 1 sibling, 0 replies; 6+ messages in thread From: Chuck Lever @ 2006-01-12 14:51 UTC (permalink / raw) To: Catalin Marinas; +Cc: Pavel Roskin, git [-- Attachment #1: Type: text/plain, Size: 1134 bytes --] Catalin Marinas wrote: > On 11/01/06, Chuck Lever <cel@citi.umich.edu> wrote: > >>Chuck Lever wrote: >> >>>seems to me the "git clone" script should create an environment where >>>"git-rev-parse --git-dir" ought to work correctly. >> >>stgit/main.py does a special stack.Series('master') just for the clone >>command. it really shouldn't do this -- the crt_series.init() in the >>clone command ought to be fixed to do this properly. > > > If the stack.Series() doesn't get a parameter, it will try to get the > default branch using 'git-symbolic-ref HEAD'. Any command run outside > a tree (and which doesn't have the -h option) would fail. The clone > command is the only one allowed to run outside a tree and that's why I > passed a default branch name. This is to avoid the creation of another > stack.Series() object later when the git tree was cloned. > > See the attached patch for a different fix and let me know if there > are any issues with it. I should probably release 0.8.1 with the fixed > bugs. looked at the patch. that's what i had in mind. the extra exception processing in Series.__init__ is a nice touch. [-- Attachment #2: cel.vcf --] [-- Type: text/x-vcard, Size: 451 bytes --] begin:vcard fn:Chuck Lever n:Lever;Charles org:Network Appliance, Incorporated;Open Source NFS Client Development adr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA email;internet:cel@citi.umich.edu title:Member of Technical Staff tel;work:+1 734 763-4415 tel;fax:+1 734 763 4434 tel;home:+1 734 668-1089 x-mozilla-html:FALSE url:http://troy.citi.umich.edu/u/cel/ version:2.1 end:vcard ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] stgit: fix clone 2006-01-12 11:54 ` Catalin Marinas 2006-01-12 14:51 ` Chuck Lever @ 2006-01-13 5:24 ` Pavel Roskin 1 sibling, 0 replies; 6+ messages in thread From: Pavel Roskin @ 2006-01-13 5:24 UTC (permalink / raw) To: Catalin Marinas; +Cc: cel, git On Thu, 2006-01-12 at 11:54 +0000, Catalin Marinas wrote: > See the attached patch for a different fix and let me know if there > are any issues with it. I should probably release 0.8.1 with the fixed > bugs. I see you have applied the fix already. Current StGIT is working fine when it comes to cloning. Thank you! -- Regards, Pavel Roskin ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-01-13 5:24 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-01-11 22:19 [PATCH] stgit: fix clone Pavel Roskin 2006-01-11 22:39 ` Chuck Lever 2006-01-11 22:47 ` Chuck Lever 2006-01-12 11:54 ` Catalin Marinas 2006-01-12 14:51 ` Chuck Lever 2006-01-13 5:24 ` Pavel Roskin
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).