File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
src/proxy/processors/push-action Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,24 @@ import { Action, Step } from '../../actions';
22import { validateUser } from './checkUserPushPermission' ;
33import simpleGit from 'simple-git' ;
44
5+ const isEmptyBranch = async ( action : Action ) => {
6+ const git = simpleGit ( `${ action . proxyGitPath } /${ action . repoName } ` ) ;
7+
8+ if ( action . commitFrom === '0' . repeat ( 40 ) ) {
9+ try {
10+ const type = await git . raw ( [ 'cat-file' , '-t' , action . commitTo || '' ] ) ;
11+ const known = type . trim ( ) === 'commit' ;
12+ if ( known ) {
13+ return true ;
14+ }
15+ } catch ( err ) {
16+ console . log ( `Commit ${ action . commitTo } not found: ${ err } ` ) ;
17+ }
18+ }
19+
20+ return false ;
21+ } ;
22+
523const exec = async ( req : any , action : Action ) : Promise < Action > => {
624 const step = new Step ( 'getMissingData' ) ;
725
@@ -11,6 +29,12 @@ const exec = async (req: any, action: Action): Promise<Action> => {
1129 }
1230
1331 if ( action . commitData . length === 0 ) {
32+ if ( await isEmptyBranch ( action ) ) {
33+ step . setError ( 'Push blocked: Empty branch. Please make a commit before pushing a new branch.' ) ;
34+ action . addStep ( step ) ;
35+ step . error = true ;
36+ return action ;
37+ }
1438 console . log ( `commitData not found, fetching missing commits from git...` ) ;
1539 const path = `${ action . proxyGitPath } /${ action . repoName } ` ;
1640 const git = simpleGit ( path ) ;
You can’t perform that action at this time.
0 commit comments