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

Commitd4756f4

Browse files
committed
Merge branch 'fix/deepsource-issues' of github.com:imkaka/GitPython into fix/deepsource-issues
2 parents1dc46d7 +abb1896 commitd4756f4

File tree

12 files changed

+148
-21
lines changed

12 files changed

+148
-21
lines changed

‎AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ Contributors are:
3535
-César Izurieta <cesar _at_ caih.org>
3636
-Arthur Milchior <arthur _at_ milchior.fr>
3737
-Anil Khatri <anil.soccer.khatri _at_ gmail.com>
38+
-JJ Graham <thetwoj _at_ gmail.com>
3839

3940
Portions derived from other open source works and are clearly marked.

‎README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ Please have a look at the [contributions file][contributing].
110110

111111
###How to make a new release
112112

113-
* Update/verify the version in the`VERSION` file
114-
* Update/verify that the changeloghas been updated
113+
* Update/verify the**version** in the`VERSION` file
114+
* Update/verify that the`doc/source/changes.rst`changelogfile was updated
115115
* Commit everything
116116
* Run`git tag -s <version>` to tag the version in Git
117117
* Run`make release`
118-
* Finally, set the upcoming version in the`VERSION` file, usually be
118+
* Close the milestone mentioned in the_changelog_ and create a new one._Do not reuse milestones by renaming them_.
119+
* set the upcoming version in the`VERSION` file, usually be
119120
incrementing the patch level, and possibly by appending`-dev`. Probably you
120121
want to`git push` once more.
121122

‎VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.3
1+
3.0.4

‎doc/source/changes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog
33
=========
44

5+
3.0.4 - Bugfixes
6+
=============================================
7+
8+
see the following for details:
9+
https://github.com/gitpython-developers/gitpython/milestone/31?closed=1
10+
511
3.0.3 - Bugfixes
612
=============================================
713

