eric7/Plugins/VcsPlugins/vcsGit/ProjectHelper.py

branch
eric7
changeset 9153
506e35e424d5
parent 8881
54e42bc2437a
equal deleted inserted replaced
9152:8a68afaf1ba2 9153:506e35e424d5
6 """ 6 """
7 Module implementing the VCS project helper for Git. 7 Module implementing the VCS project helper for Git.
8 """ 8 """
9 9
10 import os 10 import os
11 import pathlib
11 12
12 from PyQt6.QtCore import QFileInfo
13 from PyQt6.QtWidgets import QMenu, QInputDialog, QToolBar 13 from PyQt6.QtWidgets import QMenu, QInputDialog, QToolBar
14 14
15 from EricWidgets import EricMessageBox 15 from EricWidgets import EricMessageBox
16 from EricWidgets.EricApplication import ericApp 16 from EricWidgets.EricApplication import ericApp
17 17
1664 1664
1665 def __gitBranch(self): 1665 def __gitBranch(self):
1666 """ 1666 """
1667 Private slot used to perform branch operations for the project. 1667 Private slot used to perform branch operations for the project.
1668 """ 1668 """
1669 pfile = self.project.getProjectFile() 1669 pfile = pathlib.Path(self.project.getProjectFile())
1670 lastModified = QFileInfo(pfile).lastModified().toString() 1670 lastModified = pfile.stat().st_mtime
1671 shouldReopen = ( 1671 shouldReopen = (
1672 self.vcs.gitBranch(self.project.getProjectPath())[1] or 1672 self.vcs.gitBranch(self.project.getProjectPath())[1] or
1673 QFileInfo(pfile).lastModified().toString() != lastModified 1673 pfile.stat().st_mtime != lastModified
1674 ) 1674 )
1675 if shouldReopen: 1675 if shouldReopen:
1676 res = EricMessageBox.yesNo( 1676 res = EricMessageBox.yesNo(
1677 self.parent(), 1677 self.parent(),
1678 self.tr("Branch"), 1678 self.tr("Branch"),
1708 1708
1709 def __gitPull(self): 1709 def __gitPull(self):
1710 """ 1710 """
1711 Private slot used to pull changes from a remote repository. 1711 Private slot used to pull changes from a remote repository.
1712 """ 1712 """
1713 pfile = self.project.getProjectFile() 1713 pfile = pathlib.Path(self.project.getProjectFile())
1714 lastModified = QFileInfo(pfile).lastModified().toString() 1714 lastModified = pfile.stat().st_mtime
1715 shouldReopen = ( 1715 shouldReopen = (
1716 self.vcs.gitPull(self.project.getProjectPath()) or 1716 self.vcs.gitPull(self.project.getProjectPath()) or
1717 QFileInfo(pfile).lastModified().toString() != lastModified 1717 pfile.stat().st_mtime != lastModified
1718 ) 1718 )
1719 if shouldReopen: 1719 if shouldReopen:
1720 res = EricMessageBox.yesNo( 1720 res = EricMessageBox.yesNo(
1721 self.parent(), 1721 self.parent(),
1722 self.tr("Pull"), 1722 self.tr("Pull"),
1733 1733
1734 def __gitRevert(self): 1734 def __gitRevert(self):
1735 """ 1735 """
1736 Private slot used to revert changes made to the local project. 1736 Private slot used to revert changes made to the local project.
1737 """ 1737 """
1738 pfile = self.project.getProjectFile() 1738 pfile = pathlib.Path(self.project.getProjectFile())
1739 lastModified = QFileInfo(pfile).lastModified().toString() 1739 lastModified = pfile.stat().st_mtime
1740 shouldReopen = ( 1740 shouldReopen = (
1741 self.vcs.vcsRevert(self.project.getProjectPath()) or 1741 self.vcs.vcsRevert(self.project.getProjectPath()) or
1742 QFileInfo(pfile).lastModified().toString() != lastModified 1742 pfile.stat().st_mtime != lastModified
1743 ) 1743 )
1744 if shouldReopen: 1744 if shouldReopen:
1745 res = EricMessageBox.yesNo( 1745 res = EricMessageBox.yesNo(
1746 self.parent(), 1746 self.parent(),
1747 self.tr("Revert Changes"), 1747 self.tr("Revert Changes"),
1752 1752
1753 def __gitUnstage(self): 1753 def __gitUnstage(self):
1754 """ 1754 """
1755 Private slot used to unstage changes made to the local project. 1755 Private slot used to unstage changes made to the local project.
1756 """ 1756 """
1757 pfile = self.project.getProjectFile() 1757 pfile = pathlib.Path(self.project.getProjectFile())
1758 lastModified = QFileInfo(pfile).lastModified().toString() 1758 lastModified = pfile.stat().st_mtime
1759 shouldReopen = ( 1759 shouldReopen = (
1760 self.vcs.gitUnstage(self.project.getProjectPath()) or 1760 self.vcs.gitUnstage(self.project.getProjectPath()) or
1761 QFileInfo(pfile).lastModified().toString() != lastModified 1761 pfile.stat().st_mtime != lastModified
1762 ) 1762 )
1763 if shouldReopen: 1763 if shouldReopen:
1764 res = EricMessageBox.yesNo( 1764 res = EricMessageBox.yesNo(
1765 self.parent(), 1765 self.parent(),
1766 self.tr("Unstage Changes"), 1766 self.tr("Unstage Changes"),
1881 1881
1882 def __gitCherryPick(self): 1882 def __gitCherryPick(self):
1883 """ 1883 """
1884 Private slot used to copy commits into the current branch. 1884 Private slot used to copy commits into the current branch.
1885 """ 1885 """
1886 pfile = self.project.getProjectFile() 1886 pfile = pathlib.Path(self.project.getProjectFile())
1887 lastModified = QFileInfo(pfile).lastModified().toString() 1887 lastModified = pfile.stat().st_mtime
1888 shouldReopen = ( 1888 shouldReopen = (
1889 self.vcs.gitCherryPick(self.project.getProjectPath()) or 1889 self.vcs.gitCherryPick(self.project.getProjectPath()) or
1890 QFileInfo(pfile).lastModified().toString() != lastModified 1890 pfile.stat().st_mtime != lastModified
1891 ) 1891 )
1892 if shouldReopen: 1892 if shouldReopen:
1893 res = EricMessageBox.yesNo( 1893 res = EricMessageBox.yesNo(
1894 None, 1894 None,
1895 self.tr("Copy Commits"), 1895 self.tr("Copy Commits"),
1901 def __gitCherryPickContinue(self): 1901 def __gitCherryPickContinue(self):
1902 """ 1902 """
1903 Private slot used to continue the last copying session after conflicts 1903 Private slot used to continue the last copying session after conflicts
1904 were resolved. 1904 were resolved.
1905 """ 1905 """
1906 pfile = self.project.getProjectFile() 1906 pfile = pathlib.Path(self.project.getProjectFile())
1907 lastModified = QFileInfo(pfile).lastModified().toString() 1907 lastModified = pfile.stat().st_mtime
1908 shouldReopen = ( 1908 shouldReopen = (
1909 self.vcs.gitCherryPickContinue(self.project.getProjectPath()) or 1909 self.vcs.gitCherryPickContinue(self.project.getProjectPath()) or
1910 QFileInfo(pfile).lastModified().toString() != lastModified 1910 pfile.stat().st_mtime != lastModified
1911 ) 1911 )
1912 if shouldReopen: 1912 if shouldReopen:
1913 res = EricMessageBox.yesNo( 1913 res = EricMessageBox.yesNo(
1914 None, 1914 None,
1915 self.tr("Copy Commits (Continue)"), 1915 self.tr("Copy Commits (Continue)"),
1920 1920
1921 def __gitCherryPickQuit(self): 1921 def __gitCherryPickQuit(self):
1922 """ 1922 """
1923 Private slot used to quit the current copying operation. 1923 Private slot used to quit the current copying operation.
1924 """ 1924 """
1925 pfile = self.project.getProjectFile() 1925 pfile = pathlib.Path(self.project.getProjectFile())
1926 lastModified = QFileInfo(pfile).lastModified().toString() 1926 lastModified = pfile.stat().st_mtime
1927 shouldReopen = ( 1927 shouldReopen = (
1928 self.vcs.gitCherryPickQuit(self.project.getProjectPath()) or 1928 self.vcs.gitCherryPickQuit(self.project.getProjectPath()) or
1929 QFileInfo(pfile).lastModified().toString() != lastModified 1929 pfile.stat().st_mtime != lastModified
1930 ) 1930 )
1931 if shouldReopen: 1931 if shouldReopen:
1932 res = EricMessageBox.yesNo( 1932 res = EricMessageBox.yesNo(
1933 None, 1933 None,
1934 self.tr("Copy Commits (Quit)"), 1934 self.tr("Copy Commits (Quit)"),
1940 def __gitCherryPickAbort(self): 1940 def __gitCherryPickAbort(self):
1941 """ 1941 """
1942 Private slot used to cancel the last copying session and return to 1942 Private slot used to cancel the last copying session and return to
1943 the previous state. 1943 the previous state.
1944 """ 1944 """
1945 pfile = self.project.getProjectFile() 1945 pfile = pathlib.Path(self.project.getProjectFile())
1946 lastModified = QFileInfo(pfile).lastModified().toString() 1946 lastModified = pfile.stat().st_mtime
1947 shouldReopen = ( 1947 shouldReopen = (
1948 self.vcs.gitCherryPickAbort(self.project.getProjectPath()) or 1948 self.vcs.gitCherryPickAbort(self.project.getProjectPath()) or
1949 QFileInfo(pfile).lastModified().toString() != lastModified 1949 pfile.stat().st_mtime != lastModified
1950 ) 1950 )
1951 if shouldReopen: 1951 if shouldReopen:
1952 res = EricMessageBox.yesNo( 1952 res = EricMessageBox.yesNo(
1953 None, 1953 None,
1954 self.tr("Copy Commits (Cancel)"), 1954 self.tr("Copy Commits (Cancel)"),
1959 1959
1960 def __gitStashSave(self): 1960 def __gitStashSave(self):
1961 """ 1961 """
1962 Private slot to stash all current changes. 1962 Private slot to stash all current changes.
1963 """ 1963 """
1964 pfile = self.project.getProjectFile() 1964 pfile = pathlib.Path(self.project.getProjectFile())
1965 lastModified = QFileInfo(pfile).lastModified().toString() 1965 lastModified = pfile.stat().st_mtime
1966 shouldReopen = ( 1966 shouldReopen = (
1967 self.vcs.gitStashSave(self.project.getProjectPath()) or 1967 self.vcs.gitStashSave(self.project.getProjectPath()) or
1968 QFileInfo(pfile).lastModified().toString() != lastModified 1968 pfile.stat().st_mtime != lastModified
1969 ) 1969 )
1970 if shouldReopen: 1970 if shouldReopen:
1971 res = EricMessageBox.yesNo( 1971 res = EricMessageBox.yesNo(
1972 self.parent(), 1972 self.parent(),
1973 self.tr("Save Stash"), 1973 self.tr("Save Stash"),
1990 1990
1991 def __gitStashApply(self): 1991 def __gitStashApply(self):
1992 """ 1992 """
1993 Private slot to restore a stash and keep it. 1993 Private slot to restore a stash and keep it.
1994 """ 1994 """
1995 pfile = self.project.getProjectFile() 1995 pfile = pathlib.Path(self.project.getProjectFile())
1996 lastModified = QFileInfo(pfile).lastModified().toString() 1996 lastModified = pfile.stat().st_mtime
1997 shouldReopen = ( 1997 shouldReopen = (
1998 self.vcs.gitStashApply(self.project.getProjectPath()) or 1998 self.vcs.gitStashApply(self.project.getProjectPath()) or
1999 QFileInfo(pfile).lastModified().toString() != lastModified 1999 pfile.stat().st_mtime != lastModified
2000 ) 2000 )
2001 if shouldReopen: 2001 if shouldReopen:
2002 res = EricMessageBox.yesNo( 2002 res = EricMessageBox.yesNo(
2003 self.parent(), 2003 self.parent(),
2004 self.tr("Restore Stash"), 2004 self.tr("Restore Stash"),
2009 2009
2010 def __gitStashPop(self): 2010 def __gitStashPop(self):
2011 """ 2011 """
2012 Private slot to restore a stash and delete it. 2012 Private slot to restore a stash and delete it.
2013 """ 2013 """
2014 pfile = self.project.getProjectFile() 2014 pfile = pathlib.Path(self.project.getProjectFile())
2015 lastModified = QFileInfo(pfile).lastModified().toString() 2015 lastModified = pfile.stat().st_mtime
2016 shouldReopen = ( 2016 shouldReopen = (
2017 self.vcs.gitStashPop(self.project.getProjectPath()) or 2017 self.vcs.gitStashPop(self.project.getProjectPath()) or
2018 QFileInfo(pfile).lastModified().toString() != lastModified 2018 pfile.stat().st_mtime != lastModified
2019 ) 2019 )
2020 if shouldReopen: 2020 if shouldReopen:
2021 res = EricMessageBox.yesNo( 2021 res = EricMessageBox.yesNo(
2022 self.parent(), 2022 self.parent(),
2023 self.tr("Restore Stash"), 2023 self.tr("Restore Stash"),
2028 2028
2029 def __gitStashBranch(self): 2029 def __gitStashBranch(self):
2030 """ 2030 """
2031 Private slot to create a new branch and restore a stash into it. 2031 Private slot to create a new branch and restore a stash into it.
2032 """ 2032 """
2033 pfile = self.project.getProjectFile() 2033 pfile = pathlib.Path(self.project.getProjectFile())
2034 lastModified = QFileInfo(pfile).lastModified().toString() 2034 lastModified = pfile.stat().st_mtime
2035 shouldReopen = ( 2035 shouldReopen = (
2036 self.vcs.gitStashBranch(self.project.getProjectPath()) or 2036 self.vcs.gitStashBranch(self.project.getProjectPath()) or
2037 QFileInfo(pfile).lastModified().toString() != lastModified 2037 pfile.stat().st_mtime != lastModified
2038 ) 2038 )
2039 if shouldReopen: 2039 if shouldReopen:
2040 res = EricMessageBox.yesNo( 2040 res = EricMessageBox.yesNo(
2041 self.parent(), 2041 self.parent(),
2042 self.tr("Create Branch"), 2042 self.tr("Create Branch"),
2145 2145
2146 def __gitBundlePull(self): 2146 def __gitBundlePull(self):
2147 """ 2147 """
2148 Private slot to apply a head of a bundle file using the pull method. 2148 Private slot to apply a head of a bundle file using the pull method.
2149 """ 2149 """
2150 pfile = self.project.getProjectFile() 2150 pfile = pathlib.Path(self.project.getProjectFile())
2151 lastModified = QFileInfo(pfile).lastModified().toString() 2151 lastModified = pfile.stat().st_mtime
2152 shouldReopen = ( 2152 shouldReopen = (
2153 self.vcs.gitBundlePull(self.project.getProjectPath()) or 2153 self.vcs.gitBundlePull(self.project.getProjectPath()) or
2154 QFileInfo(pfile).lastModified().toString() != lastModified 2154 pfile.stat().st_mtime != lastModified
2155 ) 2155 )
2156 if shouldReopen: 2156 if shouldReopen:
2157 res = EricMessageBox.yesNo( 2157 res = EricMessageBox.yesNo(
2158 self.parent(), 2158 self.parent(),
2159 self.tr("Apply Bundle (pull)"), 2159 self.tr("Apply Bundle (pull)"),
2170 2170
2171 def __gitBisectStartExtended(self): 2171 def __gitBisectStartExtended(self):
2172 """ 2172 """
2173 Private slot used to execute the bisect start command with options. 2173 Private slot used to execute the bisect start command with options.
2174 """ 2174 """
2175 pfile = self.project.getProjectFile() 2175 pfile = pathlib.Path(self.project.getProjectFile())
2176 lastModified = QFileInfo(pfile).lastModified().toString() 2176 lastModified = pfile.stat().st_mtime
2177 shouldReopen = ( 2177 shouldReopen = (
2178 self.vcs.gitBisect(self.project.getProjectPath(), 2178 self.vcs.gitBisect(self.project.getProjectPath(),
2179 "start_extended") or 2179 "start_extended") or
2180 QFileInfo(pfile).lastModified().toString() != lastModified 2180 pfile.stat().st_mtime != lastModified
2181 ) 2181 )
2182 if shouldReopen: 2182 if shouldReopen:
2183 res = EricMessageBox.yesNo( 2183 res = EricMessageBox.yesNo(
2184 self.parent(), 2184 self.parent(),
2185 self.tr("Bisect"), 2185 self.tr("Bisect"),
2190 2190
2191 def __gitBisectGood(self): 2191 def __gitBisectGood(self):
2192 """ 2192 """
2193 Private slot used to execute the bisect good command. 2193 Private slot used to execute the bisect good command.
2194 """ 2194 """
2195 pfile = self.project.getProjectFile() 2195 pfile = pathlib.Path(self.project.getProjectFile())
2196 lastModified = QFileInfo(pfile).lastModified().toString() 2196 lastModified = pfile.stat().st_mtime
2197 shouldReopen = ( 2197 shouldReopen = (
2198 self.vcs.gitBisect(self.project.getProjectPath(), "good") or 2198 self.vcs.gitBisect(self.project.getProjectPath(), "good") or
2199 QFileInfo(pfile).lastModified().toString() != lastModified 2199 pfile.stat().st_mtime != lastModified
2200 ) 2200 )
2201 if shouldReopen: 2201 if shouldReopen:
2202 res = EricMessageBox.yesNo( 2202 res = EricMessageBox.yesNo(
2203 self.parent(), 2203 self.parent(),
2204 self.tr("Bisect"), 2204 self.tr("Bisect"),
2209 2209
2210 def __gitBisectBad(self): 2210 def __gitBisectBad(self):
2211 """ 2211 """
2212 Private slot used to execute the bisect bad command. 2212 Private slot used to execute the bisect bad command.
2213 """ 2213 """
2214 pfile = self.project.getProjectFile() 2214 pfile = pathlib.Path(self.project.getProjectFile())
2215 lastModified = QFileInfo(pfile).lastModified().toString() 2215 lastModified = pfile.stat().st_mtime
2216 shouldReopen = ( 2216 shouldReopen = (
2217 self.vcs.gitBisect(self.project.getProjectPath(), "bad") or 2217 self.vcs.gitBisect(self.project.getProjectPath(), "bad") or
2218 QFileInfo(pfile).lastModified().toString() != lastModified 2218 pfile.stat().st_mtime != lastModified
2219 ) 2219 )
2220 if shouldReopen: 2220 if shouldReopen:
2221 res = EricMessageBox.yesNo( 2221 res = EricMessageBox.yesNo(
2222 self.parent(), 2222 self.parent(),
2223 self.tr("Bisect"), 2223 self.tr("Bisect"),
2228 2228
2229 def __gitBisectSkip(self): 2229 def __gitBisectSkip(self):
2230 """ 2230 """
2231 Private slot used to execute the bisect skip command. 2231 Private slot used to execute the bisect skip command.
2232 """ 2232 """
2233 pfile = self.project.getProjectFile() 2233 pfile = pathlib.Path(self.project.getProjectFile())
2234 lastModified = QFileInfo(pfile).lastModified().toString() 2234 lastModified = pfile.stat().st_mtime
2235 shouldReopen = ( 2235 shouldReopen = (
2236 self.vcs.gitBisect(self.project.getProjectPath(), "skip") or 2236 self.vcs.gitBisect(self.project.getProjectPath(), "skip") or
2237 QFileInfo(pfile).lastModified().toString() != lastModified 2237 pfile.stat().st_mtime != lastModified
2238 ) 2238 )
2239 if shouldReopen: 2239 if shouldReopen:
2240 res = EricMessageBox.yesNo( 2240 res = EricMessageBox.yesNo(
2241 self.parent(), 2241 self.parent(),
2242 self.tr("Bisect"), 2242 self.tr("Bisect"),
2247 2247
2248 def __gitBisectReset(self): 2248 def __gitBisectReset(self):
2249 """ 2249 """
2250 Private slot used to execute the bisect reset command. 2250 Private slot used to execute the bisect reset command.
2251 """ 2251 """
2252 pfile = self.project.getProjectFile() 2252 pfile = pathlib.Path(self.project.getProjectFile())
2253 lastModified = QFileInfo(pfile).lastModified().toString() 2253 lastModified = pfile.stat().st_mtime
2254 shouldReopen = ( 2254 shouldReopen = (
2255 self.vcs.gitBisect(self.project.getProjectPath(), "reset") or 2255 self.vcs.gitBisect(self.project.getProjectPath(), "reset") or
2256 QFileInfo(pfile).lastModified().toString() != lastModified 2256 pfile.stat().st_mtime != lastModified
2257 ) 2257 )
2258 if shouldReopen: 2258 if shouldReopen:
2259 res = EricMessageBox.yesNo( 2259 res = EricMessageBox.yesNo(
2260 self.parent(), 2260 self.parent(),
2261 self.tr("Bisect"), 2261 self.tr("Bisect"),
2285 2285
2286 def __gitBisectReplay(self): 2286 def __gitBisectReplay(self):
2287 """ 2287 """
2288 Private slot used to replay a bisect session. 2288 Private slot used to replay a bisect session.
2289 """ 2289 """
2290 pfile = self.project.getProjectFile() 2290 pfile = pathlib.Path(self.project.getProjectFile())
2291 lastModified = QFileInfo(pfile).lastModified().toString() 2291 lastModified = pfile.stat().st_mtime
2292 shouldReopen = ( 2292 shouldReopen = (
2293 self.vcs.gitBisectReplay(self.project.getProjectPath()) or 2293 self.vcs.gitBisectReplay(self.project.getProjectPath()) or
2294 QFileInfo(pfile).lastModified().toString() != lastModified 2294 pfile.stat().st_mtime != lastModified
2295 ) 2295 )
2296 if shouldReopen: 2296 if shouldReopen:
2297 res = EricMessageBox.yesNo( 2297 res = EricMessageBox.yesNo(
2298 self.parent(), 2298 self.parent(),
2299 self.tr("Bisect"), 2299 self.tr("Bisect"),
2312 2312
2313 def __gitApplyPatches(self): 2313 def __gitApplyPatches(self):
2314 """ 2314 """
2315 Private slot to apply a list of patch files. 2315 Private slot to apply a list of patch files.
2316 """ 2316 """
2317 pfile = self.project.getProjectFile() 2317 pfile = pathlib.Path(self.project.getProjectFile())
2318 lastModified = QFileInfo(pfile).lastModified().toString() 2318 lastModified = pfile.stat().st_mtime
2319 self.vcs.gitApplyCheckPatches(self.project.getProjectPath()) 2319 self.vcs.gitApplyCheckPatches(self.project.getProjectPath())
2320 if QFileInfo(pfile).lastModified().toString() != lastModified: 2320 if pfile.stat().st_mtime != lastModified:
2321 res = EricMessageBox.yesNo( 2321 res = EricMessageBox.yesNo(
2322 self.parent(), 2322 self.parent(),
2323 self.tr("Apply patch files"), 2323 self.tr("Apply patch files"),
2324 self.tr("""The project should be reread. Do this now?"""), 2324 self.tr("""The project should be reread. Do this now?"""),
2325 yesDefault=True) 2325 yesDefault=True)

eric ide

mercurial