From f1c95d45bd86180ef64da018b657461c44d0236a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 9 Feb 2019 00:28:24 +0300 Subject: Fix git repository fetch that was deep regardless of the sensing result --- bpkg/fetch-git.cxx | 29 +++++++++++++++++------------ tests/rep-fetch-git-refname.testscript | 9 +++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/bpkg/fetch-git.cxx b/bpkg/fetch-git.cxx index a1c420a..69eb5a0 100644 --- a/bpkg/fetch-git.cxx +++ b/bpkg/fetch-git.cxx @@ -1397,6 +1397,8 @@ namespace bpkg fail << "unable to test if " << dir << " is shallow" << endg; }; + bool fetch_deep (fetch_repo || !dcs.empty ()); + // Print progress. // if (verb && !co.no_progress ()) @@ -1428,7 +1430,7 @@ namespace bpkg // Print warnings prior to the deep fetching. // - if (fetch_repo || !dcs.empty ()) + if (fetch_deep) { { diag_record dr (warn); @@ -1454,23 +1456,26 @@ namespace bpkg // // First, we perform the deep fetching. // - fetch (fetch_repo ? strings () : dcs, false); - - // After the deep fetching some of the shallow commits might also be - // fetched, so we drop them from the fetch list. - // - for (auto i (scs.begin ()); i != scs.end (); ) + if (fetch_deep) { - if (commit_fetched (co, dir, *i)) - i = scs.erase (i); - else - ++i; + fetch (fetch_repo ? strings () : dcs, false /* shallow */); + + // After the deep fetching some of the shallow commits might also be + // fetched, so we drop them from the fetch list. + // + for (auto i (scs.begin ()); i != scs.end (); ) + { + if (commit_fetched (co, dir, *i)) + i = scs.erase (i); + else + ++i; + } } // Finally, we perform the shallow fetching. // if (!scs.empty ()) - fetch (scs, true); + fetch (scs, true /* shallow */); // We also need to make sure that all the resulting commits are now // fetched. This may not be the case if the user misspelled the diff --git a/tests/rep-fetch-git-refname.testscript b/tests/rep-fetch-git-refname.testscript index e273569..71305ea 100644 --- a/tests/rep-fetch-git-refname.testscript +++ b/tests/rep-fetch-git-refname.testscript @@ -92,6 +92,15 @@ checked out libfoo/1.0.0 EOE + # While at it, check that the fetch was shallow (and the repository + # contains a single commit), unless the protocol is dumb. + # + if ($git_protocol != 'https-dumb') + $g "$r" log '--pretty=format:%d %s' >>:~%EOO% + % \(.+\) .+% + EOO + end; + $g "$r" config remote.origin.url "$u/libfoo.git"; # Preconditions. -- cgit v1.1