@@ -68,6 +68,16 @@ public static String setDefaultBranch(Project project) {
6868 return defaultBranch ;
6969 }
7070
71+ // get remoteUrlReplacements configuration option
72+ public static String setRemoteUrlReplacements (Project project ) {
73+ String replacements = Config .getInstance (project ).getRemoteUrlReplacements ();
74+ if (replacements == null || replacements .length () == 0 ) {
75+ Properties props = readProps ();
76+ replacements = props .getProperty ("remoteUrlReplacements" , null );
77+ }
78+ return replacements ;
79+ }
80+
7181 // readProps tries to read the $HOME/sourcegraph-jetbrains.properties file.
7282 private static Properties readProps () {
7383 Properties props = new Properties ();
@@ -94,7 +104,7 @@ private static Properties readProps() {
94104 // repoInfo returns the Sourcegraph repository URI, and the file path
95105 // relative to the repository root. If the repository URI cannot be
96106 // determined, a RepoInfo with empty strings is returned.
97- public static RepoInfo repoInfo (String fileName ) {
107+ public static RepoInfo repoInfo (String fileName , Project project ) {
98108 String fileRel = "" ;
99109 String remoteURL = "" ;
100110 String branch = "" ;
@@ -106,12 +116,24 @@ public static RepoInfo repoInfo(String fileName) {
106116 // Determine file path, relative to repository root.
107117 fileRel = fileName .substring (repoRoot .length ()+1 );
108118 remoteURL = configuredGitRemoteURL (repoRoot );
109- branch = gitBranch (repoRoot );
119+ branch = Util . setDefaultBranch ( project )!= null ? Util . setDefaultBranch ( project ) : gitBranch (repoRoot );
110120
111- // If on a branch that does not exist on the remote, use "master" instead.
121+ // If on a branch that does not exist on the remote or if defaultBranch does not exist on the remote,
122+ // use "master" instead.
112123 if (!isRemoteBranch (branch , repoRoot )) {
113124 branch = "master" ;
114125 }
126+
127+ // replace remoteURL if config option is not null
128+ String r = Util .setRemoteUrlReplacements (project );
129+
130+ if (r !=null ) {
131+ String [] replacements = r .trim ().split ("\\ s*,\\ s*" );
132+ // Check if the entered values are pairs
133+ for (int i = 0 ; i < replacements .length && replacements .length % 2 == 0 ; i += 2 ) {
134+ remoteURL = remoteURL .replace (replacements [i ], replacements [i +1 ]);
135+ }
136+ }
115137 } catch (Exception err ) {
116138 Logger .getInstance (Util .class ).info (err );
117139 err .printStackTrace ();
@@ -129,7 +151,7 @@ public static String exec(String cmd, String dir) throws IOException {
129151 BufferedReader stdout = new BufferedReader (new InputStreamReader (p .getInputStream ()));
130152 BufferedReader stderr = new BufferedReader (new InputStreamReader (p .getErrorStream ()));
131153
132- // Log any stderr ouput .
154+ // Log any stderr output .
133155 Logger logger = Logger .getInstance (Util .class );
134156 String s ;
135157 while ((s = stderr .readLine ()) != null ) {
0 commit comments