1

I have a repo where I have two branches: master and master_one. I have one commit (commit1) in master branch that is not present in master_one. Now I have created one more branch 'temp' from master_one. I wanted to merge the changes present in commit1 to my branch temp using PyGithub. I am able to merge it if I am creating a branch from master using the below code:

repo.merge(branch_name,commit_sha_key,"merge to master") 

where commit_sha_key is the sha of commit1.

But same thing I am not able to do for my temp branch that I have created from master_one.

Is there any way to do it? Thanks

codeninja
  • 11
  • 3
  • What happens if you try? – Ezra Jul 13 '21 at 06:44
  • It is not merging the changes of commit1 in temp branch. – codeninja Jul 13 '21 at 06:55
  • Does it fail silently or with an error? – Ezra Jul 13 '21 at 06:56
  • It is not failing I am not seeing any error but after the code get executed I am not seeing any commit in temp branch. – codeninja Jul 13 '21 at 06:59
  • And if you print the output? – Ezra Jul 13 '21 at 07:02
  • Actually I am getting this time out error:- HTTPSConnectionPool(host='github.abc.com', port=443): Read timed out. (read timeout=15) – codeninja Jul 13 '21 at 07:14
  • Are you using regular, public GitHub? If so, what is github.abc.com? – Ezra Jul 13 '21 at 07:18
  • I am using github enterprise. In github.abc.com, abc is enterprise name. – codeninja Jul 13 '21 at 07:22
  • And you don’t get the timeout for the master branch? – Ezra Jul 13 '21 at 07:24
  • no for the branch created from master, I am not getting this. – codeninja Jul 13 '21 at 07:25
  • What happens if you try cURLing the api directly? – Ezra Jul 13 '21 at 07:28
  • Is is something because commit1 is present in master so when I create some branch from master itself it is having all the previous commits before commit1 already present there. So it is only merging the the changes present in commit1. But for temp branch which is created from master-one, it is trying to merge all the commits present in master so getting timedout? – codeninja Jul 13 '21 at 07:28
  • @Ezra, I am not getting how to use cURLing directly? – codeninja Jul 13 '21 at 07:30
  • yes that’s my theory (if I understand you correctly). Direct api reference, with curl instructions: https://docs.github.com/en/rest/reference/repos#merging – Ezra Jul 13 '21 at 07:37
  • If I am using git cherry-pick from command line, I am able to merge commit1 in temp branch. Is there something that I can do with PyGitHub? – codeninja Jul 13 '21 at 07:59
  • I found here https://github.community/t/do-a-cherry-pick-via-the-api/14573 there is no direct github api for cherry pick. The functionality has latest been added in github desktop only. Is there any other way? I am right now stuck at this point. – codeninja Jul 13 '21 at 10:00
  • Can someone suggest me any way to achieve it? It will be very helpful. – codeninja Jul 13 '21 at 14:07
  • see my answer. You can’t do it from pygithub, but that doesn’t mean you can’t do it (or that it’s hard) – Ezra Jul 13 '21 at 15:20

1 Answers1

0

Cherry pick isn’t supported by the GitHub api, so you’ll have to do it from the command line:

# ~~~ snip initialize git repo locally, maybe using git clone  ~~~
import os
os.system(f"git cherry-pick {commit_sha_key}")
os.system("git push")  # you may need to do "git push origin temp"
# ~~~ snip ~~~ cleanup, if you want. 
Ezra
  • 471
  • 3
  • 14