github.com/atlassian/git-lob@v0.0.0-20150806085256-2386a5ed291a/cmd/cmdcheckout.go (about)

     1  package cmd
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/atlassian/git-lob/core"
     7  	"github.com/atlassian/git-lob/util"
     8  )
     9  
    10  func Checkout() int {
    11  
    12  	// git-lob checkout [options] [<pathspec>...]
    13  
    14  	// no custom options
    15  	optDryRun := util.GlobalOptions.DryRun
    16  
    17  	// All extra arguments must be <pathspec>
    18  	var pathspecs []string
    19  	for _, arg := range util.GlobalOptions.Args {
    20  		p := filepath.Clean(arg)
    21  		pathspecs = append(pathspecs, p)
    22  	}
    23  
    24  	var filesCheckedOut int
    25  	var filesFailed int
    26  	var filesUpToDate int
    27  	callback := func(t util.ProgressCallbackType, filelob *core.FileLOB, err error) {
    28  		switch t {
    29  		case util.ProgressSkip:
    30  			filesUpToDate++
    31  		case util.ProgressNotFound:
    32  			util.LogConsole(err.Error())
    33  			filesFailed++
    34  		case util.ProgressError:
    35  			util.LogConsoleError("ERROR:", err.Error())
    36  			filesFailed++
    37  		case util.ProgressTransferBytes:
    38  			if optDryRun {
    39  				util.LogConsoleDebug(filelob.Filename, "needs check out.")
    40  			} else {
    41  				util.LogConsoleDebug(filelob.Filename, "checked out.")
    42  			}
    43  			filesCheckedOut++
    44  		}
    45  
    46  	}
    47  
    48  	err := core.Checkout(pathspecs, optDryRun, callback)
    49  
    50  	if err != nil {
    51  		util.LogConsoleErrorf("git-lob: checkout error - %v\n", err.Error())
    52  		return 7
    53  	}
    54  
    55  	// Report final state
    56  	if optDryRun {
    57  		util.LogConsole(filesCheckedOut, "files need updating")
    58  		if filesCheckedOut > 0 {
    59  			util.LogConsole("Run this command again without --dry-run to update these files.")
    60  		}
    61  	} else {
    62  		util.LogConsole(filesCheckedOut, "files were updated")
    63  		if filesFailed > 0 {
    64  			util.LogConsole("WARNING:", filesFailed, "failed to be updated, check errors above")
    65  		}
    66  	}
    67  
    68  	if filesFailed > 0 {
    69  		// non-zero error code when failures happened
    70  		return 10
    71  	}
    72  	return 0
    73  }
    74  
    75  func CheckoutHelp() {
    76  	util.LogConsole(`Usage: git-lob checkout [options] [<pathspec>...]
    77  
    78    Populate files in the working copy with binary content where they
    79    currently just have placeholder content, because the real content wasn't
    80    available.
    81  
    82    NOTE: You probably won't need to run this command yourself.
    83  
    84          Running 'git lob pull' will both fetch (download) AND checkout, so
    85          most of the time you should use 'git lob pull' instead. 
    86  
    87          Also 'git checkout' will populate the binary content correctly if
    88          you have it locally so you don't have to run this command after
    89          switching branches, unless you need to download extra content, in
    90          which case 'git lob pull' is once again a better bet.
    91  
    92    Because git-lob stores binary content separately from your git repository, 
    93    it's possible that when you perform a 'git checkout' or 'git clone', you did
    94    not have the binary content available locally to populate binary files in 
    95    your working copy. In this situation, git-lob creates placeholders in the
    96    working copy, whose content looks something like this:
    97  
    98    git-lob: <sha>
    99  
   100    Where <sha> is the identifier of the content of the binary file. Once you
   101    have downloaded the content (e.g. via 'git lob fetch'), you can then use
   102    'git lob checkout' to fill in these blanks.
   103  
   104    Specify <pathspec> to limit the checking to particular files or directories.
   105  
   106    Options:
   107      --quiet, -q   Print less output
   108      --verbose, -v Print more output
   109      --dry-run     Don't actually change any files, just report
   110  
   111  `)
   112  }