| 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 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 6 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 7 | |
| 8 | "github.com/git-lfs/git-lfs/v3/toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/" |
| 9 | "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`/" |
| 10 | "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.10.2 `github.com/spf13/cobra`/" |
| 11 | ) |
| 12 | |
| 13 | // untrackCommand takes a list of paths as an argument, and removes each path from the |
| 14 | // default attributes file (.gitattributes), if it exists. |
| 15 | func untrackCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/untrackCommand().(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) { |
| 16 | setupWorkingCopyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/setupWorkingCopy().() |
| 17 | |
| 18 | installHooksscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/installHooks().(false) |
| 19 | |
| 20 | if len(args) < 1 { |
| 21 | Printscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/Print().("git lfs untrack <path> [path]*") |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | data, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.0 os/ReadFile().(".gitattributes") |
| 26 | if err != nil { |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | attributes := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(string(data)) |
| 31 | |
| 32 | attributesFile, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Createscip-go gomod github.com/golang/go/src go1.25.0 os/Create().(".gitattributes") |
| 33 | if err != nil { |
| 34 | 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().("Error opening '.gitattributes' for writing")) |
| 35 | return |
| 36 | } |
| 37 | defer attributesFile.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 38 | |
| 39 | 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().(attributes) |
| 40 | |
| 41 | // Iterate through each line of the attributes file and rewrite it, |
| 42 | // if the path was meant to be untracked, omit it, and print a message instead. |
| 43 | for scanner.Scanscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Scan().() { |
| 44 | line := scanner.Textscip-go gomod github.com/golang/go/src go1.25.0 bufio/Scanner#Text().() |
| 45 | if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(line, "filter=lfs") { |
| 46 | attributesFile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().(line + "\n") |
| 47 | continue |
| 48 | } |
| 49 | |
| 50 | path := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Fieldsscip-go gomod github.com/golang/go/src go1.25.0 strings/Fields().(line)[0] |
| 51 | if removePathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/removePath().(path, args) { |
| 52 | 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().("Untracking %q", unescapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/unescapeAttrPattern().(path))) |
| 53 | } else { |
| 54 | attributesFile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().(line + "\n") |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func removePathscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/removePath().(path string, args []string) bool { |
| 60 | withoutCurrentDir := toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.TrimCurrentPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TrimCurrentPrefix().(path) |
| 61 | for _, t := range args { |
| 62 | if withoutCurrentDir == escapeAttrPatternscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/escapeAttrPattern().(toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/.TrimCurrentPrefixscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TrimCurrentPrefix().(t)) { |
| 63 | return true |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return false |
| 68 | } |
| 69 | |
| 70 | func initscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/init().() { |
| 71 | RegisterCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/RegisterCommand().("untrack", untrackCommandscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/commands`/untrackCommand()., nil) |
| 72 | } |