aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/version/snapshot.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/version/snapshot.cxx')
-rw-r--r--libbuild2/version/snapshot.cxx27
1 files changed, 22 insertions, 5 deletions
diff --git a/libbuild2/version/snapshot.cxx b/libbuild2/version/snapshot.cxx
index 9234460..000bcba 100644
--- a/libbuild2/version/snapshot.cxx
+++ b/libbuild2/version/snapshot.cxx
@@ -12,24 +12,41 @@ namespace build2
namespace version
{
snapshot
- extract_snapshot_git (const dir_path&);
+ extract_snapshot_git (context&, dir_path);
static const path git (".git");
snapshot
extract_snapshot (const scope& rs)
{
- // Ignore errors when checking for existence since we may be iterating
- // over directories past any reasonable project boundaries.
+ // Resolve the path symlink components to make sure that if we are
+ // extracting snapshot for a subproject which is symlinked from the git
+ // submodule, then we end up with a root of the git submodule repository
+ // rather than the containing repository root.
//
- for (dir_path d (rs.src_path ()); !d.empty (); d = d.directory ())
+ dir_path d (rs.src_path ());
+
+ try
+ {
+ d.realize ();
+ }
+ catch (const invalid_path&) // Some component doesn't exist.
+ {
+ return snapshot ();
+ }
+ catch (const system_error& e)
+ {
+ fail << "unable to obtain real path for " << d << ": " << e;
+ }
+
+ for (; !d.empty (); d = d.directory ())
{
// .git can be either a directory or a file in case of a submodule.
//
if (butl::entry_exists (d / git,
true /* follow_symlinks */,
true /* ignore_errors */))
- return extract_snapshot_git (d);
+ return extract_snapshot_git (rs.ctx, move (d));
}
return snapshot ();