git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/1] git-clone: fix relative path problem in the alternates

From
HWHui Wang <jason77.wang@gmail.com>
Date
Aug 19, 2011, 05:23 UTC
Message-ID
<1313731396-10458-1-git-send-email-jason77.wang@gmail.com>
Hi Junio & everyone,

Several days ago, i reported a "git clone" issue, the url is at: http://marc.info/?l=git&m=131219022632724&w=2

Here i describe the problem again and try to provide a fix for this problem, please help to review it. Thanks.

The problem: Suppose we have two git repositories on the local machine, one is called base repository, another is called source repository, source repository need refer to some objects of the base repository via .git/objects/info/alternates. If we set a relative path (source repository to base repository) in the alternates, we can execute any git commands (branch, tag, pull, checkout...) successfully in the source repository. But if we want to clone a destiantion repository from source repository without "--shared" on the same machine, just like this: %>git clone $local_path/src_repos $local_path/des_repos This clone command will fail because git can't get objects of the base repository.

The reason: When we execute git clone $local_path/src_repos $local_path/des_repos, git will copy alternates of the src_repos to the des_repos first, then des_repos will use this alternates to refer to base repository, this is the problem, the relative in the alternates is src_repos to base_repos rather than des_repos to base_repos.

The fix: After the alternates is copied from src_repos to des_repos and before this file is used by the des_repos, we can parse it and replace all relative paths to a corrected path (absolute path of base_repos or new relative path of des_repos to base_repos). In my patch, i choose to replace relative paths to absoulte paths of base_repos.

If we add "--shared", this problem doesn't exist becase git doesn't need to copy alternates, if we add prefix before src_repos like "file://", "git://"..., this problem also doesn't exist. So i add a function to replace relative paths in the clone_local(), this only affect git clone $local_path/src_repos $local_path/des_repos without "--shared" and it has replative paths in the alternates of src_repos, for other situation, this function will not introduce any changes. Below is a execution result example of my fix:

the content of the alternates in the source repos (4 lines): $<relative_path1_source_repos_to_base1> $<relative_path2_source_repos_to_base2> # comment line $<absolute_path_of_base3>

After clone from source repos, the content of the alternates in the des_repos (4 lines): $<absolute_path_of_base1> $<absolute_path_of_base2> # comment line $<absolute_path_of_base3>

Next: Hui Wang
Message 1 of 4 in “git-clone: fix relative path problem in the alternates”
  1. 0/1 git-clone: fix relative path problem in the alternatesHui Wang, Aug 19, 2011
  2. 1/1 clone: replace relative paths in the alternatesHui Wang, Aug 19, 2011
  3. Junio C HamanoAug 19, 2011
  4. Hui WangAug 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.