This repository was archived by the owner on Aug 21, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,23 @@ export default class LinkIndex extends Command {
111111 throw new Error ( chalk . red ( "No .git found in this directory. Please initialize a git repository with `git init`." ) ) ;
112112 }
113113
114+ // Check if the current branch is 'main'
115+ let currentBranch = "" ;
116+ try {
117+ currentBranch = execSync ( "git symbolic-ref --short HEAD" , { encoding : "utf-8" } ) . trim ( ) ;
118+ } catch ( error ) {
119+ throw new Error ( chalk . red ( "Unable to determine the current branch. Are you inside a Git repository?" ) ) ;
120+ }
121+
122+ if ( currentBranch !== "main" ) {
123+ this . log ( chalk . red ( "You must be on the 'main' branch to link your repository." ) ) ;
124+ this . log ( "Please switch to the 'main' branch:" ) ;
125+ this . log ( " > git checkout main" ) ;
126+ this . log ( "or rename your current branch to 'main'." ) ;
127+ this . log ( " > git branch -m main" ) ;
128+ this . exit ( 1 ) ;
129+ }
130+
114131 const hasRemoteOrigin = await hasGitRemoteUrl ( gitConfigFilePath ) ;
115132
116133 if ( ! hasRemoteOrigin ) {
@@ -119,10 +136,10 @@ export default class LinkIndex extends Command {
119136 const projectName = path . basename ( gitRoot ) ;
120137 this . log ( `Please create a GitHub repository: https://github.com/new?name=${ projectName } ` ) ;
121138 this . log ( `And push your code:` ) ;
122- this . log ( `> git remote add origin <GIT_URL>` ) ;
123- this . log ( `> git push -u origin main` ) ;
139+ this . log ( ` > git remote add origin <GIT_URL>` ) ;
140+ this . log ( ` > git push -u origin main` ) ;
124141
125- return ;
142+ this . exit ( 1 ) ;
126143 }
127144
128145 const gitUrl = await getGitRemoteUrl ( gitConfigFilePath ) ;
You can’t perform that action at this time.
0 commit comments