Skip to content

Commit

Permalink
Merge pull request #6 from Konubinix/master
Browse files Browse the repository at this point in the history
Perform the advice only if the file is into a git repository
  • Loading branch information
jwiegley committed Nov 19, 2013
2 parents bfc3ccb 700207d commit a37648a
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions git-annex.el
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 60,39 @@ otherwise you will have to commit by hand.")
(call-process "git" nil nil nil "commit" "-m" "Updated")))

(defadvice toggle-read-only (before git-annex-edit-file activate)
(when (and buffer-file-name buffer-read-only
(file-symlink-p buffer-file-name))
(let ((target (nth 0 (file-attributes buffer-file-name))))
(assert (stringp target))
(when (string-match "\\.git/annex/" target)
(call-process "git" nil nil nil "annex" "edit"
(file-relative-name buffer-file-name default-directory))
(let ((here (point-marker)))
(unwind-protect
(revert-buffer nil t t)
(goto-char here)))
(add-hook 'kill-buffer-hook 'git-annex-add-file nil t)
(setq buffer-read-only t))))
(when (and buffer-file-name (not buffer-read-only)
(not (file-symlink-p buffer-file-name)))
(let ((cur (current-buffer))
(name buffer-file-name)
(result))
(with-temp-buffer
(call-process "git" nil t nil "diff-files" "--diff-filter=T" "-G^[./]*\\.git/annex/objects/" "--name-only" "--" (file-relative-name name default-directory))
(setq result (buffer-string)))
(unless (string= result "")
(git-annex-add-file)
(let ((here (point-marker)))
(unwind-protect
(revert-buffer nil t t)
(goto-char here)))
(setq buffer-read-only nil)))))
(when (string=
(vc-backend buffer-file-name)
"Git"
)
(when (and buffer-file-name buffer-read-only
(file-symlink-p buffer-file-name))
(let ((target (nth 0 (file-attributes buffer-file-name))))
(assert (stringp target))
(when (string-match "\\.git/annex/" target)
(call-process "git" nil nil nil "annex" "edit"
(file-relative-name buffer-file-name default-directory))
(let ((here (point-marker)))
(unwind-protect
(revert-buffer nil t t)
(goto-char here)))
(add-hook 'kill-buffer-hook 'git-annex-add-file nil t)
(setq buffer-read-only t))))
(when (and buffer-file-name (not buffer-read-only)
(not (file-symlink-p buffer-file-name)))
(let ((cur (current-buffer))
(name buffer-file-name)
(result))
(with-temp-buffer
(call-process "git" nil t nil "diff-files" "--diff-filter=T" "-G^[./]*\\.git/annex/objects/" "--name-only" "--" (file-relative-name name default-directory))
(setq result (buffer-string)))
(unless (string= result "")
(git-annex-add-file)
(let ((here (point-marker)))
(unwind-protect
(revert-buffer nil t t)
(goto-char here)))
(setq buffer-read-only nil)))))
)

(defface git-annex-dired-annexed-available
'((((class color) (background dark))
Expand Down

0 comments on commit a37648a

Please sign in to comment.