From cd1b6050c5b902472e421d7e487cc8b12cdd23bd Mon Sep 17 00:00:00 2001 From: Otmar Humbel Date: Tue, 1 Dec 2015 17:11:00 +0100 Subject: [PATCH 1/2] prevent reload from moving .gitignore away --- gitFunctions.py | 24 ++++++++++++++++--- rtcFunctions.py | 2 ++ tests/resources/test_ignore_git_status_z.txt | Bin 446 -> 504 bytes tests/test_gitFunctions.py | 22 ++++++++++++++--- tests/test_rtcFunctions.py | 13 +++++++--- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/gitFunctions.py b/gitFunctions.py index 9c98384..f6ea7f0 100644 --- a/gitFunctions.py +++ b/gitFunctions.py @@ -191,14 +191,17 @@ def promotebranchtomaster(branchname): shouter.shout("Branch %s couldnt get renamed to master, please do that on your own" % branchname) return 1 # branch couldnt get renamed + @staticmethod + def get_untracked_statuszlines(): + return shell.getoutput("git status --untracked-files=all -z", stripped=False) + + @staticmethod def handleignore(): """ check untracked files and handle both global and local ignores """ - # make sure we see all untracked files: - lines = shell.getoutput("git status --untracked-files=all -z", stripped=False) - repositoryfiles = Commiter.splitoutputofgitstatusz(lines) + repositoryfiles = Commiter.splitoutputofgitstatusz(Commiter.get_untracked_statuszlines()) Commiter.ignoreextensions(repositoryfiles) Commiter.ignorejazzignore(repositoryfiles) @@ -267,6 +270,21 @@ def translatejazzignore(jazzignorelines): gitignorelines.append(gitignoreline) return gitignorelines + @staticmethod + def restore_shed_gitignore(statuszlines): + """ + If a force reload of the RTC workspace sheds .gitignore files away, we need to restore them. + In this case they are marked as deletions from git. + + :param statuszlines: the git status z output lines + """ + gitignore = ".gitignore" + gitignorelen = len(gitignore) + deletedfiles = Commiter.splitoutputofgitstatusz(statuszlines, ' D ') + for deletedfile in deletedfiles: + if deletedfile[-gitignorelen:] == gitignore: + shell.execute("git checkout -- %s" % deletedfile) + @staticmethod def ignorejazzignore(repositoryfiles): """ diff --git a/rtcFunctions.py b/rtcFunctions.py index 60e89d0..4a387bb 100644 --- a/rtcFunctions.py +++ b/rtcFunctions.py @@ -60,6 +60,8 @@ def load(self): shouter.shout("Start (re)loading current workspace: " + command) shell.execute(command) shouter.shout("Load of workspace finished") + Commiter.restore_shed_gitignore(Commiter.get_untracked_statuszlines()) + def setcomponentstobaseline(self, componentbaselineentries, streamuuid): for entry in componentbaselineentries: diff --git a/tests/resources/test_ignore_git_status_z.txt b/tests/resources/test_ignore_git_status_z.txt index b250586d6a26c75758c385254b362f5eb66b6111..9094fdd2d16c25e97587d29a6b6ff1ed9015bf74 100644 GIT binary patch delta 66 xcmdnT{DXPJK1M4A7lneN{H)aE5<~ssqGWx&^vsgX^t}9{R0edZ;?g8!X#gEe7jFOn delta 7 OcmeytypMUqK1KizFas Date: Fri, 4 Dec 2015 15:35:55 +0100 Subject: [PATCH 2/2] respect a missing sibling .jazzignore file When there is no sibling .jazzignore file, the deletion of .gitignore is correct and should not be reverted. --- gitFunctions.py | 7 +++++-- tests/test_gitFunctions.py | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/gitFunctions.py b/gitFunctions.py index f6ea7f0..5d0160a 100644 --- a/gitFunctions.py +++ b/gitFunctions.py @@ -280,10 +280,13 @@ def restore_shed_gitignore(statuszlines): """ gitignore = ".gitignore" gitignorelen = len(gitignore) - deletedfiles = Commiter.splitoutputofgitstatusz(statuszlines, ' D ') + deletedfiles = Commiter.splitoutputofgitstatusz(statuszlines, " D ") for deletedfile in deletedfiles: if deletedfile[-gitignorelen:] == gitignore: - shell.execute("git checkout -- %s" % deletedfile) + # only restore .gitignore if sibling .jazzignore still exists + jazzignorefile = deletedfile[:-gitignorelen] + ".jazzignore" + if os.path.exists(jazzignorefile): + shell.execute("git checkout -- %s" % deletedfile) @staticmethod def ignorejazzignore(repositoryfiles): diff --git a/tests/test_gitFunctions.py b/tests/test_gitFunctions.py index 8dae105..148a817 100644 --- a/tests/test_gitFunctions.py +++ b/tests/test_gitFunctions.py @@ -215,11 +215,20 @@ def test_splitoutputofgitstatusz_filterprefix_double_question(self): self.assertEqual('project1/src/sub/klingklong.zip', repositoryfiles[6]) @patch('gitFunctions.shell') - def test_restore_shed_gitignore(self, shellmock): + def test_restore_shed_gitignore_with_sibling_jazzignore(self, shellmock): with open(testhelper.getrelativefilename('./resources/test_ignore_git_status_z.txt'), 'r') as file: - Commiter.restore_shed_gitignore(file.readlines()) - calls = [call.execute('git checkout -- project1/src/.gitignore'), call.execute('git checkout -- project1/src/sub/.gitignore')] - shellmock.assert_has_calls(calls) + with patch('os.path.exists', return_value=True): # answer inquries for sibling .jazzignore with True + Commiter.restore_shed_gitignore(file.readlines()) + calls = [call.execute('git checkout -- project1/src/.gitignore'), call.execute('git checkout -- project1/src/sub/.gitignore')] + shellmock.assert_has_calls(calls) + + @patch('gitFunctions.shell') + def test_restore_shed_gitignore_without_sibling_jazzignore(self, shellmock): + with open(testhelper.getrelativefilename('./resources/test_ignore_git_status_z.txt'), 'r') as file: + with patch('os.path.exists', return_value=True): # answer inquries for sibling .jazzignore with False + Commiter.restore_shed_gitignore(file.readlines()) + calls = [] # if there are no siblings, we are not allowed to checkout + shellmock.assert_has_calls(calls) def test_handleignore_global_extensions(self): with testhelper.mkchdir("aFolder") as folder: