Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit d848908

Browse files
Merge pull request #186 from AmadeusW/fixBaseDirResolution
#155 Resolves repository location based on pdb path
2 parents 9d72fec + e4c185a commit d848908

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Geert van Horrik <[email protected]>
1515
Wesley Eledui <[email protected]>
1616
Marek Fišera <[email protected]>
1717
Shai Nahum <[email protected]>
18+
Amadeusz Wieczorek <[email protected]>

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ When working with a repository using uncommon URL you can use placeholders to sp
7272

7373
The custom url will be used to fill the placeholders with the relative file path and the revision hash.
7474

75-
### More options
75+
### Git repository location
7676

77-
There are many more parameters you can use. Display the usage doc with the following command line:
78-
79-
GitLink.exe -h
77+
GitLink resolves the git repository based on the location of the pdb file. If the pdb file is located outside of the git repository, use the `-baseDir` parameter to point to the top-level directory of the repository.
8078

8179
### Native PDBs
8280

@@ -86,6 +84,12 @@ Native PDBs (from C++ projects) are supported by using -a option:
8684

8785
All known C++ source files from your git depot will be indexed in the PDB.
8886

87+
### More options
88+
89+
There are many more parameters you can use. Display the usage doc with the following command line:
90+
91+
GitLink.exe -h
92+
8993
# How does it work
9094

9195
The SrcSrv tool (Srcsrv.dll) enables a client to retrieve the exact version of the source files that were used to build an application. Because the source code for a module can change between versions and over the course of years, it is important to look at the source code as it existed when the version of the module in question was built.

src/GitLink/Linker.cs

+12-24
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public static class Linker
4949
}
5050
}
5151

52+
if (repositoryDirectory == null)
53+
{
54+
repositoryDirectory = GitDirFinder.TreeWalkForGitDir(Path.GetDirectoryName(pdbPath));
55+
if (repositoryDirectory == null)
56+
{
57+
Log.Error("Couldn't auto detect git repo. Please use -baseDir to manually set it.");
58+
return false;
59+
}
60+
}
61+
5262
if (PortablePdbHelper.IsPortablePdb(pdbPath))
5363
{
5464
Log.Warning("Portable PDB format is not compatible with GitLink. Please use SourceLink (https://github.com/ctaggart/SourceLink).");
@@ -57,38 +67,16 @@ public static class Linker
5767

5868
if (options.IndexAllDepotFiles)
5969
{
60-
if (repositoryDirectory == null)
61-
{
62-
repositoryDirectory = GitDirFinder.TreeWalkForGitDir(Path.GetDirectoryName(pdbPath));
63-
if (repositoryDirectory == null)
64-
{
65-
Log.Error("Couldn't auto detect git repo. Please use -baseDir to manually set it.");
66-
return false;
67-
}
68-
}
69-
7070
sourceFiles = GetSourceFilesFromDepot(repositoryDirectory);
7171
}
7272
else
7373
{
7474
sourceFiles = GetSourceFilesFromPdb(pdbPath, !options.SkipVerify);
75-
76-
string someSourceFile = sourceFiles.FirstOrDefault();
77-
if (someSourceFile == null)
75+
if (!sourceFiles.Any())
7876
{
7977
Log.Error("No source files were found in the PDB. If you're PDB is a native one you should use -a option.");
8078
return false;
8179
}
82-
83-
if (repositoryDirectory == null)
84-
{
85-
repositoryDirectory = GitDirFinder.TreeWalkForGitDir(Path.GetDirectoryName(sourceFiles.FirstOrDefault()));
86-
if (repositoryDirectory == null)
87-
{
88-
Log.Error("No source files found that are tracked in a git repo.");
89-
return false;
90-
}
91-
}
9280
}
9381

9482
string workingDirectory = Path.GetDirectoryName(repositoryDirectory);
@@ -186,7 +174,7 @@ public static class Linker
186174
}
187175
catch (RepositoryNotFoundException)
188176
{
189-
Log.Error($"Unable to find git repo at \"{options.GitWorkingDirectory}\".");
177+
Log.Error($"Unable to find git repo at \"{repositoryDirectory}\".");
190178
return false;
191179
}
192180
finally

0 commit comments

Comments
 (0)