Skip to content

Commit

Permalink
Change git directory using work-tree / git-dir (fortran-lang#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk authored Sep 7, 2022
1 parent e2f00d8 commit a5d9c70
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/fpm/git.f90
Original file line number Diff line number Diff line change
@@ -1,7 +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
use fpm_filesystem, only : get_temp_filename, getline, join_path
implicit none

public :: git_target_t
Expand Down Expand Up @@ -141,13 +141,14 @@ subroutine checkout(self, local_path, error)
type(error_t), allocatable, intent(out) :: error

integer :: stat
character(len=:), allocatable :: object
character(len=:), allocatable :: object, workdir

if (allocated(self%object)) then
object = self%object
else
object = 'HEAD'
end if
workdir = "--work-tree="//local_path//" --git-dir="//join_path(local_path, ".git")

call execute_command_line("git init "//local_path, exitstat=stat)

Expand All @@ -156,15 +157,15 @@ subroutine checkout(self, local_path, error)
return
end if

call execute_command_line("git -C "//local_path//" fetch --depth=1 "// &
call execute_command_line("git "//workdir//" fetch --depth=1 "// &
self%url//" "//object, exitstat=stat)

if (stat /= 0) then
call fatal_error(error,'Error while fetching git repository for remote dependency')
return
end if

call execute_command_line("git -C "//local_path//" checkout -qf FETCH_HEAD", exitstat=stat)
call execute_command_line("git "//workdir//" checkout -qf FETCH_HEAD", exitstat=stat)

if (stat /= 0) then
call fatal_error(error,'Error while checking out git repository for remote dependency')
Expand All @@ -186,11 +187,12 @@ subroutine git_revision(local_path, object, error)
type(error_t), allocatable, intent(out) :: error

integer :: stat, unit, istart, iend
character(len=:), allocatable :: temp_file, line, iomsg
character(len=:), allocatable :: temp_file, line, iomsg, workdir
character(len=*), parameter :: hexdigits = '0123456789abcdef'

workdir = "--work-tree="//local_path//" --git-dir="//join_path(local_path, ".git")
allocate(temp_file, source=get_temp_filename())
line = "git -C "//local_path//" log -n 1 > "//temp_file
line = "git "//workdir//" log -n 1 > "//temp_file
call execute_command_line(line, exitstat=stat)

if (stat /= 0) then
Expand Down

0 comments on commit a5d9c70

Please sign in to comment.