def cloned_dist_git(self, url, commit, workdir): repo = git.Repo.clone_from(url, workdir) repo.git.checkout(commit) # Configure user otherwise app.apply_changes() will fail repo.git.config('user.name', GitHelper.get_user(), local=True) repo.git.config('user.email', GitHelper.get_email(), local=True) return repo
def init_git(cls, directory): """Function initialize old and new Git repository""" repo = git.Repo.init(directory) repo.git.config('user.name', GitHelper.get_user(), local=True) repo.git.config('user.email', GitHelper.get_email(), local=True) repo.git.add(all=True) repo.index.commit('Initial commit', skip_hooks=True) return repo
def _prepare_rebased_repository(cls, patches, rebased_sources_dir): """ Initialize git repository in the rebased directory :return: git.Repo instance of rebased_sources """ for patch in patches['applied'] + patches['not_applied']: shutil.copy(patch.path, rebased_sources_dir) repo = git.Repo.init(rebased_sources_dir) repo.git.config('user.name', GitHelper.get_user(), local=True) repo.git.config('user.email', GitHelper.get_email(), local=True) repo.git.add(all=True) repo.index.commit('Initial commit', skip_hooks=True) return repo
def test_get_user_and_email(self, config, workdir): name = 'Foo Bar' email = '*****@*****.**' env_git_config = os.environ.get('GIT_CONFIG') env_xdg_config_home = os.environ.get('XDG_CONFIG_HOME') try: if config == 'global': work_git_path = os.path.join(workdir, 'git') os.makedirs(work_git_path) config_file = os.path.join(work_git_path, 'config') self.write_config_file(config_file, name, email) os.environ['XDG_CONFIG_HOME'] = workdir elif config == 'global_include': work_git_path = os.path.join(workdir, 'git') os.makedirs(work_git_path) config_file = os.path.join(work_git_path, 'config') with open(config_file, 'w') as f: f.write('[include]\n' ' path = included_config\n') included_config_file = os.path.join(work_git_path, 'included_config') self.write_config_file(included_config_file, name, email) os.environ['XDG_CONFIG_HOME'] = workdir elif config == 'local': repo = git.Repo.init(workdir) repo.git.config('user.name', name, local=True) repo.git.config('user.email', email, local=True) elif config == 'env': config_file = os.path.join(workdir, 'git_config') os.environ['GIT_CONFIG'] = config_file self.write_config_file(config_file, name, email) else: raise RuntimeError() assert name == GitHelper.get_user() assert email == GitHelper.get_email() finally: if env_git_config: os.environ['GIT_CONFIG'] = env_git_config elif 'GIT_CONFIG' in os.environ: del os.environ['GIT_CONFIG'] if env_xdg_config_home: os.environ['XDG_CONFIG_HOME'] = env_xdg_config_home elif 'XDG_CONFIG_HOME' in os.environ: del os.environ['XDG_CONFIG_HOME']