GitPython

How to write unit tests for GitPython clone/pull functions?

不问归期 提交于 2020-01-22 16:10:33
问题 I have a python project that is using GitPython to perform clone and pull functions against a remote Git repository. As a simple example: import git from git import Git from git import Repo def clone_and_checkout(full_dir, git_url, repo_ver): repo = Repo.clone_from( url=git_url, to_path=full_dir ) # Trigger re-create if repository is bare if repo.bare: raise git.exc.InvalidGitRepositoryError # Set origin and pull origin = repo.remotes.origin origin.pull() # Check out desired version of

how to do a git diff of current commit with last commit using gitpython?

巧了我就是萌 提交于 2020-01-21 09:52:24
问题 I am trying o grasp gitpython module, hcommit = repo.head.commit tdiff = hcommit.diff('HEAD~1') but tdiff = hcommit.diff('HEAD^ HEAD') doesn't work !! neither does ('HEAD~ HEAD') ., I am trying to get the diff output ! 回答1: import git repo = git.Repo('repo_path') commits_list = list(repo.iter_commits()) # --- To compare the current HEAD against the bare init commit a_commit = commits_list[0] b_commit = commits_list[-1] a_commit.diff(b_commit) This will return a diff object for the commits.

How to query the log of a specific git repo branch using gitpython?

橙三吉。 提交于 2020-01-16 16:31:32
问题 Goal: Perform the following git command within a python script using gitpython. cmdLine Version: git log -L :dataLoad:/home/ubuntu/projects/alpha-draw/py/enigma.py Script Version: repo.git.log(f'-L :dataLoad:/home/ubuntu/projects/alpha-draw/py/enigma.py') This results in the following error, git.exc.GitCommandError: Cmd('git') failed due to: exit code(128) cmdline: git log -L :dataLoad:/home/ubuntu/projects/alpha-draw/py/enigma.py stderr: 'fatal: -L argument not 'start,end:file' or ':funcname

OSError: [Errno 2] No such file or directory on GitPython

☆樱花仙子☆ 提交于 2020-01-11 07:47:10
问题 I am using GitPython to fetch a remote repository to my machine. The following code works well on my Ubuntu 12.04 but on my amazon ec2, on a Ubuntu 11.10 server, I get the OSError: [Errno 2] No such file or directory error. repo = git.Repo.init(fs_path) origin = repo.create_remote('origin',repo_url) origin.fetch() origin.pull(origin.refs[0].remote_head) When I run the block in a script, I don't get any error messages. But when I try these steps on Interactive shell I get this stack trace: >>>

Use GitPython to Checkout a new branch and push to remote

久未见 提交于 2020-01-01 06:07:44
问题 Given a repo(GitPython) - how can i create a new local branch, add some files, and push it to remote using GitPython? repo example: from git import * curr_dir = os.path.dirname(os.path.realpath(__file__)) repo = Repo(curr_dir) for now i'm just using subprocess: def publish_changes_to_git(commit_msg): curr_time = time.time() ts = datetime.datetime.fromtimestamp(curr_time).strftime('%Y-%m-%d-%H-%M-%S') branch_name = "auto-commit-{ts}".format(ts=ts) subprocess.check_output(["git", "checkout", "

Python os.getlogin problem

会有一股神秘感。 提交于 2020-01-01 04:12:06
问题 If i create a file like: import os print os.getlogin() and run it with cron, I get an exception print os.getlogin() OSError: [Errno 22] Invalid argument If I run it manually in shell -- it works. Problem is, GitPython 0.3.1 in commit() uses this function, and i need to use it. Is there any workaround? I've tested it on Ubuntu10.10/python2.6.6 and Debian5.0.6/python2.5.2. 回答1: From the os.getlogin() docs: "Returns the user logged in to the controlling terminal of the process." Your script does

Get changed files using gitpython

风流意气都作罢 提交于 2019-12-30 04:17:18
问题 I want to get a list of changed files of the current git-repo. The files, that are normally listed under Changes not staged for commit: when calling git status . So far I have managed to connected to the repository, pulled it and show all untracked files: from git import Repo repo = Repo(pk_repo_path) o = self.repo.remotes.origin o.pull()[0] print(repo.untracked_files) But now I want to show all files, that have changes (not commited). Can anybody push me in the right direction? I looked at

Authentication in gitpython

萝らか妹 提交于 2019-12-24 12:43:03
问题 I am trying to write a fairly simple function (I thought). I want a user to specify a path to a checked out git repo on his computer. (A git repo that requires authentication). I then want to do a git pull on that folder to grab any changes. My code looks like this: import git repo=git.cmd.Git(GIT_PATH) repo.pull() This works perfectly on my Linux machine, it never asks for any credentials (I am guessing because ssh-agent has already unlocked the key and supplies credentials when my script

Get a list of changed files between two commits or branches

廉价感情. 提交于 2019-12-24 02:23:33
问题 I'm a Python/Git newb but I'm trying to write a script that takes two branches or commits as parameters and shows a list of changed files between the two, not all the extraneous info that comes with a regular diff. This was accomplished in bash scripting by using git diff --name-only FIRSTBRANCH...SECONDBRANCH but it isn't translating as easily to Python scripting using gitpython. If anyone has any idea how to do this, that'd be great. edit: heres some code user = str(sys.argv[1]) password =

GitPython - cloning with ssh key - Host key verification failed

杀马特。学长 韩版系。学妹 提交于 2019-12-24 01:56:39
问题 i have a problem with cloning git repository in my application. KEY_FILE = "/opt/app/.ssh/id_rsa" def read_git_branch(config_id, branch): config = RepoConfig.objects.get(id=config_id) save_rsa_key(Credentials.objects.get(id=1).key) git_ssh_identity_file = os.path.expanduser(KEY_FILE) git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file with Git().custom_environment(GIT_SSH_COMMAND=git_ssh_cmd): with tempfile.TemporaryDirectory() as tmpdir: repo = Repo.clone_from(config.url, tmpdir, branch=branch