From baa00093557d4e7e41d67ac8acfd4daccb154afd Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 22 Jan 2018 10:57:29 -0600 Subject: [PATCH 1/2] Support relative paths in --reference Put the correctly-expanded relative paths in objects/info/alternates. From gitrepository-layout(5), this path should be "relative to the object database, not to the repository". Change-Id: I7b2027ae23cf7d367b80f5a187603c4cbacdb2de --- project.py | 7 ++++++- subcmds/init.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/project.py b/project.py index 2248a7ef..3ba8a073 100644 --- a/project.py +++ b/project.py @@ -1267,7 +1267,8 @@ class Project(object): try: fd = open(alt) try: - alt_dir = fd.readline().rstrip() + # This works for both absolute and relative alternate directories. + alt_dir = os.path.join(self.objdir, 'objects', fd.readline().rstrip()) finally: fd.close() except IOError: @@ -2353,6 +2354,10 @@ class Project(object): ref_dir = None if ref_dir: + if not os.path.isabs(ref_dir): + # The alternate directory is relative to the object database. + ref_dir = os.path.relpath(ref_dir, + os.path.join(self.objdir, 'objects')) _lwrite(os.path.join(self.gitdir, 'objects/info/alternates'), os.path.join(ref_dir, 'objects') + '\n') diff --git a/subcmds/init.py b/subcmds/init.py index eeddca06..9466b9a2 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -401,7 +401,7 @@ to update the working directory files. git_require(MIN_GIT_VERSION, fail=True) if opt.reference: - opt.reference = os.path.abspath(os.path.expanduser(opt.reference)) + opt.reference = os.path.expanduser(opt.reference) # Check this here, else manifest will be tagged "not new" and init won't be # possible anymore without removing the .repo/manifests directory. From 5f0e57d2ca28dad4e0f32849609c1857abb596fc Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 22 Jan 2018 11:00:24 -0600 Subject: [PATCH 2/2] init: Remove string concat in no-op os.path.join This also fixes a line length warning. Change-Id: I9c1ab65f83a35581dd657a707c7bc3c69db2b1dc --- subcmds/init.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subcmds/init.py b/subcmds/init.py index 9466b9a2..47a1c9fa 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -175,7 +175,8 @@ to update the working directory files. if not mirrored_manifest_git.endswith(".git"): mirrored_manifest_git += ".git" if not os.path.exists(mirrored_manifest_git): - mirrored_manifest_git = os.path.join(opt.reference + '/.repo/manifests.git') + mirrored_manifest_git = os.path.join(opt.reference, + '.repo/manifests.git') m._InitGitDir(mirror_git=mirrored_manifest_git)