From 1146fee52a2e40391d4ea6796fbcee5db7b71b32 Mon Sep 17 00:00:00 2001
From: Andre Smit <freevryheid@gmail.com>
Date: Tue, 20 Dec 2022 18:09:37 +0000
Subject: [PATCH 1/2] add git dependencies with submodules

---
 src/fpm/git.f90 | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/fpm/git.f90 b/src/fpm/git.f90
index 46dcca3afa..53884cd01e 100644
--- a/src/fpm/git.f90
+++ b/src/fpm/git.f90
@@ -1,7 +1,8 @@
 !> Implementation for interacting with git repositories.
 module fpm_git
     use fpm_error, only: error_t, fatal_error
-    use fpm_filesystem, only : get_temp_filename, getline, join_path
+    use fpm_filesystem, only : get_temp_filename, getline, join_path, exists
+    use fpm_os, only : get_current_directory, change_directory
     implicit none
 
     public :: git_target_t
@@ -141,7 +142,7 @@ subroutine checkout(self, local_path, error)
         type(error_t), allocatable, intent(out) :: error
 
         integer :: stat
-        character(len=:), allocatable :: object, workdir
+        character(len=:), allocatable :: object, workdir, cwd
 
         if (allocated(self%object)) then
             object = self%object
@@ -172,6 +173,21 @@ subroutine checkout(self, local_path, error)
             return
         end if
 
+        ! cd into the git_dir, update existing submodules and cd back
+        call get_current_directory(cwd, error)
+        if (allocated(error)) return
+        call change_directory(local_path, error)
+        if (allocated(error)) return
+        if (exists(".gitmodules")) then
+            call execute_command_line("git submodule update --init --recursive", exitstat=stat)
+            if (stat /= 0) then
+                call fatal_error(error,'Error while updating git submodules for remote dependency')
+                return
+            end if
+        end if
+        call change_directory(cwd, error)
+        if (allocated(error)) return
+
     end subroutine checkout
 
 

From cc454b455893dacc0ea898e6858ad957a0c30ac4 Mon Sep 17 00:00:00 2001
From: Andre Smit <freevryheid@gmail.com>
Date: Fri, 10 Feb 2023 08:52:32 -0600
Subject: [PATCH 2/2] simplify fetching submodules

---
 src/fpm/git.f90 | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/src/fpm/git.f90 b/src/fpm/git.f90
index 53884cd01e..0134558261 100644
--- a/src/fpm/git.f90
+++ b/src/fpm/git.f90
@@ -1,8 +1,7 @@
 !> Implementation for interacting with git repositories.
 module fpm_git
     use fpm_error, only: error_t, fatal_error
-    use fpm_filesystem, only : get_temp_filename, getline, join_path, exists
-    use fpm_os, only : get_current_directory, change_directory
+    use fpm_filesystem, only : get_temp_filename, getline, join_path
     implicit none
 
     public :: git_target_t
@@ -142,7 +141,7 @@ subroutine checkout(self, local_path, error)
         type(error_t), allocatable, intent(out) :: error
 
         integer :: stat
-        character(len=:), allocatable :: object, workdir, cwd
+        character(len=:), allocatable :: object, workdir
 
         if (allocated(self%object)) then
             object = self%object
@@ -158,7 +157,7 @@ subroutine checkout(self, local_path, error)
             return
         end if
 
-        call execute_command_line("git "//workdir//" fetch --depth=1 "// &
+        call execute_command_line("git "//workdir//" fetch --depth=1 --recursive "// &
                                   self%url//" "//object, exitstat=stat)
 
         if (stat /= 0) then
@@ -173,21 +172,6 @@ subroutine checkout(self, local_path, error)
             return
         end if
 
-        ! cd into the git_dir, update existing submodules and cd back
-        call get_current_directory(cwd, error)
-        if (allocated(error)) return
-        call change_directory(local_path, error)
-        if (allocated(error)) return
-        if (exists(".gitmodules")) then
-            call execute_command_line("git submodule update --init --recursive", exitstat=stat)
-            if (stat /= 0) then
-                call fatal_error(error,'Error while updating git submodules for remote dependency')
-                return
-            end if
-        end if
-        call change_directory(cwd, error)
-        if (allocated(error)) return
-
     end subroutine checkout