‎git/cmd.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
defhandle_process_output(process,stdout_handler,stderr_handler,
6969
finalizer=None,decode_streams=True):
70-
"""Registers for notifications tolean that process output is ready to read, and dispatches lines to
70+
"""Registers for notifications tolearn that process output is ready to read, and dispatches lines to
7171
the respective line handlers.
7272
This function returns once the finalizer returns
7373
@@ -330,6 +330,9 @@ def polish_url(cls, url, is_cygwin=None):
330330
but git stops liking them as it will escape the backslashes.
331331
Hence we undo the escaping just to be sure.
332332
"""
333+
url=os.path.expandvars(url)
334+
ifurl.startswith('~'):
335+
url=os.path.expanduser(url)
333336
url=url.replace("\\\\","\\").replace("\\","/")
334337

335338
returnurl
@@ -362,8 +365,11 @@ def __del__(self):
362365
proc.stderr.close()
363366

364367
# did the process finish already so we have a return code ?
365-
ifproc.poll()isnotNone:
366-
return
368+
try:
369+
ifproc.poll()isnotNone:
370+
return
371+
exceptOSErrorasex:
372+
log.info("Ignored error after process had died: %r",ex)
367373

368374
# can be that nothing really exists anymore ...
369375
ifosisNoneorgetattr(os,'kill',None)isNone:

‎git/diff.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class DiffIndex(list):
167167
# R = Renamed
168168
# M = Modified
169169
# T = Changed in the type
170-
change_type= ("A","D","R","M","T")
170+
change_type= ("A","C","D","R","M","T")
171171

172172
defiter_change_type(self,change_type):
173173
"""
@@ -193,6 +193,8 @@ def iter_change_type(self, change_type):
193193
yielddiff
194194
elifchange_type=="D"anddiff.deleted_file:
195195
yielddiff
196+
elifchange_type=="C"anddiff.copied_file:
197+
yielddiff
196198
elifchange_type=="R"anddiff.renamed:
197199
yielddiff
198200
elifchange_type=="M"anddiff.a_blobanddiff.b_blobanddiff.a_blob!=diff.b_blob:
@@ -235,14 +237,17 @@ class Diff(object):
235237
# precompiled regex
236238
re_header=re.compile(br"""
237239
^diff[ ]--git
238-
[ ](?P<a_path_fallback>"?a/.+?"?)[ ](?P<b_path_fallback>"?b/.+?"?)\n
240+
[ ](?P<a_path_fallback>"?[ab]/.+?"?)[ ](?P<b_path_fallback>"?[ab]/.+?"?)\n
239241
(?:^old[ ]mode[ ](?P<old_mode>\d+)\n
240242
^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
241243
(?:^similarity[ ]index[ ]\d+%\n
242244
^rename[ ]from[ ](?P<rename_from>.*)\n
243245
^rename[ ]to[ ](?P<rename_to>.*)(?:\n|$))?
244246
(?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))?
245247
(?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))?
248+
(?:^similarity[ ]index[ ]\d+%\n
249+
^copy[ ]from[ ].*\n
250+
^copy[ ]to[ ](?P<copied_file_name>.*)(?:\n|$))?
246251
(?:^index[ ](?P<a_blob_id>[0-9A-Fa-f]+)
247252
\.\.(?P<b_blob_id>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
248253
(?:^---[ ](?P<a_path>[^\t\n\r\f\v]*)[\t\r\f\v]*(?:\n|$))?
@@ -253,11 +258,11 @@ class Diff(object):
253258
NULL_BIN_SHA=b"\0"*20
254259

255260
__slots__= ("a_blob","b_blob","a_mode","b_mode","a_rawpath","b_rawpath",
256-
"new_file","deleted_file","raw_rename_from","raw_rename_to",
257-
"diff","change_type","score")
261+
"new_file","deleted_file","copied_file","raw_rename_from",
262+
"raw_rename_to","diff","change_type","score")
258263

259264
def__init__(self,repo,a_rawpath,b_rawpath,a_blob_id,b_blob_id,a_mode,
260-
b_mode,new_file,deleted_file,raw_rename_from,
265+
b_mode,new_file,deleted_file,copied_file,raw_rename_from,
261266
raw_rename_to,diff,change_type,score):
262267

263268
self.a_mode=a_mode
@@ -273,6 +278,14 @@ def __init__(self, repo, a_rawpath, b_rawpath, a_blob_id, b_blob_id, a_mode,
273278
ifself.b_mode:
274279
self.b_mode=mode_str_to_int(self.b_mode)
275280

281+
# Determine whether this diff references a submodule, if it does then
282+
# we need to overwrite "repo" to the corresponding submodule's repo instead
283+
ifrepoanda_rawpath:
284+
forsubmoduleinrepo.submodules:
285+
ifsubmodule.path==a_rawpath.decode("utf-8"):
286+
repo=submodule.module()
287+
break
288+
276289
ifa_blob_idisNoneora_blob_id==self.NULL_HEX_SHA:
277290
self.a_blob=None
278291
else:
@@ -285,6 +298,7 @@ def __init__(self, repo, a_rawpath, b_rawpath, a_blob_id, b_blob_id, a_mode,
285298

286299
self.new_file=new_file
287300
self.deleted_file=deleted_file
301+
self.copied_file=copied_file
288302

289303
# be clear and use None instead of empty strings
290304
assertraw_rename_fromisNoneorisinstance(raw_rename_from,binary_type)
@@ -336,6 +350,8 @@ def __str__(self):
336350
msg+='\nfile deleted in rhs'
337351
ifself.new_file:
338352
msg+='\nfile added in rhs'
353+
ifself.copied_file:
354+
msg+='\nfile %r copied from %r'% (self.b_path,self.a_path)
339355
ifself.rename_from:
340356
msg+='\nfile renamed from %r'%self.rename_from
341357
ifself.rename_to:
@@ -420,11 +436,12 @@ def _index_from_patch_format(cls, repo, proc):
420436
a_path_fallback,b_path_fallback, \
421437
old_mode,new_mode, \
422438
rename_from,rename_to, \
423-
new_file_mode,deleted_file_mode, \
439+
new_file_mode,deleted_file_mode,copied_file_name,\
424440
a_blob_id,b_blob_id,b_mode, \
425441
a_path,b_path=_header.groups()
426442

427-
new_file,deleted_file=bool(new_file_mode),bool(deleted_file_mode)
443+
new_file,deleted_file,copied_file= \
444+
bool(new_file_mode),bool(deleted_file_mode),bool(copied_file_name)
428445

429446
a_path=cls._pick_best_path(a_path,rename_from,a_path_fallback)
430447
b_path=cls._pick_best_path(b_path,rename_to,b_path_fallback)
@@ -446,7 +463,7 @@ def _index_from_patch_format(cls, repo, proc):
446463
b_blob_idandb_blob_id.decode(defenc),
447464
a_modeanda_mode.decode(defenc),
448465
b_modeandb_mode.decode(defenc),
449-
new_file,deleted_file,
466+
new_file,deleted_file,copied_file,
450467
rename_from,
451468
rename_to,
452469
None,None,None))
@@ -487,6 +504,7 @@ def handle_diff_line(line):
487504
b_path=path.encode(defenc)
488505
deleted_file=False
489506
new_file=False
507+
copied_file=False
490508
rename_from=None
491509
rename_to=None
492510

@@ -498,6 +516,11 @@ def handle_diff_line(line):
498516
elifchange_type=='A':
499517
a_blob_id=None
500518
new_file=True
519+
elifchange_type=='C':
520+
copied_file=True
521+
a_path,b_path=path.split('\t',1)
522+
a_path=a_path.encode(defenc)
523+
b_path=b_path.encode(defenc)
501524
elifchange_type=='R':
502525
a_path,b_path=path.split('\t',1)
503526
a_path=a_path.encode(defenc)
@@ -509,8 +532,8 @@ def handle_diff_line(line):
509532
# END add/remove handling
510533

511534
diff=Diff(repo,a_path,b_path,a_blob_id,b_blob_id,old_mode,new_mode,
512-
new_file,deleted_file,rename_from,rename_to,'',
513-
change_type,score)
535+
new_file,deleted_file,copied_file,rename_from,rename_to,
536+
'',change_type,score)
514537
index.append(diff)
515538

516539
handle_process_output(proc,handle_diff_line,None,finalize_process,decode_streams=False)

‎git/objects/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ def __init__(self, secs_west_of_utc, name=None):
105105
self._offset=timedelta(seconds=-secs_west_of_utc)
106106
self._name=nameor'fixed'
107107

108+
def__reduce__(self):
109+
returntzoffset, (-self._offset.total_seconds(),self._name)
110+
108111
defutcoffset(self,dt):
109112
returnself._offset
110113

‎git/test/fixtures/diff_copied_mode

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
diff --git a/test1.txt b/test2.txt
2+
similarity index 100%
3+
copy from test1.txt
4+
copy to test2.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:100644 100644 cfe9deac6e10683917e80f877566b58644aa21df cfe9deac6e10683917e80f877566b58644aa21df C100test1.txttest2.txt

‎git/test/test_diff.py

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77
importddt
8+
importshutil
9+
importtempfile
810
fromgitimport (
911
Repo,
1012
GitCommandError,
1113
Diff,
1214
DiffIndex,
1315
NULL_TREE,
16+
Submodule,
1417
)
1518
fromgit.cmdimportGit
1619
fromgit.test.libimport (
@@ -19,7 +22,6 @@
1922
fixture,
2023
assert_equal,
2124
assert_true,
22-
2325
)
2426
fromgit.test.libimportwith_rw_directory
2527

@@ -29,9 +31,15 @@
2931
@ddt.ddt
3032
classTestDiff(TestBase):
3133

34+
defsetUp(self):
35+
self.repo_dir=tempfile.mkdtemp()
36+
self.submodule_dir=tempfile.mkdtemp()
37+
3238
deftearDown(self):
3339
importgc
3440
gc.collect()
41+
shutil.rmtree(self.repo_dir)
42+
shutil.rmtree(self.submodule_dir)
3543

3644
def_assert_diff_format(self,diffs):
3745
# verify that the format of the diff is sane
@@ -60,15 +68,21 @@ def test_diff_with_staged_file(self, rw_dir):
6068

6169
withopen(fp,'w')asfs:
6270
fs.write("Hola Mundo")
63-
r.git.commit(all=True,message="change on master")
71+
r.git.add(Git.polish_url(fp))
72+
self.assertEqual(len(r.index.diff("HEAD",create_patch=True)),1,
73+
"create_patch should generate patch of diff to HEAD")
74+
r.git.commit(message="change on master")
75+
self.assertEqual(len(r.index.diff("HEAD",create_patch=True)),0,
76+
"create_patch should generate no patch, already on HEAD")
6477

6578
r.git.checkout('HEAD~1',b='topic')
6679
withopen(fp,'w')asfs:
6780
fs.write("Hallo Welt")
6881
r.git.commit(all=True,message="change on topic branch")
6982

7083
# there must be a merge-conflict
71-
self.failUnlessRaises(GitCommandError,r.git.cherry_pick,'master')
84+
withself.assertRaises(GitCommandError):
85+
r.git.cherry_pick('master')
7286

7387
# Now do the actual testing - this should just work
7488
self.assertEqual(len(r.index.diff(None)),2)
@@ -112,6 +126,29 @@ def test_diff_with_rename(self):
112126
self.assertEqual(diff.score,100)
113127
self.assertEqual(len(list(diffs.iter_change_type('R'))),1)
114128

129+
deftest_diff_with_copied_file(self):
130+
output=StringProcessAdapter(fixture('diff_copied_mode'))
131+
diffs=Diff._index_from_patch_format(self.rorepo,output)
132+
self._assert_diff_format(diffs)
133+
134+
assert_equal(1,len(diffs))
135+
136+
diff=diffs[0]
137+
assert_true(diff.copied_file)
138+
assert_true(diff.a_path,u'test1.txt')
139+
assert_true(diff.b_path,u'test2.txt')
140+
assertisinstance(str(diff),str)
141+
142+
output=StringProcessAdapter(fixture('diff_copied_mode_raw'))
143+
diffs=Diff._index_from_raw_format(self.rorepo,output)
144+
self.assertEqual(len(diffs),1)
145+
diff=diffs[0]
146+
self.assertEqual(diff.change_type,'C')
147+
self.assertEqual(diff.score,100)
148+
self.assertEqual(diff.a_path,u'test1.txt')
149+
self.assertEqual(diff.b_path,u'test2.txt')
150+
self.assertEqual(len(list(diffs.iter_change_type('C'))),1)
151+
115152
deftest_diff_with_change_in_type(self):
116153
output=StringProcessAdapter(fixture('diff_change_in_type'))
117154
diffs=Diff._index_from_patch_format(self.rorepo,output)
@@ -244,6 +281,43 @@ def test_diff_with_spaces(self):
244281
self.assertIsNone(diff_index[0].a_path,repr(diff_index[0].a_path))
245282
self.assertEqual(diff_index[0].b_path,u'file with spaces',repr(diff_index[0].b_path))
246283

284+
deftest_diff_submodule(self):
285+
"""Test that diff is able to correctly diff commits that cover submodule changes"""
286+
# Init a temp git repo that will be referenced as a submodule
287+
sub=Repo.init(self.submodule_dir)
288+
withopen(self.submodule_dir+"/subfile","w")assub_subfile:
289+
sub_subfile.write("")
290+
sub.index.add(["subfile"])
291+
sub.index.commit("first commit")
292+
293+
# Init a temp git repo that will incorporate the submodule
294+
repo=Repo.init(self.repo_dir)
295+
withopen(self.repo_dir+"/test","w")asfoo_test:
296+
foo_test.write("")
297+
repo.index.add(['test'])
298+
Submodule.add(repo,"subtest","sub",url="file://"+self.submodule_dir)
299+
repo.index.commit("first commit")
300+
repo.create_tag('1')
301+
302+
# Add a commit to the submodule
303+
submodule=repo.submodule('subtest')
304+
withopen(self.repo_dir+"/sub/subfile","w")asfoo_sub_subfile:
305+
foo_sub_subfile.write("blub")
306+
submodule.module().index.add(["subfile"])
307+
submodule.module().index.commit("changed subfile")
308+
submodule.binsha=submodule.module().head.commit.binsha
309+
310+
# Commit submodule updates in parent repo
311+
repo.index.add([submodule])
312+
repo.index.commit("submodule changed")
313+
repo.create_tag('2')
314+
315+
diff=repo.commit('1').diff(repo.commit('2'))[0]
316+
# If diff is unable to find the commit hashes (looks in wrong repo) the *_blob.size
317+
# property will be a string containing exception text, an int indicates success
318+
self.assertIsInstance(diff.a_blob.size,int)
319+
self.assertIsInstance(diff.b_blob.size,int)
320+
247321
deftest_diff_interface(self):
248322
# test a few variations of the main diff routine
249323
assertion_map= {}

‎git/test/test_util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7+
importpickle
78
importtempfile
89
importtime
910
fromunittestimportskipIf
@@ -280,3 +281,9 @@ def test_from_timestamp(self):
280281
# Wrong offset: UTC-9000, should return datetime + tzoffset(UTC)
281282
altz=utctz_to_altz('-9000')
282283
self.assertEqual(datetime.fromtimestamp(1522827734,tzoffset(0)),from_timestamp(1522827734,altz))
284+
285+
deftest_pickle_tzoffset(self):
286+
t1=tzoffset(555)
287+
t2=pickle.loads(pickle.dumps(t1))
288+
self.assertEqual(t1._offset,t2._offset)
289+
self.assertEqual(t1._name,t2._name)

‎init-tests-after-clone.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ git checkout master || git checkout -b master
1212
git reset --hard HEAD~1
1313
git reset --hard HEAD~1
1414
git reset --hard HEAD~1
15-
git reset --hard __testing_point__
15+
git reset --hard __testing_point__
16+
git submodule update --init --recursive

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp