2222
2323var exec = require ( 'child_process' ) . execSync ;
2424var logger = require ( 'debug' ) ;
25+ var trim = require ( '@stdlib/string/trim' ) ;
2526
2627
2728// VARIABLES //
2829
2930var debug = logger ( 'remark-img-equations-src-urls:git' ) ;
3031
3132// Regular expression to extract a repository slug:
32- var RE = / (?: .+ g i t h u b \. c o m ) (?: \/ | : ) ( .+ ) (?: \. (?: .+ ) | \s * $ ) / ;
33+ var RE = / (?: .+ g i t h u b \. c o m ) (?: \/ | : ) ( .+ ) (?: \. (?: .+ ) | $ ) / ;
3334
3435
3536// MAIN //
@@ -52,7 +53,8 @@ function git() {
5253
5354 // Get the local git repository path and remove any newline characters:
5455 dir = exec ( 'git rev-parse --show-toplevel' ) ;
55- dir = dir . toString ( ) . match ( / ( .+ ) / ) [ 1 ] ;
56+ dir = trim ( dir . toString ( ) ) ;
57+ dir = dir . match ( / ( .+ ) / ) [ 1 ] ;
5658 debug ( 'Local repository directory: %s' , dir ) ;
5759
5860 opts = {
@@ -62,7 +64,7 @@ function git() {
6264 // Get the remote origin:
6365 cmd = 'git config --get remote.origin.url' ;
6466 out = exec ( cmd , opts ) ;
65- origin = out . toString ( ) ;
67+ origin = trim ( out . toString ( ) ) ;
6668 debug ( 'Remote origin: %s' , origin ) ;
6769
6870 // Extract the repository slug:
@@ -72,7 +74,8 @@ function git() {
7274 // Get the current Git hash and remove any newline characters:
7375 cmd = 'git rev-parse HEAD' ;
7476 out = exec ( cmd , opts ) ;
75- hash = out . toString ( ) . match ( / ( .+ ) / ) [ 1 ] ;
77+ out = trim ( out . toString ( ) ) ;
78+ hash = out . match ( / ( .+ ) / ) [ 1 ] ;
7679 debug ( 'Current hash: %s' , hash ) ;
7780
7881 hslug = rslug + '/' + hash ;
0 commit comments