Skip to content

Commit f50936b

Browse files
authored
Lazily query for git branch & remote (#33936)
1 parent 88fa872 commit f50936b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

scripts/hermes/hermes-utils.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,21 @@ function copyPodSpec() {
159159
}
160160

161161
function isOnAReleaseBranch() {
162-
let currentBranch = execSync('git rev-parse --abbrev-ref HEAD')
163-
.toString()
164-
.trim();
165-
let currentRemote = execSync('git config --get remote.origin.url')
166-
.toString()
167-
.trim();
168-
return (
169-
currentBranch.endsWith('-stable') &&
170-
currentRemote.endsWith('facebook/react-native.git')
171-
);
162+
try {
163+
let currentBranch = execSync('git rev-parse --abbrev-ref HEAD')
164+
.toString()
165+
.trim();
166+
let currentRemote = execSync('git config --get remote.origin.url')
167+
.toString()
168+
.trim();
169+
return (
170+
currentBranch.endsWith('-stable') &&
171+
currentRemote.endsWith('facebook/react-native.git')
172+
);
173+
} catch (error) {
174+
// If not inside a git repo, we're going to fail here and return.
175+
return false;
176+
}
172177
}
173178

174179
function isOnAReleaseTag() {

sdks/hermes-engine/hermes-engine.podspec

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# LICENSE file in the root directory of this source tree.
55

66
require "json"
7+
require "open3"
78

89
# sdks/hermesc/osx-bin/ImportHermesc.cmake
910
import_hermesc_file=File.join(__dir__, "..", "hermesc", "osx-bin", "ImportHermesc.cmake")
@@ -13,8 +14,10 @@ package_file = File.join(__dir__, "..", "..", "package.json")
1314
package = JSON.parse(File.read(package_file))
1415
version = package['version']
1516

16-
currentbranch = `git rev-parse --abbrev-ref HEAD`.strip
17-
currentremote = `git config --get remote.origin.url`.strip
17+
# We need to check the current git branch/remote to verify if
18+
# we're on a React Native release branch to actually build Hermes.
19+
currentbranch, err = Open3.capture3("git rev-parse --abbrev-ref HEAD")
20+
currentremote, err = Open3.capture3("git config --get remote.origin.url")
1821

1922
source = {}
2023
git = "https://github.com/facebook/hermes.git"
@@ -23,7 +26,7 @@ if version == '1000.0.0'
2326
Pod::UI.puts '[Hermes] Hermes needs to be compiled, installing hermes-engine may take a while...'.yellow if Object.const_defined?("Pod::UI")
2427
source[:git] = git
2528
source[:commit] = `git ls-remote https://github.com/facebook/hermes main | cut -f 1`.strip
26-
elsif currentremote.end_with?("facebook/react-native.git") and currentbranch.end_with?("-stable")
29+
elsif currentremote.strip.end_with?("facebook/react-native.git") and currentbranch.strip.end_with?("-stable")
2730
Pod::UI.puts '[Hermes] Detected that you are on a React Native release branch, building Hermes from source...'.yellow if Object.const_defined?("Pod::UI")
2831
source[:git] = git
2932
source[:commit] = `git ls-remote https://github.com/facebook/hermes main | cut -f 1`.strip

0 commit comments

Comments
 (0)