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';
2
2
import { validateUser } from './checkUserPushPermission' ;
3
3
import simpleGit from 'simple-git' ;
4
4
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
+
5
23
const exec = async ( req : any , action : Action ) : Promise < Action > => {
6
24
const step = new Step ( 'getMissingData' ) ;
7
25
@@ -11,6 +29,12 @@ const exec = async (req: any, action: Action): Promise<Action> => {
11
29
}
12
30
13
31
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
+ }
14
38
console . log ( `commitData not found, fetching missing commits from git...` ) ;
15
39
const path = `${ action . proxyGitPath } /${ action . repoName } ` ;
16
40
const git = simpleGit ( path ) ;
You can’t perform that action at this time.
0 commit comments