Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcfc70fe

Browse files
committed
fix(index): handle adding symlinks to dirs
When expanding directories, check if it is a symlink and don't expandthem at all.Previously, we followed symlinks and expanded their contents, whichcould lead to weird index files.Fixes#302
1 parent8724dfa commitcfc70fe

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

‎git/index/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,17 @@ def raise_exc(e):
367367
abs_path=os.path.join(r,path)
368368
# END make absolute path
369369

370+
try:
371+
st=os.lstat(abs_path)# handles non-symlinks as well
372+
exceptOSError:
373+
# the lstat call may fail as the path may contain globs as well
374+
pass
375+
else:
376+
ifS_ISLNK(st.st_mode):
377+
yieldabs_path.replace(rs,'')
378+
continue
379+
# end check symlink
380+
370381
# resolve globs if possible
371382
if'?'inpathor'*'inpathor'['inpath:
372383
forfinself._iter_expand_paths(glob.glob(abs_path)):

‎git/test/test_index.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,18 +542,22 @@ def mixed_iterator():
542542

543543
# add symlink
544544
ifsys.platform!="win32":
545-
basename="my_real_symlink"
546-
target="/etc/that"
547-
link_file=os.path.join(rw_repo.working_tree_dir,basename)
548-
os.symlink(target,link_file)
549-
entries=index.reset(new_commit).add([link_file],fprogress=self._fprogress_add)
550-
self._assert_entries(entries)
551-
self._assert_fprogress(entries)
552-
assertlen(entries)==1andS_ISLNK(entries[0].mode)
553-
assertS_ISLNK(index.entries[index.entry_key("my_real_symlink",0)].mode)
554-
555-
# we expect only the target to be written
556-
assertindex.repo.odb.stream(entries[0].binsha).read().decode('ascii')==target
545+
fortargetin ('/etc/nonexisting','/etc/passwd','/etc'):
546+
basename="my_real_symlink"
547+
548+
link_file=os.path.join(rw_repo.working_tree_dir,basename)
549+
os.symlink(target,link_file)
550+
entries=index.reset(new_commit).add([link_file],fprogress=self._fprogress_add)
551+
self._assert_entries(entries)
552+
self._assert_fprogress(entries)
553+
assertlen(entries)==1andS_ISLNK(entries[0].mode)
554+
assertS_ISLNK(index.entries[index.entry_key("my_real_symlink",0)].mode)
555+
556+
# we expect only the target to be written
557+
assertindex.repo.odb.stream(entries[0].binsha).read().decode('ascii')==target
558+
559+
os.remove(link_file)
560+
# end for each target
557561
# END real symlink test
558562

559563
# add fake symlink and assure it checks-our as symlink

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp