Skip to content

Commit

Permalink
Merge pull request #1550 from OCamlPro/user-from-git
Browse files Browse the repository at this point in the history
opam template: get user name/email from git
  • Loading branch information
AltGr committed Jul 31, 2014
2 parents 45fb722 + 53e7b20 commit 7debcfa
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/core/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,20 +1242,35 @@ module X = struct
let template nv =
let t = create nv in
let maintainer =
let email =
try Some (Sys.getenv "EMAIL") with Not_found -> None in
try
let open Unix in
let pw = getpwuid (getuid ()) in
let email = match email with
| Some e -> e
| None -> pw.pw_name^"@"^gethostname () in
match OpamMisc.split pw.pw_gecos ',' with
| name::_ -> [Printf.sprintf "%s <%s>" name email]
| _ -> [email]
with Not_found -> match email with
| Some e -> [e]
| None -> []
let from_git = try
match
OpamSystem.read_command_output
["git"; "config"; "--get"; "user.name"],
OpamSystem.read_command_output
["git"; "config"; "--get"; "user.email"]
with
| [name], [email] ->
Some [Printf.sprintf "%s <%s>" name email]
| _ -> raise Not_found
with e -> OpamMisc.fatal e; None
in
match from_git with
| Some u -> u
| None ->
let email =
try Some (Sys.getenv "EMAIL") with Not_found -> None in
try
let open Unix in
let pw = getpwuid (getuid ()) in
let email = match email with
| Some e -> e
| None -> pw.pw_name^"@"^gethostname () in
match OpamMisc.split pw.pw_gecos ',' with
| name::_ -> [Printf.sprintf "%s <%s>" name email]
| _ -> [email]
with Not_found -> match email with
| Some e -> [e]
| None -> []
in
{ t with
maintainer;
Expand Down

0 comments on commit 7debcfa

Please sign in to comment.