Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change git directory using work-tree / git-dir #747

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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