Skip to content

Commit 9ee3c19

Browse files
llococean90
andauthored
Add filter to clone a specific Git branch (#275)
* Allows to clone a specific Git branch * Update inc/Loader/Git.php Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com> * Filter documentation improved --------- Co-authored-by: Dominik Schilling <dominikschilling+git@gmail.com>
1 parent f445d69 commit 9ee3c19

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

inc/Loader/Git.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,28 @@ public function download(): ?string {
3737
return 0 === $status ? $target : null;
3838
}
3939

40-
exec(
41-
escapeshellcmd(
42-
sprintf(
43-
'git clone --depth=1 %1$s %2$s -q',
44-
escapeshellarg( $this->get_clone_url() ),
45-
escapeshellarg( $target )
46-
)
47-
),
48-
$output,
49-
$status
40+
$cmd = sprintf(
41+
'git clone --depth 1 %s %s',
42+
escapeshellarg( $this->get_clone_url() ),
43+
escapeshellarg( $target )
5044
);
5145

46+
/**
47+
* Filters which Git branch is checked out when the repository is cloned.
48+
*
49+
* Use this to instruct Traduttore to clone a branch other than the default.
50+
*
51+
* @since 4.0.0
52+
*
53+
* @param string $branch Name of the Git branch to clone. Empty string clones the default branch.
54+
*/
55+
$branch = apply_filters( 'traduttore.git_clone_branch', '' );
56+
if ( '' !== $branch ) {
57+
$cmd .= ' --branch ' . escapeshellarg( $branch );
58+
}
59+
60+
exec( escapeshellcmd( $cmd ), $output, $status );
61+
5262
return 0 === $status ? $target : null;
5363
}
5464

0 commit comments

Comments
 (0)