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