Debian Codegraph @

commands/command_pre_push.go

raw symbols SCIP
1 package commandsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/
2
3 import (
4 "bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/"
5 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
6 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
7 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
8
9 "github.com/git-lfs/git-lfs/v3/gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/"
10 "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/"
11 "github.com/rubyist/tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/"
12 "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/"
13 )
14
15 var (
16 prePushDryRunscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prePushDryRun. = false
17 )
18
19 // prePushCommand is run through Git's pre-push hook. The pre-push hook passes
20 // two arguments on the command line:
21 //
22 // 1. Name of the remote to which the push is being done
23 // 2. URL to which the push is being done
24 //
25 // The hook receives commit information on stdin in the form:
26 //
27 // <local ref> <local sha1> <remote ref> <remote sha1>
28 //
29 // In the typical case, prePushCommand will get a list of git objects being
30 // pushed by using the following:
31 //
32 // git rev-list --objects <local sha1> ^<remote sha1>
33 //
34 // If any of those git objects are associated with Git LFS objects, those
35 // objects will be pushed to the Git LFS API.
36 //
37 // In the case of pushing a new branch, the list of git objects will be all of
38 // the git objects in this branch.
39 //
40 // In the case of deleting a branch, no attempts to push Git LFS objects will be
41 // made.
42 func prePushCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prePushCommand().(cmd *cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#, args []string) {
43 if len(args) == 0 {
44 Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("This should be run through Git's pre-push hook. Run `git lfs update` to install it."))
45 ExitWithCodescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/ExitWithCode().(1)
46 }
47
48 if cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Osscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Os..Boolscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Environment#Bool.("GIT_LFS_SKIP_PUSH", false) {
49 return
50 }
51
52 requireGitVersionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/requireGitVersion().()
53
54 // Remote is first arg
55 remote, _ := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.MapRemoteURLscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/MapRemoteURL().(args[0], true)
56 if err := cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..SetValidPushRemotescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#SetValidPushRemote().(remote); err != nil {
57 Exitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Exit().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("Invalid remote name %q: %s", args[0], err))
58 }
59
60 ctx := newUploadContextscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/newUploadContext().(prePushDryRunscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prePushDryRun.)
61 updates := prePushRefsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prePushRefs().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stdinscip-go gomod github.com/golang/go/src go1.25.0 os/Stdin.)
62 if err := uploadForRefUpdatesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/uploadForRefUpdates().(ctx, updates, false); err != nil {
63 ExitWithErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/ExitWithError().(err)
64 }
65 }
66
67 // prePushRefs parses commit information that the pre-push git hook receives:
68 //
69 // <local ref> <local sha1> <remote ref> <remote sha1>
70 //
71 // Each line describes a proposed update of the remote ref at the remote sha to
72 // the local sha. Multiple updates can be received on multiple lines (such as
73 // from 'git push --all'). These updates are typically received over STDIN.
74 func prePushRefsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prePushRefs().(r ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#) []*gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.RefUpdatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/RefUpdate# {
75 scanner := bufioscip-go gomod github.com/golang/go/src go1.25.0 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.25.0 bufio/NewScanner().(r)
76 refs := make([]*gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.RefUpdatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/RefUpdate#, 0, 1)
77
78 // We can be passed multiple lines of refs
79 for scanner.Scanscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Scan().() {
80 line := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(scanner.Textscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Text().())
81 if len(line) == 0 {
82 continue
83 }
84
85 tracerxscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/.Printfscip-go gomod github.com/rubyist/tracerx 787959303086 `github.com/rubyist/tracerx`/Printf().("pre-push: %s", line)
86
87 localRef, remoteRef := decodeRefsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/decodeRefs().(line)
88 if gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.IsZeroObjectIDscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/IsZeroObjectID().(localRef.Shascip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#Sha.) {
89 continue
90 }
91
92 refs = append(refs, gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.NewRefUpdatescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/NewRefUpdate().(cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..Gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#Git., cfgscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/cfg..PushRemotescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/config`/Configuration#PushRemote().(), localRef, remoteRef))
93 }
94
95 return refs
96 }
97
98 // decodeRefs pulls the sha1s out of the line read from the pre-push
99 // hook's stdin.
100 func decodeRefsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/decodeRefs().(input string) (*gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.Refscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#, *gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.Refscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Ref#) {
101 refs := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25.0 strings/TrimSpace().(input), " ")
102 for len(refs) < 4 {
103 refs = append(refs, "")
104 }
105
106 localRef := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.ParseRefscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ParseRef().(refs[0], refs[1])
107 remoteRef := gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.ParseRefscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/ParseRef().(refs[2], refs[3])
108 return localRef, remoteRef
109 }
110
111 func initscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/init().() {
112 RegisterCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/RegisterCommand().("pre-push", prePushCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prePushCommand()., func(cmd *cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#) {
113 cmd.Flagsscip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/Command#Flags().().BoolVarPscip-go gomod github.com/spf13/pflag v1.0.9 `github.com/spf13/pflag`/FlagSet#BoolVarP().(&prePushDryRunscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/prePushDryRun., "dry-run", "d", false, "Do everything except actually send the updates")
114 })
115 }