@matheusbsbs / matheus-bagliano / commits / 7c0f7028ee
Fork 0

Set permissions of each new file before "cvs add"ing it.

Otherwise, an executable script in git would end up being checked into the CVS repository without the execute bit. [jc: with an additional test script from Robin Rosenberg.] Signed-off-by: Jim Meyering <jim@meyering.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jim Meyering committed Dec 4, 2006 at 08:44 UTC 7c0f7028ee04f135c7481671f05ca4a66072c78f
2 files changed +29
git-cvsexportcommit.perl
+13
@@ -116,6 +116,7 @@ if ($opt_a) {
116 close MSG;
117
118 my (@afiles, @dfiles, @mfiles, @dirs);
119 +my %amodes;
120 my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit);
121 #print @files;
122 $? && die "Error in git-diff-tree";
@@ -124,6 +125,7 @@ foreach my $f (@files) {
125 my @fields = split(m!\s+!, $f);
126 if ($fields[4] eq 'A') {
127 my $path = $fields[5];
128 + $amodes{$path} = $fields[1];
129 push @afiles, $path;
130 # add any needed parent directories
131 $path = dirname $path;
@@ -268,6 +270,7 @@ if (($? >> 8) == 2) {
270 }
271
272 foreach my $f (@afiles) {
273 + set_new_file_permissions($f, $amodes{$f});
274 if (grep { $_ eq $f } @bfiles) {
275 system('cvs', 'add','-kb',$f);
276 } else {
@@ -342,3 +345,13 @@ sub safe_pipe_capture {
345 }
346 return wantarray ? @output : join('',@output);
347 }
348 +
349 +# For any file we want to add to cvs, we must first set its permissions
350 +# properly, *before* the "cvs add ..." command. Otherwise, it is impossible
351 +# to change the permission of the file in the CVS repository using only cvs
352 +# commands. This should be fixed in cvs-1.12.14.
353 +sub set_new_file_permissions {
354 + my ($file, $perm) = @_;
355 + chmod oct($perm), $file
356 + or die "failed to set permissions of \"$file\": $!\n";
357 +}
t/t9200-git-cvsexportcommit.sh
+16
@@ -142,4 +142,20 @@ test_expect_success \
142 diff F/newfile6.png ../F/newfile6.png
143 )'
144
145 +test_expect_success 'Retain execute bit' '
146 + mkdir G &&
147 + echo executeon >G/on &&
148 + chmod +x G/on &&
149 + echo executeoff >G/off &&
150 + git add G/on &&
151 + git add G/off &&
152 + git commit -a -m "Execute test" &&
153 + (
154 + cd "$CVSWORK" &&
155 + git-cvsexportcommit -c HEAD
156 + test -x G/on &&
157 + ! test -x G/off
158 + )
159 +'
160 +
161 test_done