1

I am working on a python script to automatically sync my workspace if possible and need to judge if I can rebase my changes on top of remote master changes.

I am trying to use the brilliant answer here : https://stackoverflow.com/a/6283843/965830

I want to run the following commands :

  1. Fetch the remote to your repository. For example: git fetch origin master
  2. Run git merge-base: git merge-base FETCH_HEAD master
  3. Run git merge-tree: git merge-tree mergebase master FETCH_HEAD (mergebase is the hexadecimal id that merge-base printed in the previous step)

For command 1, I am using the following successfully

gitRepo = git.Repo(abspath);
gitRepo.remotes.origin.fetch(refspec="master")

However, I am not able to find any documentation for merge-base and merge-tree commands.

------Edit

Found this documentation of merge-tree : https://gitpython.readthedocs.io/en/stable/reference.html?highlight=merge-tree#git.index.base.IndexFile.merge_tree

How can I write this in a way that it doesn't actually perform the merge.

tanvi
  • 927
  • 5
  • 17
  • 32
  • Why write this in python when it's much easier to write it as a shell script? – torek Mar 20 '21 at 22:18
  • I have other parts of the script which would need arrays to keep track of all the repositories and workspaces. That was becoming quite troublesome in shell. – tanvi Mar 22 '21 at 06:30
  • OK. Remember that you can always spin off a Git command with `subprocess`. Most Git commands that produce program-digestible output have a `-z` or similar option to produce usable byte streams. `git merge-tree` does not, but it's not really used any more. Aside from routine maintenance the last update to it was in 2013. You might be better off using a temporary index and `git read-tree` directly. – torek Mar 22 '21 at 19:47

0 Answers0