Skip to content

Commit 45d3fd8

Browse files
committed
get user name and email using git config if available else use defaults
1 parent 2ae0581 commit 45d3fd8

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

src/fpm/cmd/new.f90

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,48 @@ subroutine cmd_new(settings)
575575
call run('git init ' // settings%name)
576576
contains
577577

578+
function default_user(what) result(user)
579+
implicit none
580+
character(len=5), intent(in) :: what
581+
character(len=:), allocatable :: user
582+
if (what=="uname") then
583+
user = "Jane Doe"
584+
else
585+
586+
end if
587+
return
588+
end function default_user
589+
590+
function git_user(what) result(user)
591+
use fpm_filesystem, only : get_temp_filename, getline
592+
implicit none
593+
character(len=5), intent(in) :: what
594+
character(len=:), allocatable :: user
595+
character(len=:), allocatable :: temp_user, iomsg
596+
integer :: stat, unit
597+
allocate(temp_user, source=get_temp_filename())
598+
if (what=="uname") then
599+
user = "git config --get user.name > " // temp_user
600+
else
601+
user = "git config --get user.email > " // temp_user
602+
end if
603+
call execute_command_line(user, exitstat=stat)
604+
if (stat /= 0) then
605+
user = default_user(what)
606+
return
607+
end if
608+
open(file=temp_user, newunit=unit)
609+
call getline(unit, user, stat, iomsg)
610+
if (stat /= 0) then
611+
user = default_user(what)
612+
end if
613+
close(unit, status="delete")
614+
if (len(user)==0) then
615+
user = default_user(what)
616+
end if
617+
return
618+
end function git_user
619+
578620
subroutine create_verified_basic_manifest(filename)
579621
!> create a basic but verified default manifest file
580622
use fpm_toml, only : toml_table, toml_serializer, set_value
@@ -603,9 +645,9 @@ subroutine create_verified_basic_manifest(filename)
603645
call set_value(table, "name", BNAME)
604646
call set_value(table, "version", "0.1.0")
605647
call set_value(table, "license", "license")
606-
call set_value(table, "author", "Jane Doe")
607-
call set_value(table, "maintainer", "[email protected]")
608-
call set_value(table, "copyright", 'Copyright '//date(1:4)//', Jane Doe')
648+
call set_value(table, "author", git_user("uname"))
649+
call set_value(table, "maintainer", git_user("email"))
650+
call set_value(table, "copyright", 'Copyright '//date(1:4)//', '//git_user("uname"))
609651
! continue building of manifest
610652
! ...
611653
call new_package(package, table, error=error)

0 commit comments

Comments
 (0)