On Tue, 6 Aug 2013 20:09:19 -0700 David Hendricks dhendrix@google.com wrote:
git_url() {
# Only the first line of `git remote' is considered.
echo $(LC_ALL=C git remote show origin 2>/dev/null |
grep 'Fetch URL:' |
sed 's/.*URL:[[:blank:]]*//' |
grep ^.
)
# get all remote branches containing the last commit
branches=$(git branch -r --contains HEAD | cut -c 3-)
if [ -z "$branches" ] ; then
echo "No remote branch contains current HEAD">&2
return
fi
# find "nearest" branch
local diff=9000
local target=
for branch in $branches ; do
curdiff=$(git rev-list --count HEAD..$branch)
if [ $curdiff -ge $diff ] ; then
continue
fi
diff=$curdiff
target=$branch
done
echo "$(git ls-remote --exit-code --get-url ${target%/*})
${target#*/}" }
I am seeing a lot of errors when trying this. The version in the previous patch worked, though it kept the http:// prefix which is kind of superfluous.
Try cloning http://git.chromium.org/chromiumos/third_party/flashrom.git .
That's the only thing (out of vanilla svn, git-svn, cloned github git-svn, chromium tree) I did not test at all yet. Thanks for trying so fast!
$ sh getrevision.sh -U fatal: ambiguous argument 'HEAD..->': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' getrevision.sh: line 115: [: -ge: unary operator expected getrevision.sh: line 115: [: 0: unary operator expected http://git.chromium.org/chromiumos/third_party/flashrom.git master
What about something like: git ls-remote --exit-code --get-url | sed 's/.*////'
That looks simpler and works better, at least in my testing...
The problem is the output of git branch -r --contains HEAD: origin/HEAD -> origin/master origin/master
Namely the origin/HEAD pointing to another branch which specifies the branch one checks out automatically when cloning the repository. I do not have this in my working repository where I was testing because i did add the chromium tree as a plain remote only...
I have attached another approach, now with: branches=$(git branch -r --contains HEAD | sed 's/[\t ]*//;/.*->.*/d')
On Wed, Aug 7, 2013 at 2:57 PM, Stefan Tauner < stefan.tauner@student.tuwien.ac.at> wrote:
$ sh getrevision.sh -U fatal: ambiguous argument 'HEAD..->': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' getrevision.sh: line 115: [: -ge: unary operator expected getrevision.sh: line 115: [: 0: unary operator expected http://git.chromium.org/chromiumos/third_party/flashrom.git master
What about something like: git ls-remote --exit-code --get-url | sed 's/.*////'
That looks simpler and works better, at least in my testing...
The problem is the output of git branch -r --contains HEAD: origin/HEAD -> origin/master origin/master
Namely the origin/HEAD pointing to another branch which specifies the branch one checks out automatically when cloning the repository. I do not have this in my working repository where I was testing because i did add the chromium tree as a plain remote only...
I have attached another approach, now with: branches=$(git branch -r --contains HEAD | sed 's/[\t ]*//;/.*->.*/d')
That works nicely for my test cases. Anyone else?
Now to bikeshed the appearance of the the version string...