MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / prePush

Method prePush

tools/mage/git.go:201–262  ·  view source on GitHub ↗
(stdin string, args ...string)

Source from the content-addressed store, hash-verified

199}
200
201func (g Git) prePush(stdin string, args ...string) error {
202 if mg.Verbose() {
203 fmt.Println("Running pre-push hook")
204 }
205 if stdin == "" {
206 fmt.Println("Standard input is empty, skip pre-push hook")
207 return nil
208 }
209 var (
210 ref string
211 head string
212 )
213 if ss := strings.Fields(stdin); len(ss) == 4 {
214 ref = ss[0]
215 head = ss[1]
216 } else {
217 return fmt.Errorf("expected pre-push hook standard input to contain 4 fields, got: %d(`%s`)", len(ss), ss)
218 }
219 if len(args) != 2 {
220 return fmt.Errorf("pre-push hook expected to get 2 arguments, got: %s", args)
221 }
222 if head == "0000000000000000000000000000000000000000" {
223 // Remote branch is being deleted
224 return nil
225 }
226 const ttiMarkerHash = "f3df41ad99f4acdcb2b038da9a15671023bc827c" // Hash of the first proprietary commit.
227 switch err := exec.Command("git", "merge-base", "--is-ancestor", ttiMarkerHash, head).Run().(type) {
228 case nil:
229 case *exec.ExitError:
230 switch n := err.ExitCode(); n {
231 case 1:
232 return nil
233 case 128:
234 if mg.Verbose() {
235 fmt.Println("Unable to check presence of TTI marker commit: hash not found")
236 }
237 return nil
238 default:
239 return fmt.Errorf("expected exit code of 1, got %d", n)
240 }
241 default:
242 return fmt.Errorf("failed to check presence of TTI marker commit `%s`: %s", ttiMarkerHash, err)
243 }
244 if s := os.Getenv("TTI_REMOTES"); s != "" {
245 for _, remote := range strings.Fields(s) {
246 if args[1] == remote {
247 return nil
248 }
249 }
250 } else {
251 switch args[1] {
252 case "git@github.com:TheThingsIndustries/lorawan-stack",
253 "git@github.com:TheThingsIndustries/lorawan-stack.git",
254 "https://github.com/TheThingsIndustries/lorawan-stack",
255 "https://github.com/TheThingsIndustries/lorawan-stack.git",
256 "ssh://git@github.com:TheThingsIndustries/lorawan-stack",
257 "ssh://git@github.com:TheThingsIndustries/lorawan-stack.git":
258 return nil

Callers 1

RunHookMethod · 0.95

Calls 3

FieldsMethod · 0.65
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected