22
22
23
23
var exec = require ( 'child_process' ) . execSync ;
24
24
var logger = require ( 'debug' ) ;
25
+ var trim = require ( '@stdlib/string/trim' ) ;
25
26
26
27
27
28
// VARIABLES //
28
29
29
30
var debug = logger ( 'remark-img-equations-src-urls:git' ) ;
30
31
31
32
// 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 ) (?: \/ | : ) ( .+ ) (?: \. (?: .+ ) | $ ) / ;
33
34
34
35
35
36
// MAIN //
@@ -52,7 +53,8 @@ function git() {
52
53
53
54
// Get the local git repository path and remove any newline characters:
54
55
dir = exec ( 'git rev-parse --show-toplevel' ) ;
55
- dir = dir . toString ( ) . match ( / ( .+ ) / ) [ 1 ] ;
56
+ dir = trim ( dir . toString ( ) ) ;
57
+ dir = dir . match ( / ( .+ ) / ) [ 1 ] ;
56
58
debug ( 'Local repository directory: %s' , dir ) ;
57
59
58
60
opts = {
@@ -62,7 +64,7 @@ function git() {
62
64
// Get the remote origin:
63
65
cmd = 'git config --get remote.origin.url' ;
64
66
out = exec ( cmd , opts ) ;
65
- origin = out . toString ( ) ;
67
+ origin = trim ( out . toString ( ) ) ;
66
68
debug ( 'Remote origin: %s' , origin ) ;
67
69
68
70
// Extract the repository slug:
@@ -72,7 +74,8 @@ function git() {
72
74
// Get the current Git hash and remove any newline characters:
73
75
cmd = 'git rev-parse HEAD' ;
74
76
out = exec ( cmd , opts ) ;
75
- hash = out . toString ( ) . match ( / ( .+ ) / ) [ 1 ] ;
77
+ out = trim ( out . toString ( ) ) ;
78
+ hash = out . match ( / ( .+ ) / ) [ 1 ] ;
76
79
debug ( 'Current hash: %s' , hash ) ;
77
80
78
81
hslug = rslug + '/' + hash ;
0 commit comments