Skip to content

Commit 66d8018

Browse files
committed
Add some messages to pre-receive
1 parent fff0a1d commit 66d8018

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

cmd/hook.go

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Gitea or set your environment appropriately.`, "")
9494
newCommitIDs := make([]string, hookBatchSize)
9595
refFullNames := make([]string, hookBatchSize)
9696
count := 0
97+
total := 0
98+
lastline := 0
9799

98100
for scanner.Scan() {
99101
// TODO: support news feeds for wiki
@@ -109,14 +111,22 @@ Gitea or set your environment appropriately.`, "")
109111
oldCommitID := string(fields[0])
110112
newCommitID := string(fields[1])
111113
refFullName := string(fields[2])
114+
total++
115+
lastline++
112116

113117
// If the ref is a branch, check if it's protected
114118
if strings.HasPrefix(refFullName, git.BranchPrefix) {
115119
oldCommitIDs[count] = oldCommitID
116120
newCommitIDs[count] = newCommitID
117121
refFullNames[count] = refFullName
118122
count++
123+
fmt.Fprintf(os.Stdout, "*")
124+
os.Stdout.Sync()
125+
119126
if count >= hookBatchSize {
127+
fmt.Fprintf(os.Stdout, " Checking %d branches\n", count)
128+
os.Stdout.Sync()
129+
120130
hookOptions.OldCommitIDs = oldCommitIDs
121131
hookOptions.NewCommitIDs = newCommitIDs
122132
hookOptions.RefFullNames = refFullNames
@@ -128,7 +138,16 @@ Gitea or set your environment appropriately.`, "")
128138
fail(msg, "")
129139
}
130140
count = 0
141+
lastline = 0
131142
}
143+
} else {
144+
fmt.Fprintf(os.Stdout, ".")
145+
os.Stdout.Sync()
146+
}
147+
if lastline >= hookBatchSize {
148+
fmt.Fprintf(os.Stdout, "\n")
149+
os.Stdout.Sync()
150+
lastline = 0
132151
}
133152
}
134153

@@ -137,15 +156,25 @@ Gitea or set your environment appropriately.`, "")
137156
hookOptions.NewCommitIDs = newCommitIDs[:count]
138157
hookOptions.RefFullNames = refFullNames[:count]
139158

159+
fmt.Fprintf(os.Stdout, " Checking %d branches\n", count)
160+
os.Stdout.Sync()
161+
140162
statusCode, msg := private.HookPreReceive(username, reponame, hookOptions)
141163
switch statusCode {
142164
case http.StatusInternalServerError:
143165
fail("Internal Server Error", msg)
144166
case http.StatusForbidden:
145167
fail(msg, "")
146168
}
169+
} else if lastline > 0 {
170+
fmt.Fprintf(os.Stdout, "\n")
171+
os.Stdout.Sync()
172+
lastline = 0
147173
}
148174

175+
fmt.Fprintf(os.Stdout, "Checked %d references in total\n", total)
176+
os.Stdout.Sync()
177+
149178
return nil
150179
}
151180

@@ -211,17 +240,17 @@ Gitea or set your environment appropriately.`, "")
211240
continue
212241
}
213242

214-
fmt.Fprintf(os.Stderr, ".")
243+
fmt.Fprintf(os.Stdout, ".")
215244
oldCommitIDs[count] = string(fields[0])
216245
newCommitIDs[count] = string(fields[1])
217246
refFullNames[count] = string(fields[2])
218247
count++
219248
total++
220-
os.Stderr.Sync()
249+
os.Stdout.Sync()
221250

222251
if count >= hookBatchSize {
223-
fmt.Fprintf(os.Stderr, " Processing %d references\n", count)
224-
os.Stderr.Sync()
252+
fmt.Fprintf(os.Stdout, " Processing %d references\n", count)
253+
os.Stdout.Sync()
225254
hookOptions.OldCommitIDs = oldCommitIDs
226255
hookOptions.NewCommitIDs = newCommitIDs
227256
hookOptions.RefFullNames = refFullNames
@@ -237,8 +266,8 @@ Gitea or set your environment appropriately.`, "")
237266

238267
if count == 0 {
239268

240-
fmt.Fprintf(os.Stderr, "Processed %d references in total\n", total)
241-
os.Stderr.Sync()
269+
fmt.Fprintf(os.Stdout, "Processed %d references in total\n", total)
270+
os.Stdout.Sync()
242271

243272
return nil
244273
}
@@ -247,8 +276,8 @@ Gitea or set your environment appropriately.`, "")
247276
hookOptions.NewCommitIDs = newCommitIDs[:count]
248277
hookOptions.RefFullNames = refFullNames[:count]
249278

250-
fmt.Fprintf(os.Stderr, " Processing %d references\n", count)
251-
os.Stderr.Sync()
279+
fmt.Fprintf(os.Stdout, " Processing %d references\n", count)
280+
os.Stdout.Sync()
252281

253282
resps, err := private.HookPostReceive(repoUser, repoName, hookOptions)
254283
if resps == nil {
@@ -257,8 +286,8 @@ Gitea or set your environment appropriately.`, "")
257286
}
258287
results = append(results, resps...)
259288

260-
fmt.Fprintf(os.Stderr, "Processed %d references in total\n", total)
261-
os.Stderr.Sync()
289+
fmt.Fprintf(os.Stdout, "Processed %d references in total\n", total)
290+
os.Stdout.Sync()
262291

263292
hookPrintResults(results)
264293

0 commit comments

Comments
 (0)