Get Remote URL
This commit is contained in:
155
main2.pb
155
main2.pb
@@ -235,6 +235,7 @@ Structure mainStruct
|
|||||||
;Helpers Info
|
;Helpers Info
|
||||||
gitVersion$
|
gitVersion$
|
||||||
IsRepository.b
|
IsRepository.b
|
||||||
|
hasRemoteUrl.b
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Global main.mainStruct
|
Global main.mainStruct
|
||||||
@@ -832,6 +833,13 @@ Procedure.i GetGitVersion()
|
|||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.i DoGitFetch(remote.s="origin",branch.s="main")
|
||||||
|
If Git("fetch "+remote+" "+branch) = 0
|
||||||
|
ProcedureReturn #True
|
||||||
|
EndIf
|
||||||
|
ProcedureReturn #False
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
Procedure.s GetStatusDescription(status.s)
|
Procedure.s GetStatusDescription(status.s)
|
||||||
Select status
|
Select status
|
||||||
Case " "
|
Case " "
|
||||||
@@ -884,98 +892,69 @@ Procedure.s GetStatusDescription(status.s)
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure GetGitStatusPocelaine()
|
Procedure GetGitStatusPocelaine()
|
||||||
If Git("status --porcelain --ignored") = 0
|
If Git("status --porcelain -z --ignored") = 0
|
||||||
ProcedureReturn #True
|
ProcedureReturn #True
|
||||||
EndIf
|
EndIf
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
; Parse la sortie de: git status --porcelain -z
|
||||||
Procedure ParseStatusPorcelaine(output$)
|
Procedure ParseStatusPorcelaine(output$)
|
||||||
; Ne PAS vider la liste ici : on veut pouvoir mettre à jour des entrées existantes
|
Protected delim$ = Chr(0)
|
||||||
; ClearList(main\Files()) ; <-- laissé intentionnellement commenté
|
Protected total.l = CountString(output$, delim$) + 1
|
||||||
|
Protected i.l = 1, tok$, sp.l
|
||||||
|
Protected xy$, path1$, path2$, name$, found.b
|
||||||
|
|
||||||
; Diviser en lignes
|
; Ne PAS vider main\Files(): on met à jour si existe déjà
|
||||||
Dim lines.s(0)
|
|
||||||
Protected lineCount.l = 0
|
For i=1 To total
|
||||||
Protected currentPos.l = 1
|
tok$ = StringField(output$, i, delim$) : i + 1
|
||||||
Protected i.l,lineIndex,startPos
|
If tok$ = "" : Continue : EndIf
|
||||||
; Compter les lignes
|
; tok$ ressemble à: "XY[...score...]␠<path1>"
|
||||||
For i = 1 To Len(output$)
|
sp = FindString(tok$, " ", 3)
|
||||||
If Mid(output$, i, 1) = #LF$ Or Mid(output$, i, 1) = #CR$
|
Debug "sp="+Str(sp)
|
||||||
lineCount + 1
|
If sp = 0 Or Len(tok$) < 3 : Continue : EndIf
|
||||||
EndIf
|
xy$ = Left(tok$, 2) ; ex: " M", "R ", " C", "??", "UU", etc.
|
||||||
Next
|
path1$ = Mid(tok$, sp+1,Len(tok$)-(sp+1)) ; 1er chemin
|
||||||
|
|
||||||
; Redimensionner le tableau
|
;TODO check this
|
||||||
If lineCount > 0
|
; Renomme/copie ? (si X ou Y est R/C, le prochain champ NUL = nouveau chemin)
|
||||||
ReDim lines.s(lineCount)
|
If Left(xy$, 1) = "R" Or Right(xy$, 1) = "R" Or Left(xy$, 1) = "C" Or Right(xy$,1) = "C"
|
||||||
|
If i <= total
|
||||||
; Remplir le tableau avec les lignes
|
path2$ = StringField(output$, i, delim$)
|
||||||
lineIndex = 0
|
i + 1
|
||||||
startPos = 1
|
|
||||||
|
|
||||||
For i = 1 To Len(output$)
|
|
||||||
If Mid(output$, i, 1) = #LF$ Or Mid(output$, i, 1) = #CR$
|
|
||||||
If i > startPos
|
|
||||||
lines(lineIndex) = Mid(output$, startPos, i - startPos)
|
|
||||||
lineIndex + 1
|
|
||||||
EndIf
|
|
||||||
startPos = i + 1
|
|
||||||
; Gérer CRLF
|
|
||||||
If Mid(output$, i, 1) = #CR$ And i < Len(output$) And Mid(output$, i + 1, 1) = #LF$
|
|
||||||
i + 1
|
|
||||||
startPos = i + 1
|
|
||||||
EndIf
|
|
||||||
EndIf
|
|
||||||
Next
|
|
||||||
|
|
||||||
; Traiter la dernière ligne si elle n'a pas de retour à la ligne
|
|
||||||
If startPos <= Len(output$)
|
|
||||||
lines(lineIndex) = Mid(output$, startPos)
|
|
||||||
EndIf
|
EndIf
|
||||||
|
If path2$ <> "" : name$ = path2$ : Else : name$ = path1$ : EndIf
|
||||||
|
Else
|
||||||
|
name$ = path1$
|
||||||
EndIf
|
EndIf
|
||||||
Protected line$,status$,name$
|
|
||||||
; Parser chaque ligne
|
|
||||||
For i = 0 To ArraySize(lines())
|
|
||||||
line$ = lines(i)
|
|
||||||
If line$ <> ""
|
|
||||||
; Le format est : XY␠<filename>
|
|
||||||
; X = index status, Y = working tree status
|
|
||||||
If Len(line$) >= 3
|
|
||||||
status$ = Left(line$, 2)
|
|
||||||
name$ = Mid(line$, 4) ; chemin tel que renvoyé par Git
|
|
||||||
name$ = ReplaceString(name$, "\", "/") ; normalisation (par sécurité)
|
|
||||||
|
|
||||||
; ----- MODIF: chercher si l'entrée existe déjà -----
|
; Normalisation des séparateurs
|
||||||
Protected found.b = #False
|
name$ = ReplaceString(name$, "\", "/")
|
||||||
ForEach main\Files()
|
|
||||||
If main\Files()\name = name$
|
|
||||||
found = #True
|
|
||||||
; Mise à jour uniquement
|
|
||||||
main\Files()\status = status$
|
|
||||||
main\Files()\statusDescription = GetStatusDescription(status$)
|
|
||||||
Break
|
|
||||||
EndIf
|
|
||||||
Next
|
|
||||||
|
|
||||||
; Si non trouvée, on l'ajoute
|
; MAJ si déjà présent, sinon ajout
|
||||||
If Not found
|
found = #False
|
||||||
AddElement(main\Files())
|
ForEach main\Files()
|
||||||
main\Files()\name = name$
|
If main\Files()\name = name$
|
||||||
main\Files()\status = status$
|
found = #True
|
||||||
main\Files()\statusDescription = GetStatusDescription(status$)
|
main\Files()\status = xy$
|
||||||
EndIf
|
main\Files()\statusDescription = GetStatusDescription(xy$)
|
||||||
; ----- FIN MODIF -----
|
Break
|
||||||
EndIf
|
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
|
|
||||||
Debug "Récupération des status Git réussie. " + Str(ListSize(main\Files())) + " fichiers (maj/ajout)."
|
If Not found
|
||||||
ProcedureReturn #True
|
AddElement(main\Files())
|
||||||
|
main\Files()\name = name$
|
||||||
|
main\Files()\status = xy$
|
||||||
|
main\Files()\statusDescription = GetStatusDescription(xy$)
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
|
||||||
|
Debug "Récupération des status Git (-z) réussie. " + Str(ListSize(main\Files())) + " fichiers (maj/ajout)."
|
||||||
|
ProcedureReturn #True
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Procedure IsGitRepository()
|
Procedure IsGitRepository()
|
||||||
If Git("status") <> 0
|
If Git("status") <> 0
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
@@ -984,6 +963,14 @@ Procedure IsGitRepository()
|
|||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure GetGitRemoteUrl(name.s="origin")
|
||||||
|
If Git("remote get-url "+name)=0
|
||||||
|
ProcedureReturn #True
|
||||||
|
Else
|
||||||
|
ProcedureReturn #False
|
||||||
|
EndIf
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
; --- Helper interne : scanne un dossier et alimente la liste
|
; --- Helper interne : scanne un dossier et alimente la liste
|
||||||
Procedure _ScanFiles(path$, root$="")
|
Procedure _ScanFiles(path$, root$="")
|
||||||
If root$="":root$=path$:EndIf
|
If root$="":root$=path$:EndIf
|
||||||
@@ -1031,11 +1018,20 @@ Procedure readDirectory()
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure RefreshFiles()
|
Procedure RefreshFiles()
|
||||||
|
DoGitFetch() ;TODO add Branch
|
||||||
ClearGadgetItems(#GID_ListStatus)
|
ClearGadgetItems(#GID_ListStatus)
|
||||||
ClearList(main\Files())
|
ClearList(main\Files())
|
||||||
readDirectory()
|
readDirectory()
|
||||||
If main\IsRepository And GetGitVersion()
|
If main\IsRepository And GetGitVersion()
|
||||||
|
GetGitStatusPocelaine()
|
||||||
ParseStatusPorcelaine(main\gitCall\output)
|
ParseStatusPorcelaine(main\gitCall\output)
|
||||||
|
If GetGitRemoteUrl()
|
||||||
|
SetGadgetText(#GID_EdRemote,SupTrim(main\gitCall\output))
|
||||||
|
main\hasRemoteUrl=#True
|
||||||
|
Else
|
||||||
|
SetGadgetText(#GID_EdRemote,"")
|
||||||
|
main\hasRemoteUrl=#False
|
||||||
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
Protected n.l=n-1
|
Protected n.l=n-1
|
||||||
ForEach main\Files()
|
ForEach main\Files()
|
||||||
@@ -1045,7 +1041,6 @@ Procedure RefreshFiles()
|
|||||||
SetGadgetItemState(#GID_ListStatus,n,#PB_ListIcon_Checked)
|
SetGadgetItemState(#GID_ListStatus,n,#PB_ListIcon_Checked)
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; -----------------------------------------------------------------------------
|
; -----------------------------------------------------------------------------
|
||||||
@@ -1186,8 +1181,8 @@ EndProcedure
|
|||||||
Main()
|
Main()
|
||||||
|
|
||||||
; IDE Options = PureBasic 6.21 (Windows - x64)
|
; IDE Options = PureBasic 6.21 (Windows - x64)
|
||||||
; CursorPosition = 883
|
; CursorPosition = 1032
|
||||||
; FirstLine = 813
|
; FirstLine = 1025
|
||||||
; Folding = -----
|
; Folding = ------
|
||||||
; EnableXP
|
; EnableXP
|
||||||
; DPIAware
|
; DPIAware
|
Reference in New Issue
Block a user