correction Push
This commit is contained in:
159
PBIDE-GitTool.pb
159
PBIDE-GitTool.pb
@@ -81,6 +81,11 @@ CompilerEndIf
|
||||
#GDiffText = 301
|
||||
#GDiffClose = 302
|
||||
|
||||
; Fenêtre de sortie Git
|
||||
#WOut = 400
|
||||
#GOutText = 401
|
||||
#GOutCopy = 402
|
||||
#GOutClose = 403
|
||||
|
||||
; ====== Structures ======
|
||||
Structure GitCall
|
||||
@@ -140,9 +145,88 @@ Procedure.s TrimNewlines(text$)
|
||||
ProcedureReturn s$
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Détecte si 'remote$' ressemble à une URL (http(s):// ou git@…)
|
||||
Procedure.i IsUrlRemote(remote$)
|
||||
If FindString(remote$, "://", 1) Or FindString(remote$, "@", 1)
|
||||
ProcedureReturn 1
|
||||
EndIf
|
||||
ProcedureReturn 0
|
||||
EndProcedure
|
||||
|
||||
; Récupère le nom de branche courante (HEAD → renvoie "" si détachée)
|
||||
Procedure.s GetCurrentBranch(repoDir$)
|
||||
Protected gc.GitCall
|
||||
gc\workdir = repoDir$
|
||||
gc\args = "rev-parse --abbrev-ref HEAD"
|
||||
If RunGit(@gc) = 0
|
||||
Protected b$ = TrimNewlines(gc\output)
|
||||
If b$ <> "" And LCase(b$) <> "head"
|
||||
ProcedureReturn b$
|
||||
EndIf
|
||||
EndIf
|
||||
ProcedureReturn ""
|
||||
EndProcedure
|
||||
|
||||
; Teste si un remote nommé existe
|
||||
Procedure.i RemoteExists(repoDir$, remoteName$)
|
||||
Protected gc.GitCall, out$, i.i, n.i, line$
|
||||
gc\workdir = repoDir$
|
||||
gc\args = "remote"
|
||||
If RunGit(@gc) <> 0
|
||||
ProcedureReturn 0
|
||||
EndIf
|
||||
out$ = gc\output
|
||||
n = CountString(out$, #LF$) + 1
|
||||
For i = 1 To n
|
||||
line$ = Trim(StringField(out$, i, #LF$))
|
||||
If line$ <> "" And LCase(line$) = LCase(remoteName$)
|
||||
ProcedureReturn 1
|
||||
EndIf
|
||||
Next
|
||||
ProcedureReturn 0
|
||||
EndProcedure
|
||||
|
||||
Procedure.i ShowGitOutput(title$, stdOut$, stdErr$)
|
||||
Protected full$
|
||||
full$ + "=== STDOUT ===" + #LF$ + stdOut$ + #LF$ + "=== STDERR ===" + #LF$ + stdErr$
|
||||
|
||||
If OpenWindow(#WOut, 0, 0, 820, 520, title$, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
|
||||
EditorGadget(#GOutText, 10, 10, 800, 460)
|
||||
ButtonGadget(#GOutCopy, 600, 480, 100, 28, "Copier")
|
||||
ButtonGadget(#GOutClose, 710, 480, 100, 28, "Fermer")
|
||||
SetGadgetText(#GOutText, full$)
|
||||
Repeat
|
||||
Protected ev.i = WaitWindowEvent()
|
||||
If ev = #PB_Event_Gadget
|
||||
Select EventGadget()
|
||||
Case #GOutCopy
|
||||
SetClipboardText(full$)
|
||||
Case #GOutClose
|
||||
CloseWindow(#WOut)
|
||||
Break
|
||||
EndSelect
|
||||
EndIf
|
||||
Until ev = #PB_Event_CloseWindow
|
||||
EndIf
|
||||
ProcedureReturn 1
|
||||
EndProcedure
|
||||
|
||||
; Ajoute un remote
|
||||
Procedure.i AddRemote(repoDir$, remoteName$, remoteUrl$)
|
||||
Protected gc.GitCall
|
||||
gc\workdir = repoDir$
|
||||
gc\args = "remote add " + remoteName$ + " " + Chr(34) + remoteUrl$ + Chr(34)
|
||||
If RunGit(@gc) = 0
|
||||
ProcedureReturn 1
|
||||
EndIf
|
||||
ShowGitOutput("Git remote add — erreur", "", gc\errors)
|
||||
ProcedureReturn 0
|
||||
EndProcedure
|
||||
|
||||
; Exécute git avec capture stdout/stderr (structure passée par pointeur)
|
||||
Procedure.i RunGit(*call.GitCall)
|
||||
Protected prg.i, line$, out$, err$
|
||||
Protected prg.i, line$,lineError$, out$, err$
|
||||
If #EnableDebug
|
||||
Debug "[RunGit] " + #GitExe$ + " " + *call\args + " (wd=" + *call\workdir + ")"
|
||||
EndIf
|
||||
@@ -159,9 +243,9 @@ Procedure.i RunGit(*call.GitCall)
|
||||
While AvailableProgramOutput(prg)
|
||||
line$ = ReadProgramString(prg)
|
||||
If line$ <> "" : out$ + line$ + #LF$ : EndIf
|
||||
lineError$ = ReadProgramError(prg) ; renvoie "" si rien à lire (non bloquant)
|
||||
If lineError$ <> "" : err$ + lineError$ + #LF$ : EndIf
|
||||
Wend
|
||||
line$ = ReadProgramError(prg) ; renvoie "" si rien à lire (non bloquant)
|
||||
If line$ <> "" : err$ + line$ + #LF$ : EndIf
|
||||
Delay(5)
|
||||
Wend
|
||||
|
||||
@@ -334,18 +418,69 @@ Procedure.i DoCommit(repoDir$, message$, doPush.i, remote$, branch$)
|
||||
ProcedureReturn 1
|
||||
EndProcedure
|
||||
|
||||
; Push amélioré :
|
||||
; - Accepte 'Remote' comme URL : crée/emploie 'origin' automatiquement
|
||||
; - Si pas d'upstream : retente avec 'push -u <remote> <branch>'
|
||||
; - Affiche sorties complètes en cas d'erreur
|
||||
Procedure.i DoPush(repoDir$, remote$, branch$)
|
||||
Protected gc.GitCall
|
||||
gc\args = "push " + remote$ + " " + branch$
|
||||
Protected gc.GitCall, code.i
|
||||
Protected remoteName$ = remote$
|
||||
Protected remoteUrl$ = ""
|
||||
Protected curBranch$
|
||||
|
||||
; Remote vide → suppose 'origin'
|
||||
If Trim(remoteName$) = ""
|
||||
remoteName$ = "origin"
|
||||
EndIf
|
||||
|
||||
; Si l'utilisateur a saisi une URL comme 'remote', crée/emploie 'origin'
|
||||
If IsUrlRemote(remoteName$)
|
||||
remoteUrl$ = remoteName$
|
||||
remoteName$ = "origin"
|
||||
If RemoteExists(repoDir$, remoteName$) = 0
|
||||
If AddRemote(repoDir$, remoteName$, remoteUrl$) = 0
|
||||
ProcedureReturn 0
|
||||
EndIf
|
||||
EndIf
|
||||
EndIf
|
||||
|
||||
; Branche à utiliser : champ ou branche courante
|
||||
If Trim(branch$) = ""
|
||||
curBranch$ = GetCurrentBranch(repoDir$)
|
||||
Else
|
||||
curBranch$ = branch$
|
||||
EndIf
|
||||
|
||||
If curBranch$ = ""
|
||||
MessageRequester("Git push", "Branche courante introuvable (HEAD détachée ?). Sélectionnez une branche.", #PB_MessageRequester_Warning)
|
||||
ProcedureReturn 0
|
||||
EndIf
|
||||
|
||||
; Tentative de push normal
|
||||
gc\workdir = repoDir$
|
||||
If RunGit(@gc) = 0
|
||||
gc\args = "push " + remoteName$ + " " + curBranch$
|
||||
code = RunGit(@gc)
|
||||
If code = 0
|
||||
MessageRequester("Git push", "OK:" + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
||||
ProcedureReturn 1
|
||||
EndIf
|
||||
MessageRequester("Git push", "Échec: " + #LF$ + TrimNewlines(gc\errors), #PB_MessageRequester_Error)
|
||||
|
||||
; Si pas d'upstream, retente avec -u (premier push)
|
||||
If FindString(LCase(gc\errors), "no upstream branch", 1) Or FindString(LCase(gc\errors), "set the remote as upstream", 1)
|
||||
gc\args = "push -u " + remoteName$ + " " + curBranch$
|
||||
code = RunGit(@gc)
|
||||
If code = 0
|
||||
MessageRequester("Git push (premier envoi)", "Upstream configuré et push effectué." + #LF$ + TrimNewlines(gc\output), #PB_MessageRequester_Info)
|
||||
ProcedureReturn 1
|
||||
EndIf
|
||||
EndIf
|
||||
|
||||
; Autre erreur → fenêtre complète
|
||||
ShowGitOutput("Git push — erreur", gc\output, gc\errors)
|
||||
ProcedureReturn 0
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure.i DoPull(repoDir$, remote$, branch$)
|
||||
Protected gc.GitCall
|
||||
gc\args = "pull " + remote$ + " " + branch$
|
||||
@@ -834,6 +969,10 @@ Procedure.i UpdateGuide(repoDir$, List rows.FileRow(), branch$, remote$)
|
||||
ProcedureReturn 1
|
||||
EndProcedure
|
||||
|
||||
; Affiche stdout + stderr dans une fenêtre (évite le texte tronqué)
|
||||
|
||||
|
||||
|
||||
|
||||
; ====== UI principale ======
|
||||
; Gadgets IDs (inclut les NOUVEAUX boutons)
|
||||
@@ -1273,9 +1412,9 @@ Else
|
||||
EndIf
|
||||
|
||||
; IDE Options = PureBasic 6.21 (Windows - x64)
|
||||
; CursorPosition = 835
|
||||
; FirstLine = 794
|
||||
; Folding = ------
|
||||
; CursorPosition = 212
|
||||
; FirstLine = 181
|
||||
; Folding = -------
|
||||
; EnableXP
|
||||
; DPIAware
|
||||
; Executable = ..\PBIDE-GitTool.exe
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user