unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
@ 2024-04-23  1:51 Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-23  8:31 ` Philip Kaludercic
  2024-04-23 10:11 ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 11+ messages in thread
From: Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-23  1:51 UTC (permalink / raw)
  To: 70526

[-- Attachment #1: Type: text/plain, Size: 1909 bytes --]

Hi all:


I encountered the following Backtrace information when invoking
`package-vc-upgrade'.


Debugger entered--Lisp error: (error "File is not under version control")
  error("File is not under version control")
  vc-deduce-fileset-1(t nil nil)
  vc-deduce-fileset(t)
  vc-pull()
  ......


After some edebug debugging and reading the source code, I found that
this error occurs if the buffer where `package-vc-upgrade' is called is
not under a git repository. Additionally, if the current buffer of the
command invocation does not correspond to a specific file, then the
command can execute normally.


After reading the implementation of `package-vc-upgrade', I found that it
binds `default-directory' to the package's path. However, the internally
called `vc-pull' function, which uses `vc-deduce-fileset-1', first
utilizes `buffer-file-name' instead of `default-directory' to fetch
version control backend related information, which leads to this error.


In my past usage, I did not encounter this error, probably because I
usually invoked it within a file buffer under a git repository, or used
the command in a buffer provided by `list-packages'. Here is one
solution I used:


(when (eq emacs-major-version 29)
  (defun yy/package-vc-upgrade-advice (upfun pkg-desc)
    (with-temp-buffer
      (funcall upfun pkg-desc)))
  (advice-add 'package-vc-upgrade :around 'yy/package-vc-upgrade-advice))


In a minimal environment with emacs -Q, the following steps can
reproduce my issue:


;; a simple package by purcell
(package-vc-install "https://github.com/purcell/unfill")
;; then try to upgrade it in a buffer that buffer-file-name is not nil
;; and the file is not under Git version control system.
M-x package-vc-upgrade unfill RET
;; now the error may occurs


Regards


YI YUE

[-- Attachment #2: Type: text/html, Size: 2458 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-23  1:51 bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control" Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-23  8:31 ` Philip Kaludercic
  2024-04-23 10:11 ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 11+ messages in thread
From: Philip Kaludercic @ 2024-04-23  8:31 UTC (permalink / raw)
  To: Yi Yue; +Cc: 70526

