Skip to content

Commit 528015f

Browse files
committed
:fix: 修复获取当前分支逻辑。
1 parent 75ee403 commit 528015f

File tree

3 files changed

+520
-557
lines changed

3 files changed

+520
-557
lines changed

src/commands/git/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ async function clone(api, { deployDir, gitURL, gitBranch }) {
3232
return await execGit([ 'clone', gitURL, '-b', gitBranch, deployDir ], { cwd: deployDir });
3333
}
3434

35-
function gitPush(api, { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage, name }) {
36-
const currBranch = getCurrBranch();
35+
function gitPush(api, { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage, name, currBranch }) {
3736
// commit + push
3837
const { message } = api.applyPluginHooks('modifyCommandDeployMessage', {
3938
args, config: deployConfig,
@@ -62,12 +61,12 @@ function gitPush(api, { args, deployConfig, deployDir, gitURL, gitBranch, commit
6261
return chain;
6362
}
6463

65-
function getCommitHash(api, { isHooks, gitBranch }) {
64+
function getCommitHash(api, { currBranch, isHooks }) {
6665
let commitHash = '';
6766
if (isHooks) {
6867
commitHash = execGitSync([ 'rev-parse', '--verify', 'HEAD' ]);
6968
} else {
70-
commitHash = execGitSync([ 'rev-parse', `origin/${gitBranch}` ]);
69+
commitHash = execGitSync([ 'rev-parse', `origin/${currBranch}` ]);
7170
}
7271
return commitHash;
7372
}
@@ -83,7 +82,7 @@ function getGitMessage(api, { deployConfig, commitHash }) {
8382
return gitMessage;
8483
}
8584

86-
async function runDeploy(api, { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage }) {
85+
async function runDeploy(api, { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage, currBranch }) {
8786
const logger = api.logger;
8887
const microAppConfig = api.self;
8988
const MICRO_APP_CONFIG_NAME = microAppConfig.packageName;
@@ -119,7 +118,7 @@ async function runDeploy(api, { args, deployConfig, deployDir, gitURL, gitBranch
119118

120119
if (bModify) {
121120
spinner.text = 'Push files...';
122-
await gitPush(api, { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage, name: MICRO_APP_CONFIG_NAME });
121+
await gitPush(api, { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage, name: MICRO_APP_CONFIG_NAME, currBranch });
123122
spinner.succeed(chalk.green('Success!'));
124123
} else {
125124
spinner.succeed(chalk.yellow('NOT MODIFIED!'));
@@ -155,7 +154,9 @@ module.exports = async function deployCommit(api, args, deployConfigs) {
155154
}
156155
const gitUser = getGitUser(deployConfig);
157156

158-
const commitHash = getCommitHash(api, { isHooks, gitBranch });
157+
const currBranch = getCurrBranch(deployConfig);
158+
159+
const commitHash = getCommitHash(api, { currBranch, isHooks });
159160
if (_.isEmpty(commitHash)) {
160161
logger.warn('Not Found commit Hash!');
161162
return;
@@ -169,7 +170,7 @@ module.exports = async function deployCommit(api, args, deployConfigs) {
169170
}
170171
const deployDir = path.resolve(gitRoot, CONSTANTS.GIT_SCOPE_NAME);
171172

172-
const params = { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage };
173+
const params = { args, deployConfig, deployDir, gitURL, gitBranch, commitHash, gitUser, gitMessage, currBranch };
173174
const bSuccessful = await runDeploy(api, params);
174175

175176
// 清空

src/commands/git/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ function execGitSync(args, options = {}) {
3131
return '';
3232
}
3333

34-
function getCurrBranch() {
34+
function getCurrBranch(deployConfig) {
35+
if (deployConfig && deployConfig.baseBranch) {
36+
return deployConfig.baseBranch;
37+
}
3538
const currBranch = execGitSync([ 'rev-parse', '--abbrev-ref', 'HEAD' ]);
3639
return currBranch;
3740
}

0 commit comments

Comments
 (0)