5

I'm writing an external Git plugin. It should process commits in Git and create some entity in another system if commit contains some text. Note that I want to search through all entire repository, not some branch. Also I have storage in my plugin, so I can store some revision SHA for example

I clone Git repository locally and fetch it periodically. During fetch I want to discover which new commits were added since last synchronization. Is there any easy way to do this?

One solution is to create local branches, and after fetch discover the difference between local branch and origin branch. But what to do if there was forced update on remote branch? In that case difference can be huge, and the same commits can be processed twice. Also if I will use local branches solution, and new branch is added on remote server, I definitely do not want to process all commits in new branch, just the unique one.

Git 'fetch' command definitely can do this. So I hope there is some easy way.

struhtanov
  • 416
  • 2
  • 10
  • Seems like a duplicate of http://stackoverflow.com/questions/1331385/how-can-i-see-incoming-commits-in-git – Anshul Goyal Sep 12 '13 at 08:15
  • Not sure it is. The answer you mention requires creating of local branches. Also still no answer of duplicate commit processing in case of remote branch was updated with '--force' parameter. – struhtanov Sep 12 '13 at 08:27
  • You want to do it across branches? As in commits made to all branches since last pull? – Anshul Goyal Sep 12 '13 at 08:29
  • Exactly. I've edited my question to mention this. – struhtanov Sep 12 '13 at 08:38
  • Since You are going to update another system, I think it should be possible to store the SHA for each of the commits you are going to count. That should resolve the problem of duplicate commits. Regarding new commits made, I can't think of any other way other than local branches. – Anshul Goyal Sep 12 '13 at 08:45
  • I dont really know an answer, but it seems that Egit is actually able to do what you want. If i fetch something using Egit, i always get displayed what was fetched, across all fetched branches. Same is valid for push btw. – functionpointer Sep 12 '13 at 08:45
  • @Oznerol256 Are you talking commits, or files modified? – Anshul Goyal Sep 12 '13 at 08:46
  • ansh0l : Storing SHA is not an option. There can be million commit repository. It will require a lot of storage. But this will definitely solve my issue. – struhtanov Sep 12 '13 at 08:52

1 Answers1

1
  • If you have only one clone, you can add a git notes to remember the HEAD SHA1 you just fetched
  • If you can have two clones:
    • you fetch in the first
    • you compare between what you have fetch and you second cloned repo
    • once you have compared the log, you push to that second repo (which act as a memento for keeping the state of your last push)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok, I got SHA1(also as I want to scan cross-branch, I should remember SHA1 of each branch). What next? If branch was updated with '--force' flag and there is no such SHA1 anymore? – struhtanov Sep 12 '13 at 12:03
  • @struhtanov what next is described in the already mentioned http://stackoverflow.com/q/1331385/6309. You compare between your fetch and git notes, or git SHA1 of the second repo: `git log yourRepoHEAD..mementoRepoHEAD`. This cannot cope well with forced pushes, though. – VonC Sep 12 '13 at 12:07
  • As there is no other easier approaches, and this answer solves the task, I mark it as an answer. Thanks. – struhtanov Sep 26 '13 at 07:43