Commits

evhan committed a10907f

bind checkout_opts, use FORCE as default checkout strategy

Comments (0)

Files changed (4)

git-lolevel-exports.scm

  checkout-head
  checkout-index
  checkout-tree
+ checkout-options-default
  clone
  commit-author
  commit-committer
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; checkout.h
 
-(define-foreign-type checkout-options (c-pointer "git_checkout_opts")) ; TODO.
+(define-foreign-record-type (checkout-options git_checkout_opts)
+  (unsigned-int version version)
+  (checkout-strategy checkout_strategy checkout-strategy)
+  (int disable_filters disable-filters)
+  (unsigned-int dir_mode dir-mode)
+  (unsigned-int file_mode file-mode)
+  (int file_open_flags file-open-flags)
+  (unsigned-int notify_flags notify-flags)
+  (c-pointer notify_cb notify-cb) ; TODO (git_checkout_notify_cb notify_cb notify-cb)
+  (c-pointer notify_payload notify-payload)
+  (c-pointer progress_cb progress-cb) ; TODO (git_checkout_progress_cb progress_cb progress-cb)
+  (c-pointer progress_payload progress-payload)
+  ((struct strarray) paths paths)
+  (tree baseline baseline)
+  ((const c-string) target_directory target-directory))
+
+(define-foreign-enum-type (checkout-strategy unsigned-int)
+  (checkout-strategy->int int->checkout-strategy)
+  ((none)                         GIT_CHECKOUT_NONE)
+  ((safe)                         GIT_CHECKOUT_SAFE)
+  ((safe-create)                  GIT_CHECKOUT_SAFE_CREATE)
+  ((force)                        GIT_CHECKOUT_FORCE)
+  ((allow-conflicts)              GIT_CHECKOUT_ALLOW_CONFLICTS)
+  ((remove-untracked)             GIT_CHECKOUT_REMOVE_UNTRACKED)
+  ((remove-ignored)               GIT_CHECKOUT_REMOVE_IGNORED)
+  ((update-only)                  GIT_CHECKOUT_UPDATE_ONLY)
+  ((dont-update-index)            GIT_CHECKOUT_DONT_UPDATE_INDEX)
+  ((no-refresh)                   GIT_CHECKOUT_NO_REFRESH)
+  ((disable-pathspec-match)       GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)
+  ((skip-locked-directories)      GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES)
+  ((skip-unmerged)                GIT_CHECKOUT_SKIP_UNMERGED)
+  ((use-ours)                     GIT_CHECKOUT_USE_OURS)
+  ((use-theirs)                   GIT_CHECKOUT_USE_THEIRS)
+  ((update-submodules)            GIT_CHECKOUT_UPDATE_SUBMODULES)
+  ((update-submodules-if-changed) GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED))
+
+(foreign-declare
+  "git_checkout_opts chicken_git_default_checkout_opts =
+    {GIT_CHECKOUT_OPTS_VERSION, GIT_CHECKOUT_FORCE};")
+
+(define checkout-options-default
+  (foreign-value "&chicken_git_default_checkout_opts" checkout-options))
 
 (define checkout-head  (foreign-lambda/retval git_checkout_head repository checkout-options))
 (define checkout-index (foreign-lambda/retval git_checkout_index repository index checkout-options))
 (define (checkout repo #!optional object)
   (cond
     ((not object)
-     (git-checkout-head (repository->pointer repo) #f))
+     (git-checkout-head (repository->pointer repo) git-checkout-options-default))
     ((index? object)
-     (git-checkout-index (repository->pointer repo) (index->pointer object) #f))
+     (git-checkout-index (repository->pointer repo) (index->pointer object) git-checkout-options-default))
+    ((memq (object-type object) '(commit tag tree))
+     (git-checkout-tree (repository->pointer repo) (object->pointer object) git-checkout-options-default))
     (else
-     (git-checkout-tree (repository->pointer repo) (object->pointer object) #f))))
+     (git-checkout-tree (repository->pointer repo) (->oid->pointer object) git-checkout-options-default))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Commits
 
 If {{object}} is omitted or {{#f}}, the {{repository}}'s working
 directory and index will both be updated to match the state of the
-repository's {{"HEAD"}} commit.
+repository's {{HEAD}}.
+
+Note that {{checkout}} will silently delete untracked files and
+overwrite changes to tracked files in the repository's working
+directory.
 
 ==== Clone