pygit2

How to know if a git repository is clean with Python3 (pygit2)?

天涯浪子 提交于 2020-06-18 11:18:34
问题 I'm trying to determine if a or git commit is needed in a git repository. I come up with this code that works fine for me : def is_dirty(repo): import pygit2 status = repo.status() for filepath, flags in status.items(): if flags != pygit2.GIT_STATUS_CURRENT: if flags != 16384: return True return False; But this is extremely inefficient : the repo.status() takes forever -- at least compared to the git status command line. So my question is : is there a more efficient way to know if the

How to know if a git repository is clean with Python3 (pygit2)?

杀马特。学长 韩版系。学妹 提交于 2020-06-18 11:17:01
问题 I'm trying to determine if a or git commit is needed in a git repository. I come up with this code that works fine for me : def is_dirty(repo): import pygit2 status = repo.status() for filepath, flags in status.items(): if flags != pygit2.GIT_STATUS_CURRENT: if flags != 16384: return True return False; But this is extremely inefficient : the repo.status() takes forever -- at least compared to the git status command line. So my question is : is there a more efficient way to know if the

Steps for pulling from remote using pygit2

[亡魂溺海] 提交于 2020-02-23 04:47:07
问题 While using the pygit2 library a simple repo.fetch() fetches all the diffs. The answer here describes the steps viz 1. Remote.fetch() 2. Repository.create_reference() or Reference.target= 3. Repository.checkout_head() I am not sure about what is happening under the hood in second step and what parameters need to be passed. r.repo.create_reference: (self, name, target, force=False) Create a new reference "name" which points to an object or to another reference. Based on the type and value of

Implementing Pull with Pygit2

邮差的信 提交于 2020-01-04 04:08:05
问题 I am trying to implement some 'porcelain' commands using pygit2. It seems that I have run into a bit of road block while implementing pull. Specifically the easiest pull case, a fast forward. Setup: I have two git repos. One 'remote' and one 'local'. I make one commit on the remote repo and then create the local repo using pygit2's clone_repository() . I make a subsequent commit on the remote and then attempt to run the pull() function outlined below. My implementation: def pull(repo, remote

What is the difference between Repository.checkout() and Repository.checkout_head() in pygit2?

有些话、适合烂在心里 提交于 2019-12-25 00:52:12
问题 When pulling and integrating changes from remote with pygit2, the last step is to checkout using Repository.checkout() or Repository.checkout_head() . Which to use? Both of these take a checking out strategy as an argument. Now there are a couple of strategies for checking out viz GIT_CHECKOUT_SAFE, GIT_CHECKOUT_SAFE_CREATE, GIT_CHECKOUT_FORCE etc. The problem I am facing is that even after checking out the index file is modified ie there are a couple of files in it that are staged. r.repo

Unable to ssh push in pygit2

只愿长相守 提交于 2019-12-24 11:35:43
问题 I am trying to push using ssh to a github repo using pygit2. Here is the error I keep getting. Can you point out the error? >>> sshcred = repo_.pygit2.credentials.Keypair('avckp','id_rsa.pub','id_rsa','') >>> remo2.credentials=sshcred ## remo2 is a remote object for the repo >>> remo2.url u'https://github.com/avckp/sansa-pygit.git' >>> remo2.push_url = remo2.url >>> remo2.push('refs/heads/master') Traceback (most recent call last): File "<input>", line 1, in <module> File "pygit2/remote.py",

Difference between “(no branch)” and “(detached at abc1234)”

ε祈祈猫儿з 提交于 2019-12-22 09:50:18
问题 Normally when you run something like this inside of a git repository: git checkout abc1234 You end up in a detached HEAD state. If you run git branch , the output will look something like this: * (detached from abc1234) master This is fine and expected behaviour. I've been playing around with pygit2 recently, and have come across something I haven't seen before. Let's say I do the following: repo = pygit2.discover_repository("/path/to/repo") repo.head = "abc1234" I would expect the repository

Cloning only the main branch using PyGit2

混江龙づ霸主 提交于 2019-12-13 07:36:59
问题 I want to clone some remote repositories, but only retrieving the main branch. My code currently gets all of the branches. def init_remote(repo, name, url): # Create the remote with a mirroring url remote = repo.remotes.create(name, url, "+refs/*:refs/*") # And set the configuration option to true for the push command mirror_var = "remote.{}.mirror".format(name) repo.config[mirror_var] = True # Return the remote, which pygit2 will use to perform the clone return remote pygit2.clone_repository

How can I perform a rebase with pygit2?

寵の児 提交于 2019-12-10 12:17:11
问题 This question touches on how to perform a merge with pygit2 , but, to the best of my understanding, that will result in a new commit. Is there a way to perform a rebase, which will not result in a new commit and will simply fast-forward the branch reference to correspond to the latest from a given remote? 回答1: You can fast-forward with Reference.set_target(). Example (fast-forwarding master to origin/master , assuming that the script starts from checked out master branch in clean state): repo

Steps for pulling from remote using pygit2

夙愿已清 提交于 2019-12-06 16:46:15
While using the pygit2 library a simple repo.fetch() fetches all the diffs. The answer here describes the steps viz 1. Remote.fetch() 2. Repository.create_reference() or Reference.target= 3. Repository.checkout_head() I am not sure about what is happening under the hood in second step and what parameters need to be passed. r.repo.create_reference: (self, name, target, force=False) Create a new reference "name" which points to an object or to another reference. Based on the type and value of the target parameter, this method tries to guess whether it is a direct or a symbolic reference. Keyword