help: the question about relative path in the objects/info/alternates
Hi git experts,
From the objects/info/alternates part of this URL http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html, it says it will work if alternates has relative path in it. But i found it will always fail under below situation, i don't know whether the failure is due to the git nature or it is a git potential bug.
The failure situation is like that:
On my machine, i have a git bare base repository, e.g. /home/jason/source/base-bare. On the same machine, i have a git bare incremental (it need to refer to base repository) repository, e.g. /home/jason/source/incremental-bare. In the incremental-bare/objects/info/alternates, i set a relative path to point to the objects of base-bare like this "../../base-bare/objects". Then i want to clone a new repository from the incremental-bare on the same machine, if i use this command "git clone /home/jason/source/incremental-bare new-project", it will fail; but if i use this command "git clone file:///home/jason/source/incremental-bare new-project", it will work successfully, Why the first one can't work, it is a bug for git?
In addtion, if i write an absolute path in the incremental-bare/objects/info/alternates like this "/home/jason/source/base-bare/objects", it will always work well no matter i add or don't add "file://".
Thanks
Jason Wang.
Quoted 3 lines · Jason Wang
From the objects/info/alternates part of this URL
http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html,
it says it will work if alternates has relative path in it.
It does not just say "relative path", but "relative to the object database". It expresses where the "objects" directory you are borrowing from is, relative to your own "objects" directory.
For example, if you have /src/ib/{objects,refs,HEAD} as your repository that borrows from elsewhere, say /src/base/, then objects/info/alternates file in the borrowing repository should say either /src/base/objects/, or "../../base/objects".
An easy way to make sure you do not make typo is to go to your borrowing objects directory, and then let your shell completion to type your path, like this:
$ cd /home/jason/source/incremental-bare
$ cd objects
$ echo ../../base-bare/objects >info/alternatesWhile formulating that "echo" command line, you would type ../../ <TAB> and pick base-bare, <TAB> and pick objects.
Quoted 12 lines · Junio C Hamano
Quoted 4 lines · Jason Wang
From the objects/info/alternates part of this URL
http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html,
it says it will work if alternates has relative path in it.It does not just say "relative path", but "relative to the object database". It expresses where the "objects" directory you are borrowing from is, relative to your own "objects" directory.
Understand.
Quoted 9 lines
For example, if you have /src/ib/{objects,refs,HEAD} as your repository that borrows from elsewhere, say /src/base/, then objects/info/alternates file in the borrowing repository should say either /src/base/objects/, or "../../base/objects".
An easy way to make sure you do not make typo is to go to your borrowing objects directory, and then let your shell completion to type your path, like this:
Quoted 8 lines
$ cd /home/jason/source/incremental-bare $ cd objects $ echo ../../base-bare/objects >info/alternatesWhile formulating that "echo" command line, you would type ../../ <TAB> and pick base-bare, <TAB> and pick objects.
At first, thanks very much.
Yes, your concern is right. But here i really put a right relative path in the alternates file. Since i can verify it. For example, %> cd /home/jason/source/incremental-bare; %> git tag; %>git branch, all commands work well, while if i put a wrong relative path in the alternates file, those commands will fail.
The weird thing is if i operate git commands in the /home/jason/source/incremental-bare, all commands work well, it can successfully borrow objects (refs) from base-bare via relative path. But if i clone a new project-dir from incremental-bare (use incremental-bare as local machine dir), it will fail, from the failure output it seems it can't borrow objects (refs) from base-bare. But if i add "file://" or "git://" before incremental-bare, it can work successfully. Do you think it is a bug? %> git clone /home/jason/source/incremental-bare project-dir // it will fail
%> git clone file:///home/jason/source/incremental-bare project-dir // it will work successfully
To be convenient, i give a reproduce step for this problem:
1. verify git version on my local machine
hwang4@wanghui-desktop:mainline$ git --version git version 1.7.6
2. basing on linux-2.6, generate a bare repository linux-2.6-bare
hwang4@wanghui-desktop:mainline$ git clone --bare linux-2.6 linux-2.6-bare Cloning into bare repository linux-2.6-bare... done. hwang4@wanghui-desktop:mainline$ du -hms linux-2.6-bare/ 950 linux-2.6-bare/
3. make some change in the linux-2.6, and generate a commit
hwang4@wanghui-desktop:mainline$ emacs linux-2.6/Makefile hwang4@wanghui-desktop:mainline$ cd linux-2.6 hwang4@wanghui-desktop:linux-2.6$ git commit -m "just test" ./Makefile [master f2c6e4f] just test 1 files changed, 1 insertions(+), 1 deletions(-)
4. let the linux-2.6-bare as a reference, generate a new INCREMENTAL repositry from linux-2.6
hwang4@wanghui-desktop:mainline$ git clone --bare --reference ./linux-2.6-bare/ file:///home/hwang4/work/mainline/linux-2.6 linux-2.6-inc Cloning into bare repository linux-2.6-inc... remote: Counting objects: 5, done. remote: Compressing objects: 100% (3/3), done. Receiving objects: 100% (3/3), 293 bytes, done. Resolving deltas: 100% (2/2), completed with 2 local objects. remote: Total 3 (delta 2), reused 0 (delta 0) hwang4@wanghui-desktop:mainline$ du -hms linux-2.6-inc/ 1 linux-2.6-inc/
{
here i must add "file://" before source repository, otherwise, the mini-tree is full repository instead of incremental, E.G.:
hwang4@wanghui-desktop:mainline$ git clone --bare --reference ./linux-2.6-bare/ linux-2.6 linux-2.6-inc Cloning into bare repository linux-2.6-inc... done. hwang4@wanghui-desktop:mainline$ du -hms linux-2.6-inc/ 950 linux-2.6-inc/ }
5. replace the absolute path in the linux-2.6-inc/objects/info/alternates to the relative path.
hwang4@wanghui-desktop:mainline$ cd linux-2.6-inc/objects/ hwang4@wanghui-desktop:objects$ cat info/alternates /home/hwang4/work/mainline/linux-2.6-bare/objects hwang4@wanghui-desktop:objects$ echo ../../linux-2.6-bare/objects/ > info/alternates hwang4@wanghui-desktop:objects$ cat info/alternates ../../linux-2.6-bare/objects/
6. verify relative path can work
hwang4@wanghui-desktop:objects$ git tag v2.6.11 v2.6.11-tree v2.6.12 v2.6.12-rc2 v2.6.12-rc3 <snip>
7. from the linux-2.6-inc, we clone a new project, if we don't add "file://", it will fail
hwang4@wanghui-desktop:mainline$ git clone /home/hwang4/work/mainline/linux-2.6-inc new-project Cloning into new-project... done. error: object directory /home/hwang4/work/mainline/new-project/.git/objects/../../linux-2.6-bare/objects/ does not exist; check .git/objects/info/alternates. error: refs/tags/v2.6.38-rc8 does not point to a valid object! error: refs/tags/v2.6.38-rc7 does not point to a valid object! <snip>
8. but if we add "file://" before source repository or change to absolute path in the linux-2.6-inc/objects/info/alternates, i will work successfully
hwang4@wanghui-desktop:mainline$ git clone file:///home/hwang4/work/mainline/linux-2.6-inc new-project Cloning into new-project... remote: Counting objects: 1970908, done. remote: Compressing objects: 100% (370377/370377), done. Receiving objects: 100% (1970908/1970908), 433.54 MiB | 12.60 MiB/s, done. remote: Total 1970908 (delta 1644814), reused 1908550 (delta 1582482) Resolving deltas: 100% (1644814/1644814), done. hwang4@wanghui-desktop:mainline$ ls new-project/ arch COPYING crypto drivers fs init Kbuild kernel MAINTAINERS mm README samples security tools virt block CREDITS Documentation firmware include ipc Kconfig lib Makefile net REPORTING-BUGS scripts sound usr