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

#155 Resolves repository location based on pdb path #186

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Geert van Horrik <[email protected]>
Wesley Eledui <[email protected]>
Marek Fišera <[email protected]>
Shai Nahum <[email protected]>
Amadeusz Wieczorek <[email protected]>
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ When working with a repository using uncommon URL you can use placeholders to sp

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

### More options
### Git repository location

There are many more parameters you can use. Display the usage doc with the following command line:

GitLink.exe -h
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.

### Native PDBs

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

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

### More options

There are many more parameters you can use. Display the usage doc with the following command line:

GitLink.exe -h

# How does it work

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.
Expand Down
36 changes: 12 additions & 24 deletions src/GitLink/Linker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public static class Linker
}
}

if (repositoryDirectory == null)
{
repositoryDirectory = GitDirFinder.TreeWalkForGitDir(Path.GetDirectoryName(pdbPath));
if (repositoryDirectory == null)
{
Log.Error("Couldn't auto detect git repo. Please use -baseDir to manually set it.");
return false;
}
}

if (PortablePdbHelper.IsPortablePdb(pdbPath))
{
Log.Warning("Portable PDB format is not compatible with GitLink. Please use SourceLink (https://github.com/ctaggart/SourceLink).");
Expand All @@ -57,38 +67,16 @@ public static class Linker

if (options.IndexAllDepotFiles)
{
if (repositoryDirectory == null)
{
repositoryDirectory = GitDirFinder.TreeWalkForGitDir(Path.GetDirectoryName(pdbPath));
if (repositoryDirectory == null)
{
Log.Error("Couldn't auto detect git repo. Please use -baseDir to manually set it.");
return false;
}
}

sourceFiles = GetSourceFilesFromDepot(repositoryDirectory);
}
else
{
sourceFiles = GetSourceFilesFromPdb(pdbPath, !options.SkipVerify);

string someSourceFile = sourceFiles.FirstOrDefault();
if (someSourceFile == null)
if (!sourceFiles.Any())
{
Log.Error("No source files were found in the PDB. If you're PDB is a native one you should use -a option.");
return false;
}

if (repositoryDirectory == null)
{
repositoryDirectory = GitDirFinder.TreeWalkForGitDir(Path.GetDirectoryName(sourceFiles.FirstOrDefault()));
if (repositoryDirectory == null)
{
Log.Error("No source files found that are tracked in a git repo.");
return false;
}
}
}

string workingDirectory = Path.GetDirectoryName(repositoryDirectory);
Expand Down Expand Up @@ -186,7 +174,7 @@ public static class Linker
}
catch (RepositoryNotFoundException)
{
Log.Error($"Unable to find git repo at \"{options.GitWorkingDirectory}\".");
Log.Error($"Unable to find git repo at \"{repositoryDirectory}\".");
return false;
}
finally
Expand Down