github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/doltcore/ref/stash_ref.go (about) 1 // Copyright 2023 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ref 16 17 import ( 18 "strings" 19 ) 20 21 // StashRefName is a dummy name, and there cannot be more than one stash ref. 22 const StashRefName = "stashes" 23 24 type StashRef struct { 25 stash string 26 } 27 28 var _ DoltRef = StashRef{} 29 30 // NewStashRef creates a reference to a stashes list. There cannot be more than one stashRef. 31 func NewStashRef() StashRef { 32 stashName := StashRefName 33 if IsRef(stashName) { 34 prefix := PrefixForType(StashRefType) 35 if strings.HasPrefix(stashName, prefix) { 36 stashName = stashName[len(prefix):] 37 } else { 38 panic(stashName + " is a ref that is not of type " + prefix) 39 } 40 } 41 42 return StashRef{stashName} 43 } 44 45 // GetType will return StashRefType 46 func (br StashRef) GetType() RefType { 47 return StashRefType 48 } 49 50 // GetPath returns the name of the tag 51 func (br StashRef) GetPath() string { 52 return br.stash 53 } 54 55 // String returns the fully qualified reference name e.g. refs/heads/main 56 func (br StashRef) String() string { 57 return String(br) 58 }