diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java index 7905d312938f7f..699565966740d7 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java @@ -267,10 +267,14 @@ public RepositoryOverride convert(String input) throws OptionsParsingException { throw new OptionsParsingException( "Repository overrides must be of the form 'repository-name=path'", input); } - PathFragment path = PathFragment.create(pieces[1]); - if (!path.isAbsolute()) { + OptionsUtils.AbsolutePathFragmentConverter absolutePathFragmentConverter = + new OptionsUtils.AbsolutePathFragmentConverter(); + PathFragment path; + try { + path = absolutePathFragmentConverter.convert(pieces[1]); + } catch (OptionsParsingException e) { throw new OptionsParsingException( - "Repository override directory must be an absolute path", input); + "Repository override directory must be an absolute path", input, e); } try { return RepositoryOverride.create(RepositoryName.create(pieces[0]), path); diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java index 305622fc1d61b2..478a09937f72c4 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.repository; +import static com.google.common.base.StandardSystemProperty.USER_HOME; import static com.google.common.truth.Truth.assertThat; import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.RepositoryOverride; @@ -52,6 +53,13 @@ public void testOverridePathWithEqualsSign() throws Exception { assertThat(actual.path()).isEqualTo(PathFragment.create("/bar=/baz")); } + @Test + public void testOverridePathWithTilde() throws Exception { + RepositoryOverride actual = converter.convert("foo=~/bar"); + assertThat(actual.repositoryName()).isEqualTo(RepositoryName.createUnvalidated("foo")); + assertThat(actual.path()).isEqualTo(PathFragment.create(USER_HOME.value() + "/bar")); + } + @Test public void testInvalidOverride() throws Exception { expectedException.expect(OptionsParsingException.class);