@@ -11,7 +11,8 @@ import (
11
11
)
12
12
13
13
type Config struct {
14
- Rules map [string ]* string `json:"rules"`
14
+ Rules map [string ]* string `json:"rules"`
15
+ Protect []string `json:"protect"`
15
16
}
16
17
17
18
func main () {
@@ -56,6 +57,12 @@ func main() {
56
57
branchName := getCurrentBranchName ()
57
58
config := loadConfig ()
58
59
60
+ // Check if current branch is protected
61
+ if isProtectedBranch (branchName , config .Protect ) {
62
+ fmt .Printf ("Error: Cannot commit to protected branch '%s'\n " , branchName )
63
+ os .Exit (1 )
64
+ }
65
+
59
66
prefix := generatePrefix (branchName , config )
60
67
if prefix != "" {
61
68
commitMessage = fmt .Sprintf ("[%s] %s" , prefix , commitMessage )
@@ -96,7 +103,7 @@ func loadConfig() Config {
96
103
if err != nil {
97
104
if os .IsNotExist (err ) {
98
105
// Return an empty config if the file does not exist
99
- return Config {Rules : map [string ]* string {}}
106
+ return Config {Rules : map [string ]* string {}, Protect : [] string {} }
100
107
}
101
108
fmt .Printf ("Error reading config file at %s: %v\n " , configPath , err )
102
109
os .Exit (1 )
@@ -140,6 +147,15 @@ func generatePrefix(branchName string, config Config) string {
140
147
return fmt .Sprintf ("%s#%s" , * repo , issueNumber )
141
148
}
142
149
150
+ func isProtectedBranch (branchName string , protectedBranches []string ) bool {
151
+ for _ , protected := range protectedBranches {
152
+ if branchName == protected {
153
+ return true
154
+ }
155
+ }
156
+ return false
157
+ }
158
+
143
159
func isAlreadyTagged (commitMessage string ) bool {
144
160
// Check if commit message already contains issue tag like [#123] or [org/repo#123]
145
161
// This pattern matches:
0 commit comments