Recently, I have used Trac to manage a git project, and I used a git post-receive hook to sync the commit back to Trac.
The hook starts with something like this:
1 2 |
read oldrev newrev refname REV=$(git rev-list "$oldrev..$newrev") /usr/local/bin/trac-admin /app/trac/trac_env changeset added $git_name $REV |
It works fine for most cases, however, when I try to push a new branch to remote, the $oldrev becomes 0, and caused problem.
fatal: ambiguous argument '0..70e0844': unknown revision or path not in the working tree.
Naturally, I would like to figure out a way the find the beginning commit of the branch.
I thought it's going to be easy, and I googled around, and quickly find the following post in stackoverflow:
http://stackoverflow.com/questions/1527234/finding-a-branch-point-with-git
When you look into the post closely, you will find something very interesting:
-
It’s a very popular question, 289 votes, and a lot of highly voted answers. This is actually very common in stackoverflow. There are far far more questions about git (85477 questions so far) than svn (24616 questions so far), despite svn has a much longer history than git.
-
There are so many in-depth discussions in the thread, that you could hardly understand all the discussions unless you are really an expert about git. Unlike most python related questions, I could just pick the highly voted answer, read it, digest it, and use the remedy or concept there. They are just plain english. However, for the git answers, people (almost always) has to explain a lot of background knowledge before they could get into the answer, which you still might not understand.
-
Unfortunately, there is no single best answer after all those discussions. And I have tried all of them, none worked reliably for me. Some gives error due to version problem, and some just give a wrong result to me. I am pretty sure I am not the only one confused, because there are a lot of extra hard-to-understand comments under each hard-to-understand answers.
This is really frustrating. I mean if it could not be done, then just tell me you can’t. But the discussions are so ‘geek' there, and every body seems excited around all those discussions. I thought git is a tool to serve people, but for those people, they are just proud of being able to throughly understand and manipulate a beast.
It’s just abnormal to me. So I guess I should understand how xcode and visual studio are written and compiled, before I could happily use them? Oh, may be all people using tortoise SVN should be burned to die, because it’s just so damn easy to use? Why git has to be so difficult?
May be this question senario is not common? But seriously, I only wanted to know where my branch started in my git-post-receive hook, I believe it’s just a fair question. And I really don’t expect such rocket science discussions at the thread.
Oh, may be the difficulty is intrinsic? Being a distributed version control system must be that hard, and you could never escape from that? It must be the same case for other DVCS like mercury?
I once believed in this way, until one day I found a nice discussion thread here:
https://stevebennett.me/2012/02/24/10-things-i-hate-about-git/
Yeah, the title is very much biased. But it has the most through discussions in the comment section among all my readings.
So, now I have to say,
Thank God! I am not crazy, and I am not the only person in the planet earth that could not get comfortable with git even after YERARS of use!!! I think the following quote illustrate the current scenario the best:
Git doesn’t say “sorry about the complexity, we’ve done everything we can to make it easy”, it says “Git’s hard, deal with it”. Yes, DVCS complictated, but git itself just further complicates it, in a very successful way.
My Final Solution
1 2 3 4 5 |
if [ $oldrev -eq 0 ]; then REV=$(git rev-list "$newrev") else REV=$(git rev-list "$oldrev..$newrev") fi |
The command lists out those commits even before the branch is started, but since Trac could filter out those duplicates in the commit_updater
, it's barely fine.
The only penalty here is performance, but at least it works and I remain sane at the end of day.
Leave a comment