801801function handle_repo_develop! (ctx:: Context , pkg:: PackageSpec , shared:: Bool )
802802 # First, check if we can compute the path easily (which requires a given local path or name)
803803 is_local_path = pkg. repo. source != = nothing && ! isurl (pkg. repo. source)
804+ # Preserve whether the original source was an absolute path - needed later to decide how to store the path
805+ original_source_was_absolute = is_local_path && isabspath (pkg. repo. source)
806+
804807 if is_local_path || pkg. name != = nothing
805- dev_path = is_local_path ? pkg. repo. source : devpath (ctx. env, pkg. name, shared)
808+ # Resolve manifest-relative paths to absolute paths for file system operations
809+ dev_path = if is_local_path
810+ isabspath (pkg. repo. source) ? pkg. repo. source :
811+ Pkg. manifest_rel_path (ctx. env, pkg. repo. source)
812+ else
813+ devpath (ctx. env, pkg. name, shared)
814+ end
806815 if pkg. repo. subdir != = nothing
807816 dev_path = joinpath (dev_path, pkg. repo. subdir)
808817 end
@@ -818,7 +827,7 @@ function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool)
818827 resolve_projectfile! (pkg, dev_path)
819828 error_if_in_sysimage (pkg)
820829 if is_local_path
821- pkg. path = isabspath (dev_path) ? dev_path : relative_project_path (ctx. env. manifest_file, dev_path)
830+ pkg. path = original_source_was_absolute ? dev_path : relative_project_path (ctx. env. manifest_file, dev_path)
822831 else
823832 pkg. path = shared ? dev_path : relative_project_path (ctx. env. manifest_file, dev_path)
824833 end
@@ -847,7 +856,11 @@ function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool)
847856 cloned = false
848857 package_path = pkg. repo. subdir === nothing ? repo_path : joinpath (repo_path, pkg. repo. subdir)
849858 if ! has_name (pkg)
850- LibGit2. close (GitTools. ensure_clone (ctx. io, repo_path, pkg. repo. source))
859+ # Resolve manifest-relative path to absolute before passing to git
860+ repo_source_resolved = ! isurl (pkg. repo. source) && ! isabspath (pkg. repo. source) ?
861+ Pkg. manifest_rel_path (ctx. env, pkg. repo. source) :
862+ pkg. repo. source
863+ LibGit2. close (GitTools. ensure_clone (ctx. io, repo_path, repo_source_resolved))
851864 cloned = true
852865 resolve_projectfile! (pkg, package_path)
853866 end
@@ -870,7 +883,11 @@ function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool)
870883 else
871884 mkpath (dirname (dev_path))
872885 if ! cloned
873- LibGit2. close (GitTools. ensure_clone (ctx. io, dev_path, pkg. repo. source))
886+ # Resolve manifest-relative path to absolute before passing to git
887+ repo_source_resolved = ! isurl (pkg. repo. source) && ! isabspath (pkg. repo. source) ?
888+ Pkg. manifest_rel_path (ctx. env, pkg. repo. source) :
889+ pkg. repo. source
890+ LibGit2. close (GitTools. ensure_clone (ctx. io, dev_path, repo_source_resolved))
874891 else
875892 mv (repo_path, dev_path)
876893 end
@@ -880,7 +897,13 @@ function handle_repo_develop!(ctx::Context, pkg::PackageSpec, shared::Bool)
880897 resolve_projectfile! (pkg, joinpath (dev_path, pkg. repo. subdir === nothing ? " " : pkg. repo. subdir))
881898 end
882899 error_if_in_sysimage (pkg)
883- pkg. path = shared ? dev_path : relative_project_path (ctx. env. manifest_file, dev_path)
900+ # When an explicit local path was given, preserve whether it was absolute or relative
901+ # Otherwise, use shared flag to determine if path should be absolute (shared) or relative (local)
902+ if is_local_path
903+ pkg. path = original_source_was_absolute ? dev_path : relative_project_path (ctx. env. manifest_file, dev_path)
904+ else
905+ pkg. path = shared ? dev_path : relative_project_path (ctx. env. manifest_file, dev_path)
906+ end
884907 if pkg. repo. subdir != = nothing
885908 pkg. path = joinpath (pkg. path, pkg. repo. subdir)
886909 end
@@ -948,10 +971,12 @@ function handle_repo_add!(ctx::Context, pkg::PackageSpec)
948971 @assert pkg. repo. source != = nothing
949972
950973 # We now have the source of the package repo, check if it is a local path and if that exists
951- repo_source = pkg. repo. source
974+ repo_source = ! isurl (pkg. repo. source) && ! isabspath (pkg. repo. source) ?
975+ normpath (joinpath (dirname (ctx. env. manifest_file), pkg. repo. source)) :
976+ pkg. repo. source
952977 if ! isurl (pkg. repo. source)
953- if isdir (pkg . repo . source )
954- git_path = joinpath (pkg . repo . source , " .git" )
978+ if isdir (repo_source )
979+ git_path = joinpath (repo_source , " .git" )
955980 if isfile (git_path)
956981 # Git submodule: .git is a file containing path to actual git directory
957982 git_ref_content = readline (git_path)
@@ -961,22 +986,25 @@ function handle_repo_add!(ctx::Context, pkg::PackageSpec)
961986 git_info_path = git_path
962987 end
963988 if ! isdir (git_info_path)
964- msg = " Did not find a git repository at `$(pkg . repo . source ) `"
965- if isfile (joinpath (pkg . repo . source , " Project.toml" )) || isfile (joinpath (pkg . repo . source , " JuliaProject.toml" ))
989+ msg = " Did not find a git repository at `$(repo_source ) `"
990+ if isfile (joinpath (repo_source , " Project.toml" )) || isfile (joinpath (repo_source , " JuliaProject.toml" ))
966991 msg *= " , perhaps you meant `Pkg.develop`?"
967992 end
968993 pkgerror (msg)
969994 end
970- LibGit2. with (GitTools. check_valid_HEAD, LibGit2. GitRepo (pkg . repo . source )) # check for valid git HEAD
971- LibGit2. with (LibGit2. GitRepo (pkg . repo . source )) do repo
995+ LibGit2. with (GitTools. check_valid_HEAD, LibGit2. GitRepo (repo_source )) # check for valid git HEAD
996+ LibGit2. with (LibGit2. GitRepo (repo_source )) do repo
972997 if LibGit2. isdirty (repo)
973- @warn " The repository at `$(pkg . repo . source ) ` has uncommitted changes. Consider using `Pkg.develop` instead of `Pkg.add` if you want to work with the current state of the repository."
998+ @warn " The repository at `$(repo_source ) ` has uncommitted changes. Consider using `Pkg.develop` instead of `Pkg.add` if you want to work with the current state of the repository."
974999 end
9751000 end
976- pkg. repo. source = isabspath (pkg. repo. source) ? safe_realpath (pkg. repo. source) : relative_project_path (ctx. env. manifest_file, pkg. repo. source)
977- repo_source = normpath (joinpath (dirname (ctx. env. manifest_file), pkg. repo. source))
1001+ # Store the path: use the original path format (absolute vs relative) as the user provided
1002+ # Canonicalize repo_source for consistent hashing in cache paths
1003+ repo_source = safe_realpath (repo_source)
1004+ pkg. repo. source = isabspath (pkg. repo. source) ? repo_source : relative_project_path (ctx. env. manifest_file, repo_source)
9781005 else
979- pkgerror (" Path `$(pkg. repo. source) ` does not exist." )
1006+ # For error messages, show the absolute path which is more informative than manifest-relative
1007+ pkgerror (" Path `$(repo_source) ` does not exist." )
9801008 end
9811009 end
9821010
0 commit comments