git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Neal Kreitzinger <neal@rsss.com>
Cc: git@vger.kernel.org
Subject: Re: git-reset HEAD --permissions-only
Date: Mon, 14 Mar 2011 21:32:23 -0400	[thread overview]
Message-ID: <20110315013223.GB31865@sigill.intra.peff.net> (raw)
In-Reply-To: <illts0$c6q$1@dough.gmane.org>

On Mon, Mar 14, 2011 at 03:29:51PM -0500, Neal Kreitzinger wrote:

> Is there a way to only reset the file permissions of the working-tree
> to match HEAD file permissions without resetting the content of the
> files?

Not directly, but you could munge a patch to do so and apply it in
reverse. For example:

  git diff "$@" |
  perl -ne '
    if (/^diff/) { $diff = $_ }
    elsif (/^old mode/) { print $diff, $_ }
    elsif (/^new mode/) { print $_ }
  ' |
  git apply -R

Which seems a little more complicated than it needs to be, but we don't
(AFAIK) have a way to say "show me only the mode changes from this
diff in an applicable form". The closest would be "git diff --summary",
but you cannot directly apply it (and I would hesitate to recommend
parsing it).

You could also use "git checkout -p", which is designed for exactly this
sort of picking-apart of a patch, but it has no way to specify "say yes
to all of the mode changes, no to everything else"; you have to manually
approve each hunk. Which doesn't work if you have a lot of these files.

I guess for mode changes, you don't care if you chmod something that is
already fine. So yet another way to do it would be:

  git ls-files -sz |
  perl -0ne '
    /100(\d+).*?\t(.*)/ or next;
    -e $2 or next;
    chmod(oct($1), $2)
      or die "chmod failed: $!";
  '

Hope that helps,
-Peff

  reply	other threads:[~2011-03-15  1:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-14 20:29 git-reset HEAD --permissions-only Neal Kreitzinger
2011-03-15  1:32 ` Jeff King [this message]
2011-03-16  1:06   ` Neal Kreitzinger
2011-03-17  6:01     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110315013223.GB31865@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=neal@rsss.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).