src/eric7/Plugins/VcsPlugins/vcsGit/git.py

branch
eric7
changeset 9616
13aa04c979d7
parent 9576
be9f8e7e42e0
child 9617
6a32a62e55e7
equal deleted inserted replaced
9615:fbb3616f6bd3 9616:13aa04c979d7
72 "branches", 72 "branches",
73 ] 73 ]
74 74
75 self.commandHistory = [] 75 self.commandHistory = []
76 76
77 self.adminDir = ".git" 77 self.adminDirOrFile = ".git"
78 78
79 self.log = None 79 self.log = None
80 self.logBrowser = None 80 self.logBrowser = None
81 self.reflogBrowser = None 81 self.reflogBrowser = None
82 self.diff = None 82 self.diff = None
339 @param vcsDataDict dictionary of data required for the checkout 339 @param vcsDataDict dictionary of data required for the checkout
340 @param projectDir project directory to create (string) 340 @param projectDir project directory to create (string)
341 @return flag indicating an execution without errors (boolean) 341 @return flag indicating an execution without errors (boolean)
342 """ 342 """
343 status = self.vcsCheckout(vcsDataDict, projectDir) 343 status = self.vcsCheckout(vcsDataDict, projectDir)
344 shutil.rmtree(os.path.join(projectDir, self.adminDir), True) 344 adminPath = os.path.join(projectDir, self.adminDirOrFile)
345 if os.path.isdir(adminPath):
346 shutil.rmtree(adminPath, True)
347 else:
348 os.remove(adminPath)
345 if os.path.exists(os.path.join(projectDir, Git.IgnoreFileName)): 349 if os.path.exists(os.path.join(projectDir, Git.IgnoreFileName)):
346 os.remove(os.path.join(projectDir, Git.IgnoreFileName)) 350 os.remove(os.path.join(projectDir, Git.IgnoreFileName))
347 return status 351 return status
348 352
349 def vcsCommit(self, name, message="", noDialog=False, commitAll=True, amend=False): 353 def vcsCommit(self, name, message="", noDialog=False, commitAll=True, amend=False):
452 dname, fnames = self.splitPathList(name) 456 dname, fnames = self.splitPathList(name)
453 else: 457 else:
454 dname, fname = self.splitPath(name) 458 dname, fname = self.splitPath(name)
455 459
456 # find the root of the repo 460 # find the root of the repo
457 repodir = dname 461 repodir = self.findRepoRoot(dname)
458 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 462 if not repodir:
459 repodir = os.path.dirname(repodir) 463 return
460 if os.path.splitdrive(repodir)[1] == os.sep:
461 return
462 464
463 if isinstance(name, list): 465 if isinstance(name, list):
464 args.append("--") 466 args.append("--")
465 self.addArguments(args, fnames) 467 self.addArguments(args, fnames)
466 else: 468 else:
554 if fname != ".": 556 if fname != ".":
555 args.append("--") 557 args.append("--")
556 args.append(fname) 558 args.append(fname)
557 559
558 # find the root of the repo 560 # find the root of the repo
559 repodir = dname 561 repodir = self.findRepoRoot(dname)
560 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 562 if not repodir:
561 repodir = os.path.dirname(repodir) 563 return False
562 if os.path.splitdrive(repodir)[1] == os.sep:
563 return False
564 564
565 if noDialog: 565 if noDialog:
566 self.startSynchronizedProcess(QProcess(), "git", args, repodir) 566 self.startSynchronizedProcess(QProcess(), "git", args, repodir)
567 res = False 567 res = False
568 else: 568 else:
595 dname, fname = os.path.split(name) 595 dname, fname = os.path.split(name)
596 else: 596 else:
597 dname, fname = self.splitPath(name) 597 dname, fname = self.splitPath(name)
598 598
599 # find the root of the repo 599 # find the root of the repo
600 repodir = dname 600 repodir = self.findRepoRoot(dname)
601 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 601 if not repodir:
602 repodir = os.path.dirname(repodir) 602 return
603 if os.path.splitdrive(repodir)[1] == os.sep:
604 return
605 603
606 if isinstance(name, list): 604 if isinstance(name, list):
607 self.addArguments(args, name) 605 self.addArguments(args, name)
608 else: 606 else:
609 args.append(name) 607 args.append(name)
672 dname, fname = self.splitPath(name) 670 dname, fname = self.splitPath(name)
673 args.append("--") 671 args.append("--")
674 args.append(name) 672 args.append(name)
675 673
676 # find the root of the repo 674 # find the root of the repo
677 repodir = dname 675 repodir = self.findRepoRoot(dname)
678 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 676 if not repodir:
679 repodir = os.path.dirname(repodir) 677 return False
680 if os.path.splitdrive(repodir)[1] == os.sep:
681 return False
682 678
683 if noDialog: 679 if noDialog:
684 res = self.startSynchronizedProcess(QProcess(), "git", args, repodir) 680 res = self.startSynchronizedProcess(QProcess(), "git", args, repodir)
685 else: 681 else:
686 dia = GitDialog( 682 dia = GitDialog(
738 args.append(name) 734 args.append(name)
739 args.append(target) 735 args.append(target)
740 736
741 dname, fname = self.splitPath(name) 737 dname, fname = self.splitPath(name)
742 # find the root of the repo 738 # find the root of the repo
743 repodir = dname 739 repodir = self.findRepoRoot(dname)
744 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 740 if not repodir:
745 repodir = os.path.dirname(repodir) 741 return False
746 if os.path.splitdrive(repodir)[1] == os.sep:
747 return False
748 742
749 if noDialog: 743 if noDialog:
750 res = self.startSynchronizedProcess(QProcess(), "git", args, repodir) 744 res = self.startSynchronizedProcess(QProcess(), "git", args, repodir)
751 else: 745 else:
752 dia = GitDialog(self.tr("Renaming {0}").format(name), self) 746 dia = GitDialog(self.tr("Renaming {0}").format(name), self)
857 dname, fnames = self.splitPathList(name) 851 dname, fnames = self.splitPathList(name)
858 else: 852 else:
859 dname, fname = self.splitPath(name) 853 dname, fname = self.splitPath(name)
860 854
861 # find the root of the repo 855 # find the root of the repo
862 repodir = dname 856 repodir = self.findRepoRoot(dname)
863 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 857 if not repodir:
864 repodir = os.path.dirname(repodir) 858 return False
865 if os.path.splitdrive(repodir)[1] == os.sep:
866 return False
867 859
868 args = self.initCommand("reset") 860 args = self.initCommand("reset")
869 args.append("HEAD") 861 args.append("HEAD")
870 args.append("--") 862 args.append("--")
871 if isinstance(name, list): 863 if isinstance(name, list):
904 dname, fname = self.splitPath(name) 896 dname, fname = self.splitPath(name)
905 args.append(name) 897 args.append(name)
906 names = [name] 898 names = [name]
907 899
908 # find the root of the repo 900 # find the root of the repo
909 repodir = dname 901 repodir = self.findRepoRoot(dname)
910 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 902 if not repodir:
911 repodir = os.path.dirname(repodir) 903 return False
912 if os.path.splitdrive(repodir)[1] == os.sep:
913 return False
914 904
915 project = ericApp().getObject("Project") 905 project = ericApp().getObject("Project")
916 names = [project.getRelativePath(nam) for nam in names] 906 names = [project.getRelativePath(nam) for nam in names]
917 if names[0]: 907 if names[0]:
918 dlg = DeleteFilesConfirmationDialog( 908 dlg = DeleteFilesConfirmationDialog(
955 from .GitMergeDialog import GitMergeDialog 945 from .GitMergeDialog import GitMergeDialog
956 946
957 dname, fname = self.splitPath(name) 947 dname, fname = self.splitPath(name)
958 948
959 # find the root of the repo 949 # find the root of the repo
960 repodir = dname 950 repodir = self.findRepoRoot(dname)
961 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 951 if not repodir:
962 repodir = os.path.dirname(repodir) 952 return
963 if os.path.splitdrive(repodir)[1] == os.sep:
964 return
965 953
966 dlg = GitMergeDialog( 954 dlg = GitMergeDialog(
967 self.gitGetTagsList(repodir), 955 self.gitGetTagsList(repodir),
968 self.gitGetBranchesList(repodir, withMaster=True), 956 self.gitGetBranchesList(repodir, withMaster=True),
969 self.gitGetCurrentBranch(repodir), 957 self.gitGetCurrentBranch(repodir),
1007 from .GitRevisionSelectionDialog import GitRevisionSelectionDialog 995 from .GitRevisionSelectionDialog import GitRevisionSelectionDialog
1008 996
1009 dname, fname = self.splitPath(name) 997 dname, fname = self.splitPath(name)
1010 998
1011 # find the root of the repo 999 # find the root of the repo
1012 repodir = dname 1000 repodir = self.findRepoRoot(dname)
1013 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1001 if not repodir:
1014 repodir = os.path.dirname(repodir) 1002 return False
1015 if os.path.splitdrive(repodir)[1] == os.sep:
1016 return False
1017 1003
1018 dlg = GitRevisionSelectionDialog( 1004 dlg = GitRevisionSelectionDialog(
1019 self.gitGetTagsList(repodir), 1005 self.gitGetTagsList(repodir),
1020 self.gitGetBranchesList(repodir), 1006 self.gitGetBranchesList(repodir),
1021 trackingBranchesList=self.gitGetBranchesList(repodir, remotes=True), 1007 trackingBranchesList=self.gitGetBranchesList(repodir, remotes=True),
1037 if name.endswith(os.sep): 1023 if name.endswith(os.sep):
1038 name = name[:-1] 1024 name = name[:-1]
1039 name = os.path.normcase(name) 1025 name = os.path.normcase(name)
1040 dname, fname = self.splitPath(name) 1026 dname, fname = self.splitPath(name)
1041 1027
1042 if fname == "." and os.path.isdir(os.path.join(dname, self.adminDir)): 1028 if fname == "." and os.path.exists(os.path.join(dname, self.adminDirOrFile)):
1043 return self.canBeCommitted 1029 return self.canBeCommitted
1044 1030
1045 if name in self.statusCache: 1031 if name in self.statusCache:
1046 return self.statusCache[name] 1032 return self.statusCache[name]
1047 1033
1048 # find the root of the repo 1034 # find the root of the repo
1049 repodir = dname 1035 repodir = self.findRepoRoot(dname)
1050 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1036 if not repodir:
1051 repodir = os.path.dirname(repodir) 1037 return 0
1052 if os.path.splitdrive(repodir)[1] == os.sep:
1053 return 0
1054 1038
1055 args = self.initCommand("status") 1039 args = self.initCommand("status")
1056 args.append("--porcelain") 1040 args.append("--porcelain")
1057 args.append(name) 1041 args.append(name)
1058 1042
1118 found = True 1102 found = True
1119 names[name] = self.statusCache[name] 1103 names[name] = self.statusCache[name]
1120 1104
1121 if not found: 1105 if not found:
1122 # find the root of the repo 1106 # find the root of the repo
1123 repodir = dname 1107 repodir = self.findRepoRoot(dname)
1124 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1108 if not repodir:
1125 repodir = os.path.dirname(repodir) 1109 return names
1126 if os.path.splitdrive(repodir)[1] == os.sep:
1127 return names
1128 1110
1129 args = self.initCommand("status") 1111 args = self.initCommand("status")
1130 args.append("--porcelain") 1112 args.append("--porcelain")
1131 1113
1132 ioEncoding = Preferences.getSystem("IOEncoding") 1114 ioEncoding = Preferences.getSystem("IOEncoding")
1233 1215
1234 args = [] 1216 args = []
1235 self.addArguments(args, commandList) 1217 self.addArguments(args, commandList)
1236 1218
1237 # find the root of the repo 1219 # find the root of the repo
1238 repodir = name 1220 repodir = self.findRepoRoot(name)
1239 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1221 if not repodir:
1240 repodir = os.path.dirname(repodir) 1222 return
1241 if os.path.splitdrive(repodir)[1] == os.sep:
1242 return
1243 1223
1244 dia = GitDialog(self.tr("Git Command"), self) 1224 dia = GitDialog(self.tr("Git Command"), self)
1245 res = dia.startProcess(args, repodir) 1225 res = dia.startProcess(args, repodir)
1246 if res: 1226 if res:
1247 dia.exec() 1227 dia.exec()
1591 project = ericApp().getObject("Project") 1571 project = ericApp().getObject("Project")
1592 if nam == project.ppath and not project.saveAllScripts(): 1572 if nam == project.ppath and not project.saveAllScripts():
1593 return 1573 return
1594 1574
1595 # find the root of the repo 1575 # find the root of the repo
1596 repodir = dname 1576 repodir = self.findRepoRoot(dname)
1597 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1577 if not repodir:
1598 repodir = os.path.dirname(repodir) 1578 return
1599 if os.path.splitdrive(repodir)[1] == os.sep:
1600 return
1601 1579
1602 dlg = GitRevisionsSelectionDialog( 1580 dlg = GitRevisionsSelectionDialog(
1603 self.gitGetTagsList(repodir), self.gitGetBranchesList(repodir) 1581 self.gitGetTagsList(repodir), self.gitGetBranchesList(repodir)
1604 ) 1582 )
1605 if dlg.exec() == QDialog.DialogCode.Accepted: 1583 if dlg.exec() == QDialog.DialogCode.Accepted:
1618 @param name file name to get from the repository (string) 1596 @param name file name to get from the repository (string)
1619 @param rev revision to retrieve (string) 1597 @param rev revision to retrieve (string)
1620 @return contents of the file (string) and an error message (string) 1598 @return contents of the file (string) and an error message (string)
1621 """ 1599 """
1622 # find the root of the repo 1600 # find the root of the repo
1623 repodir = self.splitPath(name)[0] 1601 repodir = self.findRepoRoot(self.splitPath(name)[0])
1624 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1602 if not repodir:
1625 repodir = os.path.dirname(repodir) 1603 return False
1626 if os.path.splitdrive(repodir)[1] == os.sep:
1627 return False
1628 1604
1629 args = self.initCommand("cat-file") 1605 args = self.initCommand("cat-file")
1630 args.append("blob") 1606 args.append("blob")
1631 args.append("{0}:{1}".format(rev, name.replace(repodir + os.sep, ""))) 1607 args.append("{0}:{1}".format(rev, name.replace(repodir + os.sep, "")))
1632 1608
1680 if isinstance(name, list): 1656 if isinstance(name, list):
1681 raise ValueError("Wrong parameter type") 1657 raise ValueError("Wrong parameter type")
1682 1658
1683 if extended: 1659 if extended:
1684 # find the root of the repo 1660 # find the root of the repo
1685 repodir = self.splitPath(name)[0] 1661 repodir = self.findRepoRoot(self.splitPath(name)[0])
1686 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1662 if not repodir:
1687 repodir = os.path.dirname(repodir) 1663 return
1688 if os.path.splitdrive(repodir)[1] == os.sep:
1689 return
1690 1664
1691 dlg = GitRevisionsSelectionDialog( 1665 dlg = GitRevisionsSelectionDialog(
1692 self.gitGetTagsList(repodir), self.gitGetBranchesList(repodir) 1666 self.gitGetTagsList(repodir), self.gitGetBranchesList(repodir)
1693 ) 1667 )
1694 if dlg.exec() == QDialog.DialogCode.Accepted: 1668 if dlg.exec() == QDialog.DialogCode.Accepted:
1745 @param name directory name (string) 1719 @param name directory name (string)
1746 """ 1720 """
1747 from .GitFetchDialog import GitFetchDialog 1721 from .GitFetchDialog import GitFetchDialog
1748 1722
1749 # find the root of the repo 1723 # find the root of the repo
1750 repodir = self.splitPath(name)[0] 1724 repodir = self.findRepoRoot(self.splitPath(name)[0])
1751 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1725 if not repodir:
1752 repodir = os.path.dirname(repodir) 1726 return
1753 if os.path.splitdrive(repodir)[1] == os.sep:
1754 return
1755 1727
1756 dlg = GitFetchDialog(self, repodir) 1728 dlg = GitFetchDialog(self, repodir)
1757 if dlg.exec() == QDialog.DialogCode.Accepted: 1729 if dlg.exec() == QDialog.DialogCode.Accepted:
1758 ( 1730 (
1759 remote, 1731 remote,
1795 or delete (boolean) 1767 or delete (boolean)
1796 """ 1768 """
1797 from .GitPullDialog import GitPullDialog 1769 from .GitPullDialog import GitPullDialog
1798 1770
1799 # find the root of the repo 1771 # find the root of the repo
1800 repodir = self.splitPath(name)[0] 1772 repodir = self.findRepoRoot(self.splitPath(name)[0])
1801 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1773 if not repodir:
1802 repodir = os.path.dirname(repodir) 1774 return False
1803 if os.path.splitdrive(repodir)[1] == os.sep:
1804 return False
1805 1775
1806 dlg = GitPullDialog(self, repodir) 1776 dlg = GitPullDialog(self, repodir)
1807 if dlg.exec() == QDialog.DialogCode.Accepted: 1777 if dlg.exec() == QDialog.DialogCode.Accepted:
1808 remote, url, branches, pullAll, prune = dlg.getData() 1778 remote, url, branches, pullAll, prune = dlg.getData()
1809 1779
1835 @param name directory name of the project to be pushed from (string) 1805 @param name directory name of the project to be pushed from (string)
1836 """ 1806 """
1837 from .GitPushDialog import GitPushDialog 1807 from .GitPushDialog import GitPushDialog
1838 1808
1839 # find the root of the repo 1809 # find the root of the repo
1840 repodir = self.splitPath(name)[0] 1810 repodir = self.findRepoRoot(self.splitPath(name)[0])
1841 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1811 if not repodir:
1842 repodir = os.path.dirname(repodir) 1812 return
1843 if os.path.splitdrive(repodir)[1] == os.sep:
1844 return
1845 1813
1846 dlg = GitPushDialog(self, repodir) 1814 dlg = GitPushDialog(self, repodir)
1847 if dlg.exec() == QDialog.DialogCode.Accepted: 1815 if dlg.exec() == QDialog.DialogCode.Accepted:
1848 remote, refspecs, tags, tracking, submodule = dlg.getData() 1816 remote, refspecs, tags, tracking, submodule = dlg.getData()
1849 1817
1872 @param name file/directory name (string) 1840 @param name file/directory name (string)
1873 """ 1841 """
1874 dname, fname = self.splitPath(name) 1842 dname, fname = self.splitPath(name)
1875 1843
1876 # find the root of the repo 1844 # find the root of the repo
1877 repodir = dname 1845 repodir = self.findRepoRoot(dname)
1878 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1846 if not repodir:
1879 repodir = os.path.dirname(repodir) 1847 return
1880 if os.path.splitdrive(repodir)[1] == os.sep:
1881 return
1882 1848
1883 editor = sys.argv[0].replace(".py", "_editor.py") 1849 editor = sys.argv[0].replace(".py", "_editor.py")
1884 env = {"GIT_EDITOR": "{0} {1}".format(Globals.getPythonExecutable(), editor)} 1850 env = {"GIT_EDITOR": "{0} {1}".format(Globals.getPythonExecutable(), editor)}
1885 1851
1886 args = self.initCommand("commit") 1852 args = self.initCommand("commit")
1901 or delete (boolean) 1867 or delete (boolean)
1902 """ 1868 """
1903 dname, fname = self.splitPath(name) 1869 dname, fname = self.splitPath(name)
1904 1870
1905 # find the root of the repo 1871 # find the root of the repo
1906 repodir = dname 1872 repodir = self.findRepoRoot(dname)
1907 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1873 if not repodir:
1908 repodir = os.path.dirname(repodir) 1874 return False
1909 if os.path.splitdrive(repodir)[1] == os.sep:
1910 return False
1911 1875
1912 args = self.initCommand("merge") 1876 args = self.initCommand("merge")
1913 args.append("--abort") 1877 args.append("--abort")
1914 1878
1915 dia = GitDialog(self.tr("Aborting uncommitted/failed merge"), self) 1879 dia = GitDialog(self.tr("Aborting uncommitted/failed merge"), self)
1956 @param check flag indicating to perform a check operation (boolean) 1920 @param check flag indicating to perform a check operation (boolean)
1957 """ 1921 """
1958 from .GitPatchFilesDialog import GitPatchFilesDialog 1922 from .GitPatchFilesDialog import GitPatchFilesDialog
1959 1923
1960 # find the root of the repo 1924 # find the root of the repo
1961 repodir = projectDir 1925 repodir = self.findRepoRoot(projectDir)
1962 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1926 if not repodir:
1963 repodir = os.path.dirname(repodir) 1927 return
1964 if os.path.splitdrive(repodir)[1] == os.sep:
1965 return
1966 1928
1967 dlg = GitPatchFilesDialog(repodir, self.__patchCheckData) 1929 dlg = GitPatchFilesDialog(repodir, self.__patchCheckData)
1968 if dlg.exec() == QDialog.DialogCode.Accepted: 1930 if dlg.exec() == QDialog.DialogCode.Accepted:
1969 patchFilesList, stripCount, inaccurateEof, recount = dlg.getData() 1931 patchFilesList, stripCount, inaccurateEof, recount = dlg.getData()
1970 if patchFilesList: 1932 if patchFilesList:
2027 from .GitTagDialog import GitTagDialog 1989 from .GitTagDialog import GitTagDialog
2028 1990
2029 dname, fname = self.splitPath(name) 1991 dname, fname = self.splitPath(name)
2030 1992
2031 # find the root of the repo 1993 # find the root of the repo
2032 repodir = dname 1994 repodir = self.findRepoRoot(dname)
2033 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 1995 if not repodir:
2034 repodir = os.path.dirname(repodir) 1996 return False
2035 if os.path.splitdrive(repodir)[1] == os.sep:
2036 return False
2037 1997
2038 dlg = GitTagDialog(self.gitGetTagsList(repodir), revision, tagName) 1998 dlg = GitTagDialog(self.gitGetTagsList(repodir), revision, tagName)
2039 if dlg.exec() == QDialog.DialogCode.Accepted: 1999 if dlg.exec() == QDialog.DialogCode.Accepted:
2040 tag, revision, tagOp, tagType, force = dlg.getParameters() 2000 tag, revision, tagOp, tagType, force = dlg.getParameters()
2041 else: 2001 else:
2229 from .GitBranchDialog import GitBranchDialog 2189 from .GitBranchDialog import GitBranchDialog
2230 2190
2231 dname, fname = self.splitPath(name) 2191 dname, fname = self.splitPath(name)
2232 2192
2233 # find the root of the repo 2193 # find the root of the repo
2234 repodir = dname 2194 repodir = self.findRepoRoot(dname)
2235 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2195 if not repodir:
2236 repodir = os.path.dirname(repodir) 2196 return False, False
2237 if os.path.splitdrive(repodir)[1] == os.sep:
2238 return False, False
2239 2197
2240 dlg = GitBranchDialog( 2198 dlg = GitBranchDialog(
2241 self.gitGetBranchesList(repodir, allBranches=True), 2199 self.gitGetBranchesList(repodir, allBranches=True),
2242 revision, 2200 revision,
2243 branchName, 2201 branchName,
2333 from .GitBranchPushDialog import GitBranchPushDialog 2291 from .GitBranchPushDialog import GitBranchPushDialog
2334 2292
2335 dname, fname = self.splitPath(name) 2293 dname, fname = self.splitPath(name)
2336 2294
2337 # find the root of the repo 2295 # find the root of the repo
2338 repodir = dname 2296 repodir = self.findRepoRoot(dname)
2339 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2297 if not repodir:
2340 repodir = os.path.dirname(repodir) 2298 return
2341 if os.path.splitdrive(repodir)[1] == os.sep:
2342 return
2343 2299
2344 dlg = GitBranchPushDialog( 2300 dlg = GitBranchPushDialog(
2345 self.gitGetBranchesList(repodir), 2301 self.gitGetBranchesList(repodir),
2346 self.gitGetRemotesList(repodir), 2302 self.gitGetRemotesList(repodir),
2347 delete=True, 2303 delete=True,
2365 @param name file/directory name (string) 2321 @param name file/directory name (string)
2366 """ 2322 """
2367 dname, fname = self.splitPath(name) 2323 dname, fname = self.splitPath(name)
2368 2324
2369 # find the root of the repo 2325 # find the root of the repo
2370 repodir = dname 2326 repodir = self.findRepoRoot(dname)
2371 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2327 if not repodir:
2372 repodir = os.path.dirname(repodir) 2328 return
2373 if os.path.splitdrive(repodir)[1] == os.sep:
2374 return
2375 2329
2376 branchName = self.gitGetCurrentBranch(repodir) 2330 branchName = self.gitGetCurrentBranch(repodir)
2377 EricMessageBox.information( 2331 EricMessageBox.information(
2378 None, 2332 None,
2379 self.tr("Current Branch"), 2333 self.tr("Current Branch"),
2391 @param projectDir name of the project directory (string) 2345 @param projectDir name of the project directory (string)
2392 """ 2346 """
2393 from .GitBundleDialog import GitBundleDialog 2347 from .GitBundleDialog import GitBundleDialog
2394 2348
2395 # find the root of the repo 2349 # find the root of the repo
2396 repodir = projectDir 2350 repodir = self.findRepoRoot(projectDir)
2397 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2351 if not repodir:
2398 repodir = os.path.dirname(repodir) 2352 return
2399 if os.path.splitdrive(repodir)[1] == os.sep:
2400 return
2401 2353
2402 dlg = GitBundleDialog( 2354 dlg = GitBundleDialog(
2403 self.gitGetTagsList(repodir), self.gitGetBranchesList(repodir) 2355 self.gitGetTagsList(repodir), self.gitGetBranchesList(repodir)
2404 ) 2356 )
2405 if dlg.exec() == QDialog.DialogCode.Accepted: 2357 if dlg.exec() == QDialog.DialogCode.Accepted:
2453 Public method to verify a bundle file. 2405 Public method to verify a bundle file.
2454 2406
2455 @param projectDir name of the project directory (string) 2407 @param projectDir name of the project directory (string)
2456 """ 2408 """
2457 # find the root of the repo 2409 # find the root of the repo
2458 repodir = projectDir 2410 repodir = self.findRepoRoot(projectDir)
2459 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2411 if not repodir:
2460 repodir = os.path.dirname(repodir) 2412 return
2461 if os.path.splitdrive(repodir)[1] == os.sep:
2462 return
2463 2413
2464 fname = EricFileDialog.getOpenFileName( 2414 fname = EricFileDialog.getOpenFileName(
2465 None, 2415 None,
2466 self.tr("Verify Bundle"), 2416 self.tr("Verify Bundle"),
2467 self.__lastBundlePath or repodir, 2417 self.__lastBundlePath or repodir,
2484 Public method to list the heads contained in a bundle file. 2434 Public method to list the heads contained in a bundle file.
2485 2435
2486 @param projectDir name of the project directory (string) 2436 @param projectDir name of the project directory (string)
2487 """ 2437 """
2488 # find the root of the repo 2438 # find the root of the repo
2489 repodir = projectDir 2439 repodir = self.findRepoRoot(projectDir)
2490 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2440 if not repodir:
2491 repodir = os.path.dirname(repodir) 2441 return
2492 if os.path.splitdrive(repodir)[1] == os.sep:
2493 return
2494 2442
2495 fname = EricFileDialog.getOpenFileName( 2443 fname = EricFileDialog.getOpenFileName(
2496 None, 2444 None,
2497 self.tr("List Bundle Heads"), 2445 self.tr("List Bundle Heads"),
2498 self.__lastBundlePath or repodir, 2446 self.__lastBundlePath or repodir,
2552 @param projectDir name of the project directory (string) 2500 @param projectDir name of the project directory (string)
2553 """ 2501 """
2554 from .GitApplyBundleDataDialog import GitApplyBundleDataDialog 2502 from .GitApplyBundleDataDialog import GitApplyBundleDataDialog
2555 2503
2556 # find the root of the repo 2504 # find the root of the repo
2557 repodir = projectDir 2505 repodir = self.findRepoRoot(projectDir)
2558 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2506 if not repodir:
2559 repodir = os.path.dirname(repodir) 2507 return
2560 if os.path.splitdrive(repodir)[1] == os.sep:
2561 return
2562 2508
2563 fname = EricFileDialog.getOpenFileName( 2509 fname = EricFileDialog.getOpenFileName(
2564 None, 2510 None,
2565 self.tr("Apply Bundle"), 2511 self.tr("Apply Bundle"),
2566 self.__lastBundlePath or repodir, 2512 self.__lastBundlePath or repodir,
2600 or delete (boolean) 2546 or delete (boolean)
2601 """ 2547 """
2602 from .GitApplyBundleDataDialog import GitApplyBundleDataDialog 2548 from .GitApplyBundleDataDialog import GitApplyBundleDataDialog
2603 2549
2604 # find the root of the repo 2550 # find the root of the repo
2605 repodir = projectDir 2551 repodir = self.findRepoRoot(projectDir)
2606 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2552 if not repodir:
2607 repodir = os.path.dirname(repodir) 2553 return False
2608 if os.path.splitdrive(repodir)[1] == os.sep:
2609 return False
2610 2554
2611 res = False 2555 res = False
2612 fname = EricFileDialog.getOpenFileName( 2556 fname = EricFileDialog.getOpenFileName(
2613 None, 2557 None,
2614 self.tr("Apply Bundle"), 2558 self.tr("Apply Bundle"),
2670 raise ValueError( 2614 raise ValueError(
2671 self.tr("Bisect subcommand ({0}) invalid.").format(subcommand) 2615 self.tr("Bisect subcommand ({0}) invalid.").format(subcommand)
2672 ) 2616 )
2673 2617
2674 # find the root of the repo 2618 # find the root of the repo
2675 repodir = projectDir 2619 repodir = self.findRepoRoot(projectDir)
2676 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2620 if not repodir:
2677 repodir = os.path.dirname(repodir) 2621 return False
2678 if os.path.splitdrive(repodir)[1] == os.sep:
2679 return False
2680 2622
2681 res = False 2623 res = False
2682 rev = "" 2624 rev = ""
2683 if subcommand in ("good", "bad", "skip", "reset"): 2625 if subcommand in ("good", "bad", "skip", "reset"):
2684 showBranches = subcommand == "reset" 2626 showBranches = subcommand == "reset"
2741 Public method used to create a bisect replay file for the project. 2683 Public method used to create a bisect replay file for the project.
2742 2684
2743 @param projectDir name of the project directory (string) 2685 @param projectDir name of the project directory (string)
2744 """ 2686 """
2745 # find the root of the repo 2687 # find the root of the repo
2746 repodir = projectDir 2688 repodir = self.findRepoRoot(projectDir)
2747 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2689 if not repodir:
2748 repodir = os.path.dirname(repodir) 2690 return
2749 if os.path.splitdrive(repodir)[1] == os.sep:
2750 return
2751 2691
2752 args = self.initCommand("bisect") 2692 args = self.initCommand("bisect")
2753 args.append("log") 2693 args.append("log")
2754 2694
2755 output = "" 2695 output = ""
2826 Public method used to edit a bisect replay file. 2766 Public method used to edit a bisect replay file.
2827 2767
2828 @param projectDir name of the project directory (string) 2768 @param projectDir name of the project directory (string)
2829 """ 2769 """
2830 # find the root of the repo 2770 # find the root of the repo
2831 repodir = projectDir 2771 repodir = self.findRepoRoot(projectDir)
2832 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2772 if not repodir:
2833 repodir = os.path.dirname(repodir) 2773 return
2834 if os.path.splitdrive(repodir)[1] == os.sep:
2835 return
2836 2774
2837 fname = EricFileDialog.getOpenFileName( 2775 fname = EricFileDialog.getOpenFileName(
2838 None, 2776 None,
2839 self.tr("Edit Bisect Replay File"), 2777 self.tr("Edit Bisect Replay File"),
2840 self.__lastReplayPath or repodir, 2778 self.__lastReplayPath or repodir,
2853 @param projectDir name of the project directory (string) 2791 @param projectDir name of the project directory (string)
2854 @return flag indicating, that the update contained an add 2792 @return flag indicating, that the update contained an add
2855 or delete (boolean) 2793 or delete (boolean)
2856 """ 2794 """
2857 # find the root of the repo 2795 # find the root of the repo
2858 repodir = projectDir 2796 repodir = self.findRepoRoot(projectDir)
2859 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2797 if not repodir:
2860 repodir = os.path.dirname(repodir) 2798 return False
2861 if os.path.splitdrive(repodir)[1] == os.sep:
2862 return False
2863 2799
2864 res = False 2800 res = False
2865 fname = EricFileDialog.getOpenFileName( 2801 fname = EricFileDialog.getOpenFileName(
2866 None, 2802 None,
2867 self.tr("Bisect Replay"), 2803 self.tr("Bisect Replay"),
3028 2964
3029 @param projectDir name of the project directory (string) 2965 @param projectDir name of the project directory (string)
3030 @param remoteName name of the remote repository (string) 2966 @param remoteName name of the remote repository (string)
3031 """ 2967 """
3032 # find the root of the repo 2968 # find the root of the repo
3033 repodir = projectDir 2969 repodir = self.findRepoRoot(projectDir)
3034 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 2970 if not repodir:
3035 repodir = os.path.dirname(repodir) 2971 return
3036 if os.path.splitdrive(repodir)[1] == os.sep:
3037 return
3038 2972
3039 args = self.initCommand("remote") 2973 args = self.initCommand("remote")
3040 args.append("show") 2974 args.append("show")
3041 args.append(remoteName) 2975 args.append(remoteName)
3042 2976
3066 @param projectDir name of the project directory (string) 3000 @param projectDir name of the project directory (string)
3067 """ 3001 """
3068 from .GitAddRemoteDialog import GitAddRemoteDialog 3002 from .GitAddRemoteDialog import GitAddRemoteDialog
3069 3003
3070 # find the root of the repo 3004 # find the root of the repo
3071 repodir = projectDir 3005 repodir = self.findRepoRoot(projectDir)
3072 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3006 if not repodir:
3073 repodir = os.path.dirname(repodir) 3007 return
3074 if os.path.splitdrive(repodir)[1] == os.sep:
3075 return
3076 3008
3077 dlg = GitAddRemoteDialog() 3009 dlg = GitAddRemoteDialog()
3078 if dlg.exec() == QDialog.DialogCode.Accepted: 3010 if dlg.exec() == QDialog.DialogCode.Accepted:
3079 name, url = dlg.getData() 3011 name, url = dlg.getData()
3080 args = self.initCommand("remote") 3012 args = self.initCommand("remote")
3090 3022
3091 @param projectDir name of the project directory (string) 3023 @param projectDir name of the project directory (string)
3092 @param remoteName name of the remote repository (string) 3024 @param remoteName name of the remote repository (string)
3093 """ 3025 """
3094 # find the root of the repo 3026 # find the root of the repo
3095 repodir = projectDir 3027 repodir = self.findRepoRoot(projectDir)
3096 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3028 if not repodir:
3097 repodir = os.path.dirname(repodir) 3029 return
3098 if os.path.splitdrive(repodir)[1] == os.sep:
3099 return
3100 3030
3101 newName, ok = QInputDialog.getText( 3031 newName, ok = QInputDialog.getText(
3102 None, 3032 None,
3103 self.tr("Rename Remote Repository"), 3033 self.tr("Rename Remote Repository"),
3104 self.tr("Enter new name for remote repository:"), 3034 self.tr("Enter new name for remote repository:"),
3124 @type str 3054 @type str
3125 """ 3055 """
3126 from .GitChangeRemoteUrlDialog import GitChangeRemoteUrlDialog 3056 from .GitChangeRemoteUrlDialog import GitChangeRemoteUrlDialog
3127 3057
3128 # find the root of the repo 3058 # find the root of the repo
3129 repodir = projectDir 3059 repodir = self.findRepoRoot(projectDir)
3130 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3060 if not repodir:
3131 repodir = os.path.dirname(repodir) 3061 return
3132 if os.path.splitdrive(repodir)[1] == os.sep:
3133 return
3134 3062
3135 if not remoteUrl: 3063 if not remoteUrl:
3136 remoteUrl = self.gitGetRemoteUrl(repodir, remoteName) 3064 remoteUrl = self.gitGetRemoteUrl(repodir, remoteName)
3137 3065
3138 dlg = GitChangeRemoteUrlDialog(remoteName, remoteUrl) 3066 dlg = GitChangeRemoteUrlDialog(remoteName, remoteUrl)
3160 @type str 3088 @type str
3161 """ 3089 """
3162 from .GitRemoteCredentialsDialog import GitRemoteCredentialsDialog 3090 from .GitRemoteCredentialsDialog import GitRemoteCredentialsDialog
3163 3091
3164 # find the root of the repo 3092 # find the root of the repo
3165 repodir = projectDir 3093 repodir = self.findRepoRoot(projectDir)
3166 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3094 if not repodir:
3167 repodir = os.path.dirname(repodir) 3095 return
3168 if os.path.splitdrive(repodir)[1] == os.sep:
3169 return
3170 3096
3171 if not remoteUrl: 3097 if not remoteUrl:
3172 remoteUrl = self.gitGetRemoteUrl(repodir, remoteName) 3098 remoteUrl = self.gitGetRemoteUrl(repodir, remoteName)
3173 3099
3174 dlg = GitRemoteCredentialsDialog(remoteName, remoteUrl) 3100 dlg = GitRemoteCredentialsDialog(remoteName, remoteUrl)
3190 3116
3191 @param projectDir name of the project directory (string) 3117 @param projectDir name of the project directory (string)
3192 @param remoteName name of the remote repository (string) 3118 @param remoteName name of the remote repository (string)
3193 """ 3119 """
3194 # find the root of the repo 3120 # find the root of the repo
3195 repodir = projectDir 3121 repodir = self.findRepoRoot(projectDir)
3196 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3122 if not repodir:
3197 repodir = os.path.dirname(repodir) 3123 return
3198 if os.path.splitdrive(repodir)[1] == os.sep:
3199 return
3200 3124
3201 args = self.initCommand("remote") 3125 args = self.initCommand("remote")
3202 args.append("remove") 3126 args.append("remove")
3203 args.append(remoteName) 3127 args.append(remoteName)
3204 3128
3210 3134
3211 @param projectDir name of the project directory (string) 3135 @param projectDir name of the project directory (string)
3212 @param remoteName name of the remote repository (string) 3136 @param remoteName name of the remote repository (string)
3213 """ 3137 """
3214 # find the root of the repo 3138 # find the root of the repo
3215 repodir = projectDir 3139 repodir = self.findRepoRoot(projectDir)
3216 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3140 if not repodir:
3217 repodir = os.path.dirname(repodir) 3141 return
3218 if os.path.splitdrive(repodir)[1] == os.sep:
3219 return
3220 3142
3221 args = self.initCommand("remote") 3143 args = self.initCommand("remote")
3222 args.append("prune") 3144 args.append("prune")
3223 args.append(remoteName) 3145 args.append(remoteName)
3224 3146
3234 3156
3235 @param projectDir name of the project directory (string) 3157 @param projectDir name of the project directory (string)
3236 @param commit commit to start the log at (strings) 3158 @param commit commit to start the log at (strings)
3237 """ 3159 """
3238 # find the root of the repo 3160 # find the root of the repo
3239 repodir = projectDir 3161 repodir = self.findRepoRoot(projectDir)
3240 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3162 if not repodir:
3241 repodir = os.path.dirname(repodir) 3163 return
3242 if os.path.splitdrive(repodir)[1] == os.sep:
3243 return
3244 3164
3245 args = self.initCommand("shortlog") 3165 args = self.initCommand("shortlog")
3246 args.append("-w") 3166 args.append("-w")
3247 args.append(commit) 3167 args.append(commit)
3248 3168
3281 @return flag indicating that the project should be reread (boolean) 3201 @return flag indicating that the project should be reread (boolean)
3282 """ 3202 """
3283 from .GitCherryPickDialog import GitCherryPickDialog 3203 from .GitCherryPickDialog import GitCherryPickDialog
3284 3204
3285 # find the root of the repo 3205 # find the root of the repo
3286 repodir = projectDir 3206 repodir = self.findRepoRoot(projectDir)
3287 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3207 if not repodir:
3288 repodir = os.path.dirname(repodir) 3208 return False
3289 if os.path.splitdrive(repodir)[1] == os.sep:
3290 return False
3291 3209
3292 res = False 3210 res = False
3293 3211
3294 dlg = GitCherryPickDialog(commits) 3212 dlg = GitCherryPickDialog(commits)
3295 if dlg.exec() == QDialog.DialogCode.Accepted: 3213 if dlg.exec() == QDialog.DialogCode.Accepted:
3320 3238
3321 @param projectDir name of the project directory (string) 3239 @param projectDir name of the project directory (string)
3322 @return flag indicating that the project should be reread (boolean) 3240 @return flag indicating that the project should be reread (boolean)
3323 """ 3241 """
3324 # find the root of the repo 3242 # find the root of the repo
3325 repodir = projectDir 3243 repodir = self.findRepoRoot(projectDir)
3326 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3244 if not repodir:
3327 repodir = os.path.dirname(repodir) 3245 return False
3328 if os.path.splitdrive(repodir)[1] == os.sep:
3329 return False
3330 3246
3331 editor = sys.argv[0].replace(".py", "_editor.py") 3247 editor = sys.argv[0].replace(".py", "_editor.py")
3332 env = {"GIT_EDITOR": "{0} {1}".format(Globals.getPythonExecutable(), editor)} 3248 env = {"GIT_EDITOR": "{0} {1}".format(Globals.getPythonExecutable(), editor)}
3333 3249
3334 args = self.initCommand("cherry-pick") 3250 args = self.initCommand("cherry-pick")
3348 3264
3349 @param projectDir name of the project directory (string) 3265 @param projectDir name of the project directory (string)
3350 @return flag indicating that the project should be reread (boolean) 3266 @return flag indicating that the project should be reread (boolean)
3351 """ 3267 """
3352 # find the root of the repo 3268 # find the root of the repo
3353 repodir = projectDir 3269 repodir = self.findRepoRoot(projectDir)
3354 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3270 if not repodir:
3355 repodir = os.path.dirname(repodir) 3271 return False
3356 if os.path.splitdrive(repodir)[1] == os.sep:
3357 return False
3358 3272
3359 args = self.initCommand("cherry-pick") 3273 args = self.initCommand("cherry-pick")
3360 args.append("--quit") 3274 args.append("--quit")
3361 3275
3362 dia = GitDialog(self.tr("Copy Changesets (Quit)"), self) 3276 dia = GitDialog(self.tr("Copy Changesets (Quit)"), self)
3374 3288
3375 @param projectDir name of the project directory (string) 3289 @param projectDir name of the project directory (string)
3376 @return flag indicating that the project should be reread (boolean) 3290 @return flag indicating that the project should be reread (boolean)
3377 """ 3291 """
3378 # find the root of the repo 3292 # find the root of the repo
3379 repodir = projectDir 3293 repodir = self.findRepoRoot(projectDir)
3380 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3294 if not repodir:
3381 repodir = os.path.dirname(repodir) 3295 return False
3382 if os.path.splitdrive(repodir)[1] == os.sep:
3383 return False
3384 3296
3385 args = self.initCommand("cherry-pick") 3297 args = self.initCommand("cherry-pick")
3386 args.append("--abort") 3298 args.append("--abort")
3387 3299
3388 dia = GitDialog(self.tr("Copy Changesets (Cancel)"), self) 3300 dia = GitDialog(self.tr("Copy Changesets (Cancel)"), self)
3403 3315
3404 @param projectDir name of the project directory (string) 3316 @param projectDir name of the project directory (string)
3405 @return list of available stashes (list of string) 3317 @return list of available stashes (list of string)
3406 """ 3318 """
3407 # find the root of the repo 3319 # find the root of the repo
3408 repodir = projectDir 3320 repodir = self.findRepoRoot(projectDir)
3409 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3321 if not repodir:
3410 repodir = os.path.dirname(repodir) 3322 return []
3411 if os.path.splitdrive(repodir)[1] == os.sep:
3412 return []
3413 3323
3414 args = self.initCommand("stash") 3324 args = self.initCommand("stash")
3415 args.append("list") 3325 args.append("list")
3416 args.append("--format=format:%gd") 3326 args.append("--format=format:%gd")
3417 3327
3444 or delete (boolean) 3354 or delete (boolean)
3445 """ 3355 """
3446 from .GitStashDataDialog import GitStashDataDialog 3356 from .GitStashDataDialog import GitStashDataDialog
3447 3357
3448 # find the root of the repo 3358 # find the root of the repo
3449 repodir = projectDir 3359 repodir = self.findRepoRoot(projectDir)
3450 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3360 if not repodir:
3451 repodir = os.path.dirname(repodir) 3361 return False
3452 if os.path.splitdrive(repodir)[1] == os.sep:
3453 return False
3454 3362
3455 res = False 3363 res = False
3456 dlg = GitStashDataDialog() 3364 dlg = GitStashDataDialog()
3457 if dlg.exec() == QDialog.DialogCode.Accepted: 3365 if dlg.exec() == QDialog.DialogCode.Accepted:
3458 message, keepIndex, untracked = dlg.getData() 3366 message, keepIndex, untracked = dlg.getData()
3497 @param stashName name of a stash (string) 3405 @param stashName name of a stash (string)
3498 """ 3406 """
3499 from .GitDiffDialog import GitDiffDialog 3407 from .GitDiffDialog import GitDiffDialog
3500 3408
3501 # find the root of the repo 3409 # find the root of the repo
3502 repodir = projectDir 3410 repodir = self.findRepoRoot(projectDir)
3503 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3411 if not repodir:
3504 repodir = os.path.dirname(repodir) 3412 return
3505 if os.path.splitdrive(repodir)[1] == os.sep:
3506 return
3507 3413
3508 if not stashName: 3414 if not stashName:
3509 availableStashes = self.__gitGetStashesList(repodir) 3415 availableStashes = self.__gitGetStashesList(repodir)
3510 stashName, ok = QInputDialog.getItem( 3416 stashName, ok = QInputDialog.getItem(
3511 None, 3417 None,
3532 @param stashName name of a stash (string) 3438 @param stashName name of a stash (string)
3533 @return flag indicating, that the restore contained an add 3439 @return flag indicating, that the restore contained an add
3534 or delete (boolean) 3440 or delete (boolean)
3535 """ 3441 """
3536 # find the root of the repo 3442 # find the root of the repo
3537 repodir = projectDir 3443 repodir = self.findRepoRoot(projectDir)
3538 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3444 if not repodir:
3539 repodir = os.path.dirname(repodir) 3445 return False
3540 if os.path.splitdrive(repodir)[1] == os.sep:
3541 return False
3542 3446
3543 if not stashName: 3447 if not stashName:
3544 availableStashes = self.__gitGetStashesList(repodir) 3448 availableStashes = self.__gitGetStashesList(repodir)
3545 stashName, ok = QInputDialog.getItem( 3449 stashName, ok = QInputDialog.getItem(
3546 None, 3450 None,
3574 @param stashName name of a stash (string) 3478 @param stashName name of a stash (string)
3575 @return flag indicating, that the restore contained an add 3479 @return flag indicating, that the restore contained an add
3576 or delete (boolean) 3480 or delete (boolean)
3577 """ 3481 """
3578 # find the root of the repo 3482 # find the root of the repo
3579 repodir = projectDir 3483 repodir = self.findRepoRoot(projectDir)
3580 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3484 if not repodir:
3581 repodir = os.path.dirname(repodir) 3485 return False
3582 if os.path.splitdrive(repodir)[1] == os.sep:
3583 return False
3584 3486
3585 if not stashName: 3487 if not stashName:
3586 availableStashes = self.__gitGetStashesList(repodir) 3488 availableStashes = self.__gitGetStashesList(repodir)
3587 stashName, ok = QInputDialog.getItem( 3489 stashName, ok = QInputDialog.getItem(
3588 None, 3490 None,
3616 @param stashName name of a stash (string) 3518 @param stashName name of a stash (string)
3617 @return flag indicating, that the restore contained an add 3519 @return flag indicating, that the restore contained an add
3618 or delete (boolean) 3520 or delete (boolean)
3619 """ 3521 """
3620 # find the root of the repo 3522 # find the root of the repo
3621 repodir = projectDir 3523 repodir = self.findRepoRoot(projectDir)
3622 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3524 if not repodir:
3623 repodir = os.path.dirname(repodir) 3525 return False
3624 if os.path.splitdrive(repodir)[1] == os.sep:
3625 return False
3626 3526
3627 branchName, ok = QInputDialog.getText( 3527 branchName, ok = QInputDialog.getText(
3628 None, 3528 None,
3629 self.tr("Create Branch"), 3529 self.tr("Create Branch"),
3630 self.tr("Enter a branch name to restore a stash to:"), 3530 self.tr("Enter a branch name to restore a stash to:"),
3667 @param projectDir name of the project directory (string) 3567 @param projectDir name of the project directory (string)
3668 @param stashName name of a stash (string) 3568 @param stashName name of a stash (string)
3669 @return flag indicating a successful deletion (boolean) 3569 @return flag indicating a successful deletion (boolean)
3670 """ 3570 """
3671 # find the root of the repo 3571 # find the root of the repo
3672 repodir = projectDir 3572 repodir = self.findRepoRoot(projectDir)
3673 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3573 if not repodir:
3674 repodir = os.path.dirname(repodir) 3574 return False
3675 if os.path.splitdrive(repodir)[1] == os.sep:
3676 return False
3677 3575
3678 if not stashName: 3576 if not stashName:
3679 availableStashes = self.__gitGetStashesList(repodir) 3577 availableStashes = self.__gitGetStashesList(repodir)
3680 stashName, ok = QInputDialog.getItem( 3578 stashName, ok = QInputDialog.getItem(
3681 None, 3579 None,
3713 3611
3714 @param projectDir name of the project directory (string) 3612 @param projectDir name of the project directory (string)
3715 @return flag indicating a successful deletion (boolean) 3613 @return flag indicating a successful deletion (boolean)
3716 """ 3614 """
3717 # find the root of the repo 3615 # find the root of the repo
3718 repodir = projectDir 3616 repodir = self.findRepoRoot(projectDir)
3719 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3617 if not repodir:
3720 repodir = os.path.dirname(repodir) 3618 return False
3721 if os.path.splitdrive(repodir)[1] == os.sep:
3722 return False
3723 3619
3724 res = EricMessageBox.yesNo( 3620 res = EricMessageBox.yesNo(
3725 None, 3621 None,
3726 self.tr("Delete All Stashes"), 3622 self.tr("Delete All Stashes"),
3727 self.tr("""Do you really want to delete all stashes?"""), 3623 self.tr("""Do you really want to delete all stashes?"""),
3741 Public method used to edit the repository configuration file. 3637 Public method used to edit the repository configuration file.
3742 3638
3743 @param projectDir name of the project directory (string) 3639 @param projectDir name of the project directory (string)
3744 """ 3640 """
3745 # find the root of the repo 3641 # find the root of the repo
3746 repodir = projectDir 3642 repodir = self.findRepoRoot(projectDir)
3747 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3643 if not repodir:
3748 repodir = os.path.dirname(repodir) 3644 return
3749 if os.path.splitdrive(repodir)[1] == os.sep: 3645
3750 return 3646 cfgFile = os.path.join(repodir, self.adminDirOrFile, "config")
3751
3752 cfgFile = os.path.join(repodir, self.adminDir, "config")
3753 if not os.path.exists(cfgFile): 3647 if not os.path.exists(cfgFile):
3754 # create an empty one 3648 # create an empty one
3755 with contextlib.suppress(OSError), open(cfgFile, "w"): 3649 with contextlib.suppress(OSError), open(cfgFile, "w"):
3756 pass 3650 pass
3757 self.repoEditor = MiniEditor(cfgFile, "Properties") 3651 self.repoEditor = MiniEditor(cfgFile, "Properties")
3783 Public method to show the combined configuration. 3677 Public method to show the combined configuration.
3784 3678
3785 @param projectDir name of the project directory (string) 3679 @param projectDir name of the project directory (string)
3786 """ 3680 """
3787 # find the root of the repo 3681 # find the root of the repo
3788 repodir = projectDir 3682 repodir = self.findRepoRoot(projectDir)
3789 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3683 if not repodir:
3790 repodir = os.path.dirname(repodir) 3684 return
3791 if os.path.splitdrive(repodir)[1] == os.sep:
3792 return
3793 3685
3794 args = self.initCommand("config") 3686 args = self.initCommand("config")
3795 args.append("--list") 3687 args.append("--list")
3796 3688
3797 dia = GitDialog(self.tr("Showing the combined configuration settings"), self) 3689 dia = GitDialog(self.tr("Showing the combined configuration settings"), self)
3805 of the database. 3697 of the database.
3806 3698
3807 @param projectDir name of the project directory (string) 3699 @param projectDir name of the project directory (string)
3808 """ 3700 """
3809 # find the root of the repo 3701 # find the root of the repo
3810 repodir = projectDir 3702 repodir = self.findRepoRoot(projectDir)
3811 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3703 if not repodir:
3812 repodir = os.path.dirname(repodir) 3704 return
3813 if os.path.splitdrive(repodir)[1] == os.sep:
3814 return
3815 3705
3816 args = self.initCommand("fsck") 3706 args = self.initCommand("fsck")
3817 args.append("--strict") 3707 args.append("--strict")
3818 args.append("--full") 3708 args.append("--full")
3819 args.append("--cache") 3709 args.append("--cache")
3828 Public method to cleanup and optimize the local repository. 3718 Public method to cleanup and optimize the local repository.
3829 3719
3830 @param projectDir name of the project directory (string) 3720 @param projectDir name of the project directory (string)
3831 """ 3721 """
3832 # find the root of the repo 3722 # find the root of the repo
3833 repodir = projectDir 3723 repodir = self.findRepoRoot(projectDir)
3834 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3724 if not repodir:
3835 repodir = os.path.dirname(repodir) 3725 return
3836 if os.path.splitdrive(repodir)[1] == os.sep:
3837 return
3838 3726
3839 args = self.initCommand("gc") 3727 args = self.initCommand("gc")
3840 args.append("--prune") 3728 args.append("--prune")
3841 if self.__plugin.getPreferences("AggressiveGC"): 3729 if self.__plugin.getPreferences("AggressiveGC"):
3842 args.append("--aggressive") 3730 args.append("--aggressive")
3851 Public method to show some statistics of the local repository. 3739 Public method to show some statistics of the local repository.
3852 3740
3853 @param projectDir name of the project directory (string) 3741 @param projectDir name of the project directory (string)
3854 """ 3742 """
3855 # find the root of the repo 3743 # find the root of the repo
3856 repodir = projectDir 3744 repodir = self.findRepoRoot(projectDir)
3857 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3745 if not repodir:
3858 repodir = os.path.dirname(repodir) 3746 return
3859 if os.path.splitdrive(repodir)[1] == os.sep:
3860 return
3861 3747
3862 args = self.initCommand("count-objects") 3748 args = self.initCommand("count-objects")
3863 args.append("-v") 3749 args.append("-v")
3864 3750
3865 output = "" 3751 output = ""
3975 @param projectDir name of the project directory (string) 3861 @param projectDir name of the project directory (string)
3976 """ 3862 """
3977 from .GitArchiveDataDialog import GitArchiveDataDialog 3863 from .GitArchiveDataDialog import GitArchiveDataDialog
3978 3864
3979 # find the root of the repo 3865 # find the root of the repo
3980 repodir = projectDir 3866 repodir = self.findRepoRoot(projectDir)
3981 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3867 if not repodir:
3982 repodir = os.path.dirname(repodir) 3868 return
3983 if os.path.splitdrive(repodir)[1] == os.sep:
3984 return
3985 3869
3986 dlg = GitArchiveDataDialog( 3870 dlg = GitArchiveDataDialog(
3987 self.gitGetTagsList(repodir), 3871 self.gitGetTagsList(repodir),
3988 self.gitGetBranchesList(repodir, withMaster=True), 3872 self.gitGetBranchesList(repodir, withMaster=True),
3989 self.gitGetArchiveFormats(repodir), 3873 self.gitGetArchiveFormats(repodir),
4017 @type str 3901 @type str
4018 """ 3902 """
4019 from .GitSubmoduleAddDialog import GitSubmoduleAddDialog 3903 from .GitSubmoduleAddDialog import GitSubmoduleAddDialog
4020 3904
4021 # find the root of the repo 3905 # find the root of the repo
4022 repodir = projectDir 3906 repodir = self.findRepoRoot(projectDir)
4023 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3907 if not repodir:
4024 repodir = os.path.dirname(repodir) 3908 return
4025 if os.path.splitdrive(repodir)[1] == os.sep:
4026 return
4027 3909
4028 dlg = GitSubmoduleAddDialog(self, repodir) 3910 dlg = GitSubmoduleAddDialog(self, repodir)
4029 if dlg.exec() == QDialog.DialogCode.Accepted: 3911 if dlg.exec() == QDialog.DialogCode.Accepted:
4030 repo, branch, name, path, force = dlg.getData() 3912 repo, branch, name, path, force = dlg.getData()
4031 args = self.initCommand("submodule") 3913 args = self.initCommand("submodule")
4095 @type str 3977 @type str
4096 """ 3978 """
4097 from .GitSubmodulesListDialog import GitSubmodulesListDialog 3979 from .GitSubmodulesListDialog import GitSubmodulesListDialog
4098 3980
4099 # find the root of the repo 3981 # find the root of the repo
4100 repodir = projectDir 3982 repodir = self.findRepoRoot(projectDir)
4101 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 3983 if not repodir:
4102 repodir = os.path.dirname(repodir) 3984 return
4103 if os.path.splitdrive(repodir)[1] == os.sep:
4104 return
4105 3985
4106 submodulesList = self.__gitSubmodulesList(repodir) 3986 submodulesList = self.__gitSubmodulesList(repodir)
4107 if submodulesList: 3987 if submodulesList:
4108 dlg = GitSubmodulesListDialog(submodulesList) 3988 dlg = GitSubmodulesListDialog(submodulesList)
4109 dlg.exec() 3989 dlg.exec()
4166 4046
4167 @param projectDir name of the project directory 4047 @param projectDir name of the project directory
4168 @type str 4048 @type str
4169 """ 4049 """
4170 # find the root of the repo 4050 # find the root of the repo
4171 repodir = projectDir 4051 repodir = self.findRepoRoot(projectDir)
4172 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 4052 if not repodir:
4173 repodir = os.path.dirname(repodir) 4053 return
4174 if os.path.splitdrive(repodir)[1] == os.sep:
4175 return
4176 4054
4177 submodulePaths, ok = self.__selectSubmodulePaths(repodir) 4055 submodulePaths, ok = self.__selectSubmodulePaths(repodir)
4178 if ok: 4056 if ok:
4179 args = self.initCommand("submodule") 4057 args = self.initCommand("submodule")
4180 args.append("init") 4058 args.append("init")
4193 @type str 4071 @type str
4194 """ 4072 """
4195 from .GitSubmodulesDeinitDialog import GitSubmodulesDeinitDialog 4073 from .GitSubmodulesDeinitDialog import GitSubmodulesDeinitDialog
4196 4074
4197 # find the root of the repo 4075 # find the root of the repo
4198 repodir = projectDir 4076 repodir = self.findRepoRoot(projectDir)
4199 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 4077 if not repodir:
4200 repodir = os.path.dirname(repodir) 4078 return
4201 if os.path.splitdrive(repodir)[1] == os.sep:
4202 return
4203 4079
4204 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)] 4080 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)]
4205 4081
4206 dlg = GitSubmodulesDeinitDialog(paths) 4082 dlg = GitSubmodulesDeinitDialog(paths)
4207 if dlg.exec() == QDialog.DialogCode.Accepted: 4083 if dlg.exec() == QDialog.DialogCode.Accepted:
4230 @type bool 4106 @type bool
4231 @param remote flag indicating a fetch and update operation 4107 @param remote flag indicating a fetch and update operation
4232 @type bool 4108 @type bool
4233 """ 4109 """
4234 # find the root of the repo 4110 # find the root of the repo
4235 repodir = projectDir 4111 repodir = self.findRepoRoot(projectDir)
4236 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 4112 if not repodir:
4237 repodir = os.path.dirname(repodir) 4113 return
4238 if os.path.splitdrive(repodir)[1] == os.sep:
4239 return
4240 4114
4241 submodulePaths, ok = self.__selectSubmodulePaths(repodir) 4115 submodulePaths, ok = self.__selectSubmodulePaths(repodir)
4242 if ok: 4116 if ok:
4243 args = self.initCommand("submodule") 4117 args = self.initCommand("submodule")
4244 args.append("update") 4118 args.append("update")
4262 @type str 4136 @type str
4263 """ 4137 """
4264 from .GitSubmodulesUpdateOptionsDialog import GitSubmodulesUpdateOptionsDialog 4138 from .GitSubmodulesUpdateOptionsDialog import GitSubmodulesUpdateOptionsDialog
4265 4139
4266 # find the root of the repo 4140 # find the root of the repo
4267 repodir = projectDir 4141 repodir = self.findRepoRoot(projectDir)
4268 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 4142 if not repodir:
4269 repodir = os.path.dirname(repodir) 4143 return
4270 if os.path.splitdrive(repodir)[1] == os.sep:
4271 return
4272 4144
4273 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)] 4145 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)]
4274 4146
4275 dlg = GitSubmodulesUpdateOptionsDialog(paths) 4147 dlg = GitSubmodulesUpdateOptionsDialog(paths)
4276 if dlg.exec() == QDialog.DialogCode.Accepted: 4148 if dlg.exec() == QDialog.DialogCode.Accepted:
4302 @type str 4174 @type str
4303 """ 4175 """
4304 from .GitSubmodulesSyncDialog import GitSubmodulesSyncDialog 4176 from .GitSubmodulesSyncDialog import GitSubmodulesSyncDialog
4305 4177
4306 # find the root of the repo 4178 # find the root of the repo
4307 repodir = projectDir 4179 repodir = self.findRepoRoot(projectDir)
4308 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 4180 if not repodir:
4309 repodir = os.path.dirname(repodir) 4181 return
4310 if os.path.splitdrive(repodir)[1] == os.sep:
4311 return
4312 4182
4313 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)] 4183 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)]
4314 4184
4315 dlg = GitSubmodulesSyncDialog(paths) 4185 dlg = GitSubmodulesSyncDialog(paths)
4316 if dlg.exec() == QDialog.DialogCode.Accepted: 4186 if dlg.exec() == QDialog.DialogCode.Accepted:
4349 @type str 4219 @type str
4350 """ 4220 """
4351 from .GitSubmodulesSummaryOptionsDialog import GitSubmodulesSummaryOptionsDialog 4221 from .GitSubmodulesSummaryOptionsDialog import GitSubmodulesSummaryOptionsDialog
4352 4222
4353 # find the root of the repo 4223 # find the root of the repo
4354 repodir = projectDir 4224 repodir = self.findRepoRoot(projectDir)
4355 while not os.path.isdir(os.path.join(repodir, self.adminDir)): 4225 if not repodir:
4356 repodir = os.path.dirname(repodir) 4226 return
4357 if os.path.splitdrive(repodir)[1] == os.sep:
4358 return
4359 4227
4360 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)] 4228 paths = [submodule["path"] for submodule in self.__gitSubmodulesList(repodir)]
4361 4229
4362 dlg = GitSubmodulesSummaryOptionsDialog(paths) 4230 dlg = GitSubmodulesSummaryOptionsDialog(paths)
4363 if dlg.exec() == QDialog.DialogCode.Accepted: 4231 if dlg.exec() == QDialog.DialogCode.Accepted:
4427 @return reference to the monitor thread (QThread) 4295 @return reference to the monitor thread (QThread)
4428 """ 4296 """
4429 from .GitStatusMonitorThread import GitStatusMonitorThread 4297 from .GitStatusMonitorThread import GitStatusMonitorThread
4430 4298
4431 return GitStatusMonitorThread(interval, project, self) 4299 return GitStatusMonitorThread(interval, project, self)
4300
4301 ###########################################################################
4302 ## Method to find the repository root below
4303 ###########################################################################
4304
4305 def findRepoRoot(self, start):
4306 """
4307 Public method to find the repository root directory given a start.
4308
4309 @param start start directory name
4310 @type str
4311 @return directory name of the repository root or None, if it was not found
4312 @rtype str or None
4313 """
4314 repoRoot = start
4315 while not os.path.exists(os.path.join(repoRoot, self.adminDirOrFile)):
4316 repoRoot = os.path.dirname(repoRoot)
4317 if os.path.splitdrive(repoRoot)[1] == os.sep:
4318 repoRoot = None
4319 return repoRoot

eric ide

mercurial