Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support temporarily ignoring files using git update-index --assume-unchanged #531

Closed
jixiuf opened this issue Jan 12, 2013 · 9 comments
Closed
Labels
wont add This feature will not be worked on
Milestone

Comments

@jixiuf
Copy link

jixiuf commented Jan 12, 2013

[alias]
    ignore = !git update-index --assume-unchanged
    unignore = !git update-index --no-assume-unchanged
    # ignored = !git ls-files -v | grep ^[a-z]
         # ignored = !git ls-files -v | grep "^[[:lower:]]" | awk '{print $2}'
    ignored = !git ls-files -v | grep "^[[:lower:]]"

I can use this command in my shell ,

     git ignore filename 
     git unignore filename 
     gilt ignored  

and I hope magit can support this feature.

@tarsius
Copy link
Member

tarsius commented May 26, 2013

I don't think this is particularly useful. At least not in Magit: you cannot easily tell Git show me the difference except for this file; in Magit you would just collapse the item showing the boring file's diffs.

@tarsius tarsius closed this as completed May 26, 2013
@kuanyui
Copy link

kuanyui commented Nov 23, 2017

Just want to say that I indeed encountered some situation which need this function...

During development, I want to modify a file temporarily for debug / testing; however this modification:

  1. Don't want to be committed nor pushed because it's quite large and not needed by others.
  2. The modification is quite large, which cause fold/expand function of Magit crash.
  3. Even if the fold/expand function is available, that's easily be committed & pushed carelessly.

@zilongshanren
Copy link
Contributor

zilongshanren commented Jul 21, 2019

@jixiuf @kuanyui

I have write some elisp code to implement this feature and it works perfect for assume-unchanged:

(defun magit-skip-assume-unchanged-files ()
  (--keep (and (and (= (aref it 0) ?h)
                    (substring it 2)))
          (magit-git-items "ls-files"
                           (string-trim
                            (car (magit-git-items "rev-parse" "--show-toplevel")))
                           "-v" "--full-name" "-z")))

(defun magit-insert-assume-unchanged-files ()
  "Insert a tree of assume unchanged files.

    If the first element of `magit-buffer-diff-files' is a
    directory, then limit the list to files below that.  The value
    of that variable can be set using \"D -- DIRECTORY RET g\"."
  (when-let ((files (magit-skip-assume-unchanged-files)))
    (let* ((base (car magit-buffer-diff-files))
           (base (and base (file-directory-p base) base)))
      (magit-insert-section (assume-unchanged nil t)
        (magit-insert-heading "Assume-unchanged files:")
        (magit-insert-files files base)
        (insert ?\n)))))

(defun magit-list-all-files ()
    (magit-with-toplevel
      (with-temp-buffer
        (apply #'magit-git-insert '("ls-files" "-z" "--full-name"))
        (split-string (buffer-string) "\0" t))))

(defun magit-assume-unchanged (file)
  "Call \"git update-index --assume-unchanged FILE\"."
  (interactive (list (magit-read-file-choice "Assume unchanged for: "
                                             (cl-set-difference
                                              (magit-list-all-files)
                                              (magit-skip-assume-unchanged-files)))))
  (magit-with-toplevel
    (magit-run-git "update-index" "--assume-unchanged" "--" file)))

(defun magit-no-assume-unchanged (file)
  "Call \"git update-index --no-assume-unchanged FILE\"."
  (interactive (list (magit-read-file-choice "Do not assume unchanged for: "
                                             (magit-skip-assume-unchanged-files))))
  (magit-with-toplevel
    (magit-run-git "update-index" "--no-assume-unchanged" "--" file)))

Add assume-unchanged section to magit-status buffer:

 (magit-add-section-hook 'magit-status-sections-hook
                         'magit-insert-assume-unchanged-files nil t)

   ;; define jump 
 (magit-define-section-jumper magit-jump-to-assume-unchanged "Assume-unchanged files" assume-unchanged)
 (define-key magit-status-mode-map "ga" 'magit-jump-to-assume-unchanged)

@phil-s
Copy link
Contributor

phil-s commented Jul 21, 2019

Very nice @zilongshanren ; cheers. It looks like the prompts should lose the trailing : as that's being added automatically (so we end up with two of them), but otherwise (at least at first glance) that works great!

@tarsius I think this feature is worth including. Git's support for this isn't very visible which in turn can make usage error-prone if users simply forget that certain files are being treated this way, so I think this integration in the status buffer is really beneficial.

@tarsius
Copy link
Member

tarsius commented Jul 21, 2019

I think this feature is worth including.

Agreed. (Changed my mind in the six years since I rejected this proposal.)

@phil-s
Copy link
Contributor

phil-s commented Jul 22, 2019

Excellent. Perhaps remove the "wontadd" label and re-open the issue?

@tarsius
Copy link
Member

tarsius commented Jul 22, 2019

I was hoping for a pull-request from @zilongshanren.

@zilongshanren
Copy link
Contributor

@tarsius
At your command, PR is coming. It's my first time to contribute to magit, helps are wanted. 😄

@tarsius
Copy link
Member

tarsius commented Jul 24, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wont add This feature will not be worked on
Development

No branches or pull requests

5 participants