@@ -121,9 +121,9 @@ def _set_cache_(self, attr):
121121 # default submodule values
122122 try :
123123 self .path = reader .get ('path' )
124- except cp .NoSectionError :
124+ except cp .NoSectionError as e :
125125 raise ValueError ("This submodule instance does not exist anymore in '%s' file"
126- % osp .join (self .repo .working_tree_dir , '.gitmodules' ))
126+ % osp .join (self .repo .working_tree_dir , '.gitmodules' )) from e
127127 # end
128128 self ._url = reader .get ('url' )
129129 # git-python extension values - optional
@@ -189,9 +189,9 @@ def _config_parser(cls, repo, parent_commit, read_only):
189189 assert parent_commit is not None , "need valid parent_commit in bare repositories"
190190 try :
191191 fp_module = cls ._sio_modules (parent_commit )
192- except KeyError :
192+ except KeyError as e :
193193 raise IOError ("Could not find %s file in the tree of parent commit %s" %
194- (cls .k_modules_file , parent_commit ))
194+ (cls .k_modules_file , parent_commit )) from e
195195 # END handle exceptions
196196 # END handle non-bare working tree
197197
@@ -516,9 +516,9 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
516516 if not dry_run and osp .isdir (checkout_module_abspath ):
517517 try :
518518 os .rmdir (checkout_module_abspath )
519- except OSError :
519+ except OSError as e :
520520 raise OSError ("Module directory at %r does already exist and is non-empty"
521- % checkout_module_abspath )
521+ % checkout_module_abspath ) from e
522522 # END handle OSError
523523 # END handle directory removal
524524
@@ -737,8 +737,8 @@ def move(self, module_path, configuration=True, module=True):
737737 del (index .entries [ekey ])
738738 nentry = git .IndexEntry (entry [:3 ] + (module_checkout_path ,) + entry [4 :])
739739 index .entries [tekey ] = nentry
740- except KeyError :
741- raise InvalidGitRepositoryError ("Submodule's entry at %r did not exist" % (self .path ))
740+ except KeyError as e :
741+ raise InvalidGitRepositoryError ("Submodule's entry at %r did not exist" % (self .path )) from e
742742 # END handle submodule doesn't exist
743743
744744 # update configuration
@@ -871,7 +871,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
871871 rmtree (wtd )
872872 except Exception as ex :
873873 if HIDE_WINDOWS_KNOWN_ERRORS :
874- raise SkipTest ("FIXME: fails with: PermissionError\n {}" .format (ex ))
874+ raise SkipTest ("FIXME: fails with: PermissionError\n {}" .format (ex )) from ex
875875 raise
876876 # END delete tree if possible
877877 # END handle force
@@ -882,7 +882,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
882882 rmtree (git_dir )
883883 except Exception as ex :
884884 if HIDE_WINDOWS_KNOWN_ERRORS :
885- raise SkipTest ("FIXME: fails with: PermissionError\n %s" , ex )
885+ raise SkipTest ("FIXME: fails with: PermissionError\n %s" , ex ) from ex
886886 else :
887887 raise
888888 # end handle separate bare repository
@@ -1046,8 +1046,8 @@ def module(self):
10461046 if repo != self .repo :
10471047 return repo
10481048 # END handle repo uninitialized
1049- except (InvalidGitRepositoryError , NoSuchPathError ):
1050- raise InvalidGitRepositoryError ("No valid repository at %s" % module_checkout_abspath )
1049+ except (InvalidGitRepositoryError , NoSuchPathError ) as e :
1050+ raise InvalidGitRepositoryError ("No valid repository at %s" % module_checkout_abspath ) from e
10511051 else :
10521052 raise InvalidGitRepositoryError ("Repository at %r was not yet checked out" % module_checkout_abspath )
10531053 # END handle exceptions
0 commit comments