From ef8c178393deae297754e951315461cc0dcca3d3 Mon Sep 17 00:00:00 2001 From: Orivej Desh Date: Mon, 30 May 2016 00:38:08 +0000 Subject: [PATCH] Add checkout --unstaged flag --- commands/command_checkout.go | 8 ++++++-- docs/man/git-lfs-checkout.1.ronn | 7 ++++++- test/test-checkout.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/commands/command_checkout.go b/commands/command_checkout.go index dfa9e445..395913ab 100644 --- a/commands/command_checkout.go +++ b/commands/command_checkout.go @@ -20,6 +20,7 @@ var ( Use: "checkout", Run: checkoutCommand, } + checkoutUnstagedArg bool ) func checkoutCommand(cmd *cobra.Command, args []string) { @@ -43,6 +44,7 @@ func checkoutCommand(cmd *cobra.Command, args []string) { } func init() { + checkoutCmd.Flags().BoolVarP(&checkoutUnstagedArg, "unstaged", "u", false, "Do not add files to the index") RootCmd.AddCommand(checkoutCmd) } @@ -207,7 +209,7 @@ func checkoutWithChan(in <-chan *lfs.WrappedPointer) { } } - if cmd == nil { + if cmd == nil && !checkoutUnstagedArg { // Fire up the update-index command cmd = exec.Command("git", "update-index", "-q", "--refresh", "--stdin") updateIdxStdin, err = cmd.StdinPipe() @@ -221,7 +223,9 @@ func checkoutWithChan(in <-chan *lfs.WrappedPointer) { } - updateIdxStdin.Write([]byte(cwdfilepath + "\n")) + if updateIdxStdin != nil { + updateIdxStdin.Write([]byte(cwdfilepath + "\n")) + } } close(repopathchan) diff --git a/docs/man/git-lfs-checkout.1.ronn b/docs/man/git-lfs-checkout.1.ronn index c7dd82f3..b7f50312 100644 --- a/docs/man/git-lfs-checkout.1.ronn +++ b/docs/man/git-lfs-checkout.1.ronn @@ -3,7 +3,7 @@ git-lfs-checkout(1) -- Update working copy with file content if available ## SYNOPSIS -`git lfs checkout` ... +`git lfs checkout` [options] ... ## DESCRIPTION @@ -18,6 +18,11 @@ we have it in the local store. Modified files are never overwritten. Filespecs can be provided as arguments to restrict the files which are updated. +## OPTIONS + +* `--unstaged` `-u`: + Do not add files to the index, keeping them unstaged. + ## EXAMPLES * Checkout all files that are missing or placeholders diff --git a/test/test-checkout.sh b/test/test-checkout.sh index bcf20a6a..51daab7c 100755 --- a/test/test-checkout.sh +++ b/test/test-checkout.sh @@ -119,3 +119,34 @@ begin_test "checkout: outside git repository" grep "Not in a git repository" checkout.log ) end_test + +begin_test "checkout --unstaged" +( + set -e + + reponame="$(basename "$0" ".sh")-unstaged" + setup_remote_repo "$reponame" + + clone_repo "$reponame" repo-unstaged + + git lfs track "*.dat" 2>&1 | tee track.log + + contents="something something" + + printf "$contents" > file1.dat + git add file1.dat + git add .gitattributes + git commit -m "add files" + + # Remove the working directory + rm -f file1.dat + + echo "checkout should replace all" + git lfs checkout --unstaged + [ "$contents" = "$(cat file1.dat)" ] + + echo "large files should not be staged" + git diff-files + git diff-files | grep file1.dat +) +end_test