From: Alexander Potashev <aspotashev@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Subject: [RFC PATCH] builtin-apply: prevent non-explicit permission changes
Date: Wed, 31 Dec 2008 02:53:57 +0300 [thread overview]
Message-ID: <20081230235357.GA12747@myhost> (raw)
Prevent 'git apply' from changing permissions without
'old mode'/'new mode' lines in patch.
(WARNING: this changes the behaviour of 'git apply')
Signed-off-by: Alexander Potashev <aspotashev@gmail.com>
---
Once upon a time there was a shell script in a Git repository. But that
shell script had 100644 permission (regular file). Then I did
'chmod +x', commit... but the shell script was related to my friend's
stuff in the repository and I received a patch from him regarding the
script. But the patch was against a repository version before
'chmod +x', thus it contained an index line such as the following:
index fc3c3a4..066a4ac 100644
(it still had '100644' permissions)
I have to note that there was no 'old/new mode' lines. But when I ran
'git am <patch>' it restored '100644' permissions. So, 'git am' changed
my permissions (100755 -> 100644) without any explicit permission
changes in the patch.
I think, 'git apply'/'git am' should apply only _changes_ _mentioned_ in
patch; if there's no 'old mode ...'/'new mode ...' lines in it, 'git
apply' shouldn't change the permissions.
Test cases are probably wanted, but I don't really know how to do them
and I'll only give a chain of commands to reproduce the issue:
mkdir repo
cd repo
git init
echo "This is a shell script" > script.sh
git add script.sh
git ci -m "initial commit"
echo "a new line and a newline" >> script.sh
git ci -a -m "only content changes" # aka patch to apply
git format-patch -1 # now we have a patch
git reset --hard HEAD^
chmod +x script.sh
git ci -a -m "permission changes"
git am 0001-only-content-changes.patch
stat -c %a script.sh # check the result
'stat' says '644' if 'git am' has changed the permissions or '755' if
it hasn't.
Alexander
builtin-apply.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 07244b0..071f6d8 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -630,7 +630,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
memcpy(patch->new_sha1_prefix, line, len);
patch->new_sha1_prefix[len] = 0;
if (*ptr == ' ')
- patch->new_mode = patch->old_mode = strtoul(ptr+1, NULL, 8);
+ patch->old_mode = strtoul(ptr+1, NULL, 8);
return 0;
}
@@ -2447,6 +2447,7 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s
if (st_mode != patch->old_mode)
fprintf(stderr, "warning: %s has type %o, expected %o\n",
old_name, st_mode, patch->old_mode);
+ patch->new_mode = st_mode;
return 0;
is_new:
--
1.6.0.6
next reply other threads:[~2008-12-30 23:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-30 23:53 Alexander Potashev [this message]
2009-01-01 13:00 ` [RFC PATCH] builtin-apply: prevent non-explicit permission changes Junio C Hamano
2009-01-01 22:17 ` Alexander Potashev
2009-01-02 0:56 ` Junio C Hamano
2009-01-02 13:37 ` Alexander Potashev
2009-01-02 10:55 ` Junio C Hamano
2009-01-02 17:35 ` 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=20081230235357.GA12747@myhost \
--to=aspotashev@gmail.com \
--cc=git@vger.kernel.org \
/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).