# typed: strong# frozen_string_literal: truerequire"pathname"require"sorbet-runtime"moduleDependabotclassDependencyFileextendT::Sigsig{returns(String)}attr_accessor:namesig{returns(T.nilable(String))}attr_accessor:content# This is the directory of the job source, not the directory of the file itself.# The name actually contains the relative path from the job directory.sig{returns(String)}attr_accessor:directorysig{returns(String)}attr_accessor:typesig{returns(T::Boolean)}attr_accessor:support_filesig{returns(T::Boolean)}attr_accessor:vendored_filesig{returns(T.nilable(String))}attr_accessor:symlink_targetsig{returns(String)}attr_accessor:content_encodingsig{returns(String)}attr_accessor:operationsig{returns(T.nilable(String))}attr_accessor:modeclassContentEncodingUTF_8="utf-8"BASE64="base64"endclassOperationUPDATE="update"CREATE="create"DELETE="delete"endclassModeEXECUTABLE="100755"FILE="100644"TREE="040000"SUBMODULE="160000"SYMLINK="120000"end# See https://github.com/git/git/blob/a36e024e989f4d35f35987a60e3af8022cac3420/object.h#L144-L153VALID_MODES=T.let([Mode::FILE,Mode::EXECUTABLE,Mode::TREE,Mode::SUBMODULE,Mode::SYMLINK].freeze,T::Array[String])sigdoparams(name: String,content: T.nilable(String),directory: String,type: String,support_file: T::Boolean,vendored_file: T::Boolean,symlink_target: T.nilable(String),content_encoding: String,deleted: T::Boolean,operation: String,mode: T.nilable(String)).voidenddefinitialize(name:,content:,directory: "/",type: "file",support_file: false,vendored_file: false,symlink_target: nil,content_encoding: ContentEncoding::UTF_8,deleted: false,operation: Operation::UPDATE,mode: nil)@name=name@content=content@directory=T.let(clean_directory(directory),String)@symlink_target=symlink_target@support_file=support_file@vendored_file=vendored_file@content_encoding=content_encoding@operation=operation@mode=moderaiseArgumentError,"Invalid Git mode: #{mode}"ifmode&&!VALID_MODES.include?(mode)# Make deleted override the operation. Deleted is kept when operation# was introduced to keep compatibility with downstream dependants.@operation=Operation::DELETEifdeleted# Type is used *very* sparingly. It lets the git_modules updater know that# a "file" is actually a submodule, and lets our Go updaters know which# file represents the main.go.# New use cases should be avoided if at all possible (and use the# support_file flag instead)@type=typereturnunless(type=="symlink")^symlink_targetraise"Symlinks must specify a target!"unlesssymlink_targetraise"Only symlinked files must specify a target!"ifsymlink_targetendsig{returns(T::Hash[String,T.untyped])}defto_hdetails={"name"=>name,"content"=>content,"directory"=>directory,"type"=>type,"support_file"=>support_file,"content_encoding"=>content_encoding,"deleted"=>deleted,"operation"=>operation}details["mode"]=modeifmodedetails["symlink_target"]=symlink_targetifsymlink_targetdetailsendsig{returns(String)}defpathPathname.new(File.join(directory,name)).cleanpath.to_pathendsig{returns(String)}defrealpath(symlink_target||path).sub(%r{^/},"")endsig{params(other: BasicObject).returns(T::Boolean)}def==(other)caseotherwhenDependencyFilemy_hash=to_h.reject{|k|k=="support_file"}their_hash=other.to_h.reject{|k|k=="support_file"}my_hash==their_hashelsefalseendendsig{returns(Integer)}defhashto_h.hashendsig{params(other: BasicObject).returns(T::Boolean)}defeql?(other)self==otherendsig{returns(T::Boolean)}defsupport_file?@support_fileendsig{returns(T::Boolean)}defvendored_file?@vendored_fileendsig{returns(T::Boolean)}defdeleted@operation==Operation::DELETEendsig{params(deleted: T::Boolean).void}defdeleted=(deleted)@operation=deleted?Operation::DELETE:Operation::UPDATEendsig{returns(T::Boolean)}defdeleted?deletedendsig{returns(T::Boolean)}defbinary?content_encoding==ContentEncoding::BASE64endsig{returns(String)}defdecoded_contentreturnBase64.decode64(T.must(content))ifbinary?T.must(content)endprivatesig{params(directory: String).returns(String)}defclean_directory(directory)# Directory should always start with a `/`directory.sub(%r{^/*},"/")endendend