GitPython

git log --follow, the gitpython way

独自空忆成欢 提交于 2021-02-05 17:58:33
问题 I am trying to access the commit history of a single file as in: git log --follow -- <filename> I have to use gitpython, so what I am doing now is: import git g = git.Git('repo_dir') hexshas = g.log('--pretty=%H','--follow','--',filename).split('\n') then I build commit objects: repo = git.Repo('repo_dir') commits = [repo.rev_parse(c) for c in r] Is there a way to do it in a more gitpython-ic way? I tried both commit.iter_parents() and commit.iter_items() , but they both rely on git-rev-list

How to get commit author name and email with gitpython?

眉间皱痕 提交于 2020-08-26 05:41:08
问题 When I run git log , I get the this line for each commit: "Author: name < email >". How do I get the exact same format for a commit in Python for a local repo? When I run the code below, I get just the author name. from git import Repo repo_path = 'mockito' repo = Repo(repo_path) commits_list = list(repo.iter_commits()) for i in range(5): commit = commits_list[i] print(commit.hexsha) print(commit.author) print(commit.committer) 回答1: It seems that gitpython's Commit objects do not have an

How to get commit author name and email with gitpython?

╄→гoц情女王★ 提交于 2020-08-26 05:39:11
问题 When I run git log , I get the this line for each commit: "Author: name < email >". How do I get the exact same format for a commit in Python for a local repo? When I run the code below, I get just the author name. from git import Repo repo_path = 'mockito' repo = Repo(repo_path) commits_list = list(repo.iter_commits()) for i in range(5): commit = commits_list[i] print(commit.hexsha) print(commit.author) print(commit.committer) 回答1: It seems that gitpython's Commit objects do not have an

通过Python扫描代码关键字并进行预警

空扰寡人 提交于 2020-08-09 11:03:04
近期线上出现一个bug,研发的小伙伴把测试环境的地址写死到代码中,在上线前忘记修改,导致线上发布的代码中使用了测试环境地址。 开发过程中虽然有各种规范制度,但是难免有粗心,与其责备不如通过技术手段将问题进行避免。 为了达到上述需求,初步想通过以下步骤来实现代码关键字自动扫描告警。 Python安装 Git安装 GitPython安装 定时任务配置(方案一:crontab 方案二:APScheduler) git代码获取 关键词扫描 邮件告警 #安装python的依赖包 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz- devel libffi-devel gcc #下载Python安装包,版本号:Python-3.7.1.tgz(在/ opt下创建目录Python3) wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz #解压安装包 tar -zxvf Python-3.8.1.tgz #指定python3安装目录 ./configure --prefix=/usr/local

how do I emulate read and update git global config file using gitPython?

天涯浪子 提交于 2020-06-02 17:08:20
问题 I want to reads git global config file using git config --list , so I can use to read and update the global config file ? 回答1: This will give you the ~/.gitconfig type config: globalconfig = git.GitConfigParser([os.path.normpath(os.path.expanduser("~/.gitconfig"))], read_only=True) That's more or less what gitpython itself does, except it also uses "system" and "repo" level configs (where system is "/etc/gitconfig"), see def _get_config_path(self, config_level): and def config_reader(self,

gitpython git authentication using user and password

折月煮酒 提交于 2020-05-11 04:15:33
问题 I'm using GitPython but did not find a way to push to repo using username and password. Can anybody send me a working example or give me some pointer about how to do it? What I need to do is: add a file to the repository, push it using the username and password provided. 回答1: This is what I used for myself for pulling pull.py #! /usr/bin/env python3 import git import os from getpass import getpass project_dir = os.path.dirname(os.path.abspath(__file__)) os.environ['GIT_ASKPASS'] = os.path

gitpython git authentication using user and password

荒凉一梦 提交于 2020-05-11 04:15:32
问题 I'm using GitPython but did not find a way to push to repo using username and password. Can anybody send me a working example or give me some pointer about how to do it? What I need to do is: add a file to the repository, push it using the username and password provided. 回答1: This is what I used for myself for pulling pull.py #! /usr/bin/env python3 import git import os from getpass import getpass project_dir = os.path.dirname(os.path.abspath(__file__)) os.environ['GIT_ASKPASS'] = os.path

Get tags of a commit

戏子无情 提交于 2020-03-27 03:17:49
问题 Given an object of GitPython Commit, how can I get the tags related to this commit? I'd enjoy having something like: next(repo.iter_commits()).tags 回答1: The problem is that tags point to commits, not the other way around. To get this information would require a linear scan of all tags to find out which ones point to the given commit. You could probably write something yourself that would do it. The following would get you a commit-to-tags dictionary: tagmap = {} for t in repo.tags(): tagmap

gitpython - how to check if a remote branch exists?

萝らか妹 提交于 2020-01-24 15:59:26
问题 I'm new to gitpython and haven't been able to find a reference to this anywhere. What I'm looking to do is something like: If remote branch name exists: do something else: do something else Any suggestions? 回答1: This may not work, but give it a shot let me know how it goes: does_exist = True try: repo.git.checkout('branch_name') except repo.exc.GitCommandError: does_exist = False print(does_exist) This may also work but give it a try: repo.git.rev_parse('--verify', 'branch_name') 回答2: Thanks