[-- Attachment #1: Type: text/plain, Size: 1616 bytes --]

"Yi Yue" <include_yy@qq.com> writes:

> Hi all:
>
>
> I encountered the following Backtrace information when invoking
> `package-vc-upgrade'.
>
>
> Debugger entered--Lisp error: (error "File is not under version control")
> &nbsp; error("File is not under version control")
> &nbsp; vc-deduce-fileset-1(t nil nil)
> &nbsp; vc-deduce-fileset(t)
> &nbsp; vc-pull()
> &nbsp; ......
>
>
> After some edebug debugging and reading the source code, I found that
> this error occurs if the buffer where `package-vc-upgrade' is called is
> not under a git repository. Additionally, if the current buffer of the
> command invocation does not correspond to a specific file, then the
> command can execute normally.
>
>
> After reading the implementation of `package-vc-upgrade', I found that it
> binds `default-directory' to the package's path. However, the internally
> called `vc-pull' function, which uses `vc-deduce-fileset-1', first
> utilizes `buffer-file-name' instead of `default-directory' to fetch
> version control backend related information, which leads to this error.
>
>
> In my past usage, I did not encounter this error, probably because I
> usually invoked it within a file buffer under a git repository, or used
> the command in a buffer provided by `list-packages'. Here is one
> solution I used:
>
>
> (when (eq emacs-major-version 29)
> &nbsp; (defun yy/package-vc-upgrade-advice (upfun pkg-desc)
> &nbsp; &nbsp; (with-temp-buffer
> &nbsp; &nbsp; &nbsp; (funcall upfun pkg-desc)))
> &nbsp; (advice-add 'package-vc-upgrade :around 'yy/package-vc-upgrade-advice))

Injecting this into package-vc, we get:


[-- Attachment #2: Type: text/plain, Size: 672 bytes --]

diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
index ef056c7909b..4e88964ecd0 100644
--- a/lisp/emacs-lisp/package-vc.el
+++ b/lisp/emacs-lisp/package-vc.el
@@ -810,8 +810,9 @@ package-vc-upgrade
                   (remove-hook 'vc-post-command-functions post-upgrade))))))
     (add-hook 'vc-post-command-functions post-upgrade)
     (with-demoted-errors "Failed to fetch: %S"
-      (let ((default-directory pkg-dir))
-        (vc-pull)))))
+      (with-temp-buffer
+        (let ((default-directory pkg-dir))
+          (vc-pull))))))
 
 (defun package-vc--archives-initialize ()
   "Initialize package.el and fetch package specifications."

[-- Attachment #3: Type: text/plain, Size: 718 bytes --]


(or alternatively just binding buffer-file-name to nil after default-directory).

but it feels like the fix should happen in vc.el, by being able to
communicate that we the file set should be derived from the default
directory, and the current file should be ignored...

> In a minimal environment with emacs -Q, the following steps can
> reproduce my issue:
>
>
> ;; a simple package by purcell
> (package-vc-install "https://github.com/purcell/unfill")
> ;; then try to upgrade it in a buffer that buffer-file-name is not nil
> ;; and the file is not under Git version control system.
> M-x package-vc-upgrade unfill RET
> ;; now the error may occurs
>
>
> Regards
>
>
> YI YUE

-- 
	Philip Kaludercic on peregrine

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-23  1:51 bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control" Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-23  8:31 ` Philip Kaludercic
@ 2024-04-23 10:11 ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-23 19:35   ` Philip Kaludercic
  1 sibling, 1 reply; 11+ messages in thread
From: Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-23 10:11 UTC (permalink / raw)
  To: 70526; +Cc: philipk

[-- Attachment #1: Type: text/plain, Size: 479 bytes --]

&gt; (or alternatively just binding buffer-file-name to nil after default-directory).


Yes, this is simpler.


&gt; but it feels like the fix should happen in vc.el, by being able to
&gt; communicate that we the file set should be derived from the default
&gt; directory, and the current file should be ignored...


Maybe it is better, but I don't know what will happen if we
change the implementation of `vc-deduce-fileset-1', I don't have
much knowledge of vc.el.

[-- Attachment #2: Type: text/html, Size: 681 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-23 10:11 ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-23 19:35   ` Philip Kaludercic
  2024-04-23 21:07     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-24  2:00     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 11+ messages in thread
From: Philip Kaludercic @ 2024-04-23 19:35 UTC (permalink / raw)
  To: Yi Yue; +Cc: 70526

(unrelated, but why do your messages include HTML entities?)

"Yi Yue" <include_yy@qq.com> writes:

> &gt; (or alternatively just binding buffer-file-name to nil after default-directory).
>
>
> Yes, this is simpler.

My main fear is that this might have some unintended consequences.

> &gt; but it feels like the fix should happen in vc.el, by being able to
> &gt; communicate that we the file set should be derived from the default
> &gt; directory, and the current file should be ignored...
>
> Maybe it is better, but I don't know what will happen if we
> change the implementation of `vc-deduce-fileset-1', I don't have
> much knowledge of vc.el.

I wouldn't want to rely on my understanding of vc either.  While it
would be easy to add a dynamic variable to indicate this behaviour, I am
careful not to overburden the abstractions that VC provides.

-- 
	Philip Kaludercic on peregrine





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-23 19:35   ` Philip Kaludercic
@ 2024-04-23 21:07     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-24  2:00     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 11+ messages in thread
From: Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-23 21:07 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 70526

[-- Attachment #1: Type: text/plain, Size: 1349 bytes --]

&gt; (unrelated, but why do your messages include HTML entities?) (Sorry, I forgot to forbid the default formatter of my email client.) &gt; My main fear is that this might have some unintended consequences. Of course. &gt; I wouldn't want to rely on my understanding of vc either.  While it &gt; would be easy to add a dynamic variable to indicate this behaviour, I am &gt; careful not to overburden the abstractions that VC provides. Understand. I read the docstring of `vc-pull', which is used by `package-vc-upgrade'. It says: --------------------------------------------------------------------------   "Update the current fileset or branch. You must be visiting a version controlled file, or in a `vc-dir' buffer. ..." -------------------------------------------------------------------------- But `vc-dir' is a user command other than a function, it will open a  new buffer and return nil. In consideration of the fact that `vc-pull'  is an async function, it is not easy for us to kill the `vc-diff' buffer  right after the pull operation. As you suggested earlier, maybe we need to modify vc.el, making the restriction looser?  Also, I noticed that the maintainer bind `default-directory' in this commit: https://github.com/emacs-mirror/emacs/commit/7ab556b57631cb28db86b89ba296bc0599d9a399 Improve robustness of 'package-vc-update' Regards

[-- Attachment #2: Type: text/html, Size: 1361 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-23 19:35   ` Philip Kaludercic
  2024-04-23 21:07     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-24  2:00     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-24  6:19       ` Philip Kaludercic
  1 sibling, 1 reply; 11+ messages in thread
From: Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-24  2:00 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 70526

[-- Attachment #1: Type: text/plain, Size: 1398 bytes --]

(sorry for the format problem again) &gt; (unrelated, but why do your messages include HTML entities?)  (Sorry, I forgot to forbid the default formatter of my email client.) &gt; My main fear is that this might have some unintended consequences.  Of course.  &gt; I wouldn't want to rely on my understanding of vc either. While it  &gt; would be easy to add a dynamic variable to indicate this behaviour, I am  &gt; careful not to overburden the abstractions that VC provides.  Understand.  I read the docstring of `vc-pull', which is used by `package-vc-upgrade'.  It says:  --------------------------------------------------------------------------  "Update the current fileset or branch.  You must be visiting a version controlled file, or in a `vc-dir' buffer.  ..." --------------------------------------------------------------------------  But `vc-dir' is a user command other than a function, it will open a new buffer and return nil.  In consideration of the fact that `vc-pull' is an async function, it is not easy for us to  kill the `vc-diff' buffer right after the pull operation.  As you suggested earlier, maybe we need to modify vc.el, making the restriction looser?  Also, I noticed that the maintainer bind `default-directory' in this commit:  https://github.com/emacs-mirror/emacs/commit/7ab556b57631cb28db86b89ba296bc0599d9a399  Improve robustness of 'package-vc-update' Regards

[-- Attachment #2: Type: text/html, Size: 1491 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-24  2:00     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-24  6:19       ` Philip Kaludercic
  2024-04-24  7:02         ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2024-04-24  6:19 UTC (permalink / raw)
  To: Yi Yue; +Cc: 70526

[-- Attachment #1: Type: text/plain, Size: 1278 bytes --]

"Yi Yue" <include_yy@qq.com> writes:

>> (unrelated, but why do your messages include HTML entities?) 
>
> (Sorry, I forgot to forbid the default formatter of my email client.)

it appears more or less correctly when I view the HTML message, so don't
worry.

>> My main fear is that this might have some unintended consequences. 
>
> Of course. 
>
>> I wouldn't want to rely on my understanding of vc either. While it 
>> would be easy to add a dynamic variable to indicate this behaviour, I am 
>> careful not to overburden the abstractions that VC provides. 
>
> Understand. 
>
> I read the docstring of `vc-pull', which is used by `package-vc-upgrade'. 
> It says: 
>
> -------------------------------------------------------------------------- 
> "Update the current fileset or branch. 
> You must be visiting a version controlled file, or in a `vc-dir' buffer. 
> ..."
> -------------------------------------------------------------------------- 
>
> But `vc-dir' is a user command other than a function, it will open a new buffer and return nil. 
> In consideration of the fact that `vc-pull' is an async function, it is not easy for us to 
> kill the `vc-diff' buffer right after the pull operation. 

This actually gives us another possibility how to tackle the issue:


[-- Attachment #2: Type: text/plain, Size: 1111 bytes --]

diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el
index ef056c7909b..c29e8b5d738 100644
--- a/lisp/emacs-lisp/package-vc.el
+++ b/lisp/emacs-lisp/package-vc.el
@@ -774,6 +774,9 @@ package-vc-upgrade-all
         (package-vc-upgrade pkg-desc))))
   (message "Done upgrading packages."))
 
+(declare-function vc-dir-prepare-status-buffer "vc-dir"
+                  (bname dir backend &optional create-new))
+
 ;;;###autoload
 (defun package-vc-upgrade (pkg-desc)
   "Upgrade the package described by PKG-DESC from package's VC repository.
@@ -810,7 +813,10 @@ package-vc-upgrade
                   (remove-hook 'vc-post-command-functions post-upgrade))))))
     (add-hook 'vc-post-command-functions post-upgrade)
     (with-demoted-errors "Failed to fetch: %S"
-      (let ((default-directory pkg-dir))
+      (require 'vc-dir)
+      (with-current-buffer (vc-dir-prepare-status-buffer
+                            (format " *vc-dir: %s*" pkg-dir)
+                            pkg-dir (vc-responsible-backend pkg-dir))
         (vc-pull)))))
 
 (defun package-vc--archives-initialize ()

[-- Attachment #3: Type: text/plain, Size: 722 bytes --]


I am actually satisfied with this approach, and it seems reliable.

>
> As you suggested earlier, maybe we need to modify vc.el, making the restriction looser? 

If you can, try out the above patch and tell me if you end up having any
issues, otherwise I don't think we need to adjust vc.

> Also, I noticed that the maintainer bind `default-directory' in this commit: 
>
> https://github.com/emacs-mirror/emacs/commit/7ab556b57631cb28db86b89ba296bc0599d9a399 
> Improve robustness of 'package-vc-update' Regards

FYI that was my change, GitHub just doesn't display commit names by
default:

https://github.com/emacs-mirror/emacs/commit/7ab556b57631cb28db86b89ba296bc0599d9a399.patch

-- 
	Philip Kaludercic on peregrine

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-24  6:19       ` Philip Kaludercic
@ 2024-04-24  7:02         ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-24  7:51           ` Philip Kaludercic
  0 siblings, 1 reply; 11+ messages in thread
From: Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-24  7:02 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 70526

[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]

&gt; I am actually satisfied with this approach, and it seems reliable. &gt; &gt; &gt; &gt; As you suggested earlier, maybe we need to modify vc.el, making the restriction looser? &gt; If you can, try out the above patch and tell me if you end up having any &gt; issues, otherwise I don't think we need to adjust vc. Yes, it works as expected, thanks. But now it will create an additional empty buffer named "{pkg}*", {pkg} is the name of pacakge. So I suggest the following code: ------------------------------------------------------------------ (with-demoted-errors "Failed to fetch: %S"   (require 'vc-dir)   (let ((vcbuf (vc-dir-prepare-status-buffer                 (format " *vc-dir: %s*" pkg-dir)                 pkg-dir (vc-responsible-backend pkg-dir))))     (unwind-protect 	(with-current-buffer vcbuf           (vc-pull))       (kill-buffer vcbuf)))) ------------------------------------------------------------------- Anyway, I think this buffer doesn't matter. Both are OK. Regards Yi Yue

[-- Attachment #2: Type: text/html, Size: 1090 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-24  7:02         ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-24  7:51           ` Philip Kaludercic
  2024-04-24  8:09             ` o0o0o���� via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 11+ messages in thread
From: Philip Kaludercic @ 2024-04-24  7:51 UTC (permalink / raw)
  To: Yi Yue; +Cc: 70526

"Yi Yue" <include_yy@qq.com> writes:

>> >
>> > As you suggested earlier, maybe we need to modify vc.el, making the restriction looser?
>
>> If you can, try out the above patch and tell me if you end up having any
>> issues, otherwise I don't think we need to adjust vc.
>
> Yes, it works as expected, thanks. But now it will create an
> additional empty buffer named "{pkg}*", {pkg} is the name of pacakge.
> So I suggest the following code:
>
> ------------------------------------------------------------------
> (with-demoted-errors "Failed to fetch: %S"
>   (require 'vc-dir)
>   (let ((vcbuf (vc-dir-prepare-status-buffer
>                 (format " *vc-dir: %s*" pkg-dir)
>                 pkg-dir (vc-responsible-backend pkg-dir))))
>     (unwind-protect
> 	(with-current-buffer vcbuf
>           (vc-pull))
>       (kill-buffer vcbuf))))
> -------------------------------------------------------------------
>
> Anyway, I think this buffer doesn't matter. Both are OK.

As the buffer is hidden, I didn't see the need to clean it up.  It can
be re-used later on and might help with debugging.

> Regards
>
> Yi Yue

-- 
	Philip Kaludercic on peregrine





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-24  7:51           ` Philip Kaludercic
@ 2024-04-24  8:09             ` o0o0o���� via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-27  7:28               ` Philip Kaludercic
  0 siblings, 1 reply; 11+ messages in thread
From: o0o0o���� via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-24  8:09 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: 70526

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 183 bytes --]

&gt; As the buffer is hidden, I didn't see the need to clean it up.  It can &gt; be re-used later on and might help with debugging. I think you are right. Now we fix this bug. Regards

[-- Attachment #2: Type: text/html, Size: 267 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control"
  2024-04-24  8:09             ` o0o0o���� via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-27  7:28               ` Philip Kaludercic
  0 siblings, 0 replies; 11+ messages in thread
From: Philip Kaludercic @ 2024-04-27  7:28 UTC (permalink / raw)
  To: o0o0o耗子; +Cc: 70526

"o0o0o耗子" <include_yy@qq.com> writes:

> &gt; As the buffer is hidden, I didn't see the need to clean it up.
> It can &gt; be re-used later on and might help with debugging. I think
> you are right. Now we fix this bug. Regards

I have pushed the changes, and will therefore close this bug report.
Thank you for your help!

-- 
	Philip Kaludercic on peregrine





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-04-27  7:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-23  1:51 bug#70526: 29.2; package-vc-upgrade failed with error message "File is not under version control" Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-23  8:31 ` Philip Kaludercic
2024-04-23 10:11 ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-23 19:35   ` Philip Kaludercic
2024-04-23 21:07     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-24  2:00     ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-24  6:19       ` Philip Kaludercic
2024-04-24  7:02         ` Yi Yue via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-24  7:51           ` Philip Kaludercic
2024-04-24  8:09             ` o0o0o���� via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-27  7:28               ` Philip Kaludercic

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).