def changed_python_files_in_tree(root_path): # type: (str) -> typing.List[str] git_repo = repo.Repo(root_path) remote_master = _remote_origin_master(git_repo) modified = _modified_in_branch(git_repo, remote_master) abs_modified = [os.path.join(git_repo.working_dir, x) for x in modified] return [mod for (mod, abs_mod) in zip(modified, abs_modified) if os.path.exists(abs_mod) and os.path.isfile(abs_mod) and _file_is_python(abs_mod)]
def __call__(self, path): repository_paths = [] for repository in self.repositories: if isinstance(repository, str): repository_paths.append(repository) elif hasattr(repository.__path__, "_path"): repository_paths.append(repository.__path__._path[0]) else: repository_paths.append(repository.__path__[0]) for repository_path in repository_paths: # create a git diff of the changes against head. current_repository = repo.Repo(repository_path) repository_changes = current_repository.git.diff() diff_name = os.path.basename( repository_path) + SaveCodeChanges.DIFF_EXTENSION with open(os.path.join(path, diff_name), "w") as diff_file: diff_file.write(repository_changes)
def test_git_package(develop_mode, git_package_root): # type: (bool, 'py.path.LocalPath') -> None git_sha = str(repo.Repo(str(git_package_root)).commit()) with package_installed(git_package_root, develop_mode=develop_mode): assert git_sha == call_get_package_revision()
__author__ = 'Gareth Coles' #: The current version. This gets replaced if you're using git. __version__ = "1.1.0" __version_info__ = "Not being run from a Git repo." __release__ = "1.1.0" version_info = {"release": __release__, "hash": None, "commit": None} import datetime try: from git import repo r = repo.Repo(".") heads = r.heads master = heads[0] commit = master.commit __version__ = "Git: %s" % commit __version_info__ = "Last commit by %s (%s) - %s" % \ (commit.author, datetime.datetime.fromtimestamp( commit.committed_date ).strftime("%d %b, %Y - %H:%M:%S"), commit.summary.replace("\n", " / ")) version_info["hash"] = str(commit) version_info["commit"] = commit.summary.replace("\n", " / ") except Exception as e: if __version__ is None: __version__ = "1.1.0"
print(str(commit.hexsha)) print("\"{}\" by {} ({})".format(commit.summary, commit.author.name, commit.author.email)) print(str(commit.authored_datetime)) print(str("count: {} and size: {}".format(commit.count(), commit.size))) def print_repository(repo): print('Repo description: {}'.format(repo.description)) print('Repo active branch is {}'.format(repo.active_branch)) for remote in repo.remotes: print('Remote named "{}" with URL "{}"'.format(remote, remote.url)) print('Last commit for repo is {}.'.format(str(repo.head.commit.hexsha))) if __name__ == "__main__": repo_path = os.getenv('GIT_REPO_PATH') # Repo object used to programmatically interact with Git repositories repo = repo.Repo(repo_path) # check that the repository loaded correctly if not repo.bare: print('Repo at {} successfully loaded.'.format(repo_path)) print_repository(repo) # create list of commits then print some of them to stdout commits = list(repo.iter_commits('master'))[:COMMITS_TO_PRINT] for commit in commits: print_commit(commit) pass else: print('Could not load repository at {} :('.format(repo_path))
cacertca = infile.read() with open(cafile, 'ab') as outfile: outfile.write(cacertca) # -- Project information ----------------------------------------------------- project = 'CAcert code documentation' copyright = '2018-2020 CAcert development team' author = 'CAcert development team' # The short X.Y version version = '0.1' # The full version, including alpha/beta/rc tags release = "{}-git:{} built:{}".format( version, repo.Repo('..').git.describe('--always', '--dirty'), datetime.utcnow().replace(microsecond=0)) # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.intersphinx', 'sphinx.ext.extlinks', 'sphinx.ext.todo',
from git import repo import os assert not Repo.delete_remote(origin).exists() # TODO: Instead of hard-coding the path, you should've passed it via commandline Repo = repo.Repo('/home/ar.sehgal/newrepo') #os.system('git remote remove origin') # TODO: You did not need create any remote origin. You just needed to fetch latest content from remote repository. ie just git pull origin = Repo.create_remote('origin', 'https://github.com/arpit110298/test') assert origin.exists() Repo.create_head('master', origin.refs.master).set_tracking_branch( origin.refs.master).checkout() origin.pull()