Commits

evhan committed ff70b6b

fall back to repo-discover when initial repo-open fails

Comments (0)

Files changed (3)

git-lolevel-exports.scm

  remote-url
  remote-valid-url
  repository-config
+ repository-discover
  repository-free
  repository-head
  repository-head-detached
 (define repository-head-detached (foreign-lambda bool git_repository_head_detached repository))
 (define repository-head-orphan   (foreign-lambda bool git_repository_head_orphan repository))
 
+(define (repository-discover path)
+  (let* ((len (foreign-value GIT_PATH_MAX int))
+         (str (make-string len)))
+    ((foreign-lambda/retval git_repository_discover scheme-pointer size_t nonnull-c-string bool c-string) str len path #f #f)
+    (substring str 0 (string-index str #\x00))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; remote.h/net.h
 
 (define repository-working-directory repository-workdir)
 
 (define (repository-open #!optional (path (current-directory)))
-  ;; Try opening path as a "normal" repo first (i.e. a workdir with a
-  ;; `.git` directory), and if that doesn't work try as a "bare" repo.
   (let ((path (normalize-pathname path)))
     (pointer->repository
      (condition-case
-      (git-repository-open (make-pathname path ".git"))
-      ((git) (git-repository-open path))))))
+       (git-repository-open path)
+       ((git) (git-repository-open (git-repository-discover path)))))))
 
 (define (repository-ref repo ref #!optional (type 'any))
   (condition-case