Skip to content

Commit 7c0f702

Browse files
meyeringJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 278fcd7 commit 7c0f702

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

git-cvsexportcommit.perl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
close MSG;
117117

118118
my (@afiles, @dfiles, @mfiles, @dirs);
119+
my %amodes;
119120
my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit);
120121
#print @files;
121122
$? && die "Error in git-diff-tree";
@@ -124,6 +125,7 @@
124125
my @fields = split(m!\s+!, $f);
125126
if ($fields[4] eq 'A') {
126127
my $path = $fields[5];
128+
$amodes{$path} = $fields[1];
127129
push @afiles, $path;
128130
# add any needed parent directories
129131
$path = dirname $path;
@@ -268,6 +270,7 @@
268270
}
269271

270272
foreach my $f (@afiles) {
273+
set_new_file_permissions($f, $amodes{$f});
271274
if (grep { $_ eq $f } @bfiles) {
272275
system('cvs', 'add','-kb',$f);
273276
} else {
@@ -342,3 +345,13 @@ sub safe_pipe_capture {
342345
}
343346
return wantarray ? @output : join('',@output);
344347
}
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,20 @@ test_expect_success \
142142
diff F/newfile6.png ../F/newfile6.png
143143
)'
144144

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+
145161
test_done

0 commit comments

Comments
 (0)