1
1
! > Implementation for interacting with git repositories.
2
2
module fpm_git
3
3
use fpm_error, only: error_t, fatal_error
4
- use fpm_filesystem, only : get_temp_filename, getline
4
+ use fpm_filesystem, only : get_temp_filename, getline, join_path
5
5
implicit none
6
6
7
7
public :: git_target_t
@@ -141,13 +141,14 @@ subroutine checkout(self, local_path, error)
141
141
type (error_t), allocatable , intent (out ) :: error
142
142
143
143
integer :: stat
144
- character (len= :), allocatable :: object
144
+ character (len= :), allocatable :: object, workdir
145
145
146
146
if (allocated (self% object)) then
147
147
object = self% object
148
148
else
149
149
object = ' HEAD'
150
150
end if
151
+ workdir = " --work-tree=" // local_path// " --git-dir=" // join_path(local_path, " .git" )
151
152
152
153
call execute_command_line(" git init " // local_path, exitstat= stat)
153
154
@@ -156,15 +157,15 @@ subroutine checkout(self, local_path, error)
156
157
return
157
158
end if
158
159
159
- call execute_command_line(" git -C " // local_path // " fetch --depth=1 " // &
160
+ call execute_command_line(" git " // workdir // " fetch --depth=1 " // &
160
161
self% url// " " // object, exitstat= stat)
161
162
162
163
if (stat /= 0 ) then
163
164
call fatal_error(error,' Error while fetching git repository for remote dependency' )
164
165
return
165
166
end if
166
167
167
- call execute_command_line(" git -C " // local_path // " checkout -qf FETCH_HEAD" , exitstat= stat)
168
+ call execute_command_line(" git " // workdir // " checkout -qf FETCH_HEAD" , exitstat= stat)
168
169
169
170
if (stat /= 0 ) then
170
171
call fatal_error(error,' Error while checking out git repository for remote dependency' )
@@ -186,11 +187,12 @@ subroutine git_revision(local_path, object, error)
186
187
type (error_t), allocatable , intent (out ) :: error
187
188
188
189
integer :: stat, unit, istart, iend
189
- character (len= :), allocatable :: temp_file, line, iomsg
190
+ character (len= :), allocatable :: temp_file, line, iomsg, workdir
190
191
character (len=* ), parameter :: hexdigits = ' 0123456789abcdef'
191
192
193
+ workdir = " --work-tree=" // local_path// " --git-dir=" // join_path(local_path, " .git" )
192
194
allocate (temp_file, source= get_temp_filename())
193
- line = " git -C " // local_path // " log -n 1 > " // temp_file
195
+ line = " git " // workdir // " log -n 1 > " // temp_file
194
196
call execute_command_line(line, exitstat= stat)
195
197
196
198
if (stat /= 0 ) then
0 commit comments