2012-07-16 6 views
25

Poiché "test" è un uso comune per un hook Git, la mia domanda è difficile da cercare.Come testare git git

Sto scrivendo un hook git post-receive abbastanza impegnativo e voglio sapere qual è il modo migliore per testarlo. Attualmente il mio processo è:

  • apportare modifiche al post-ricevere in un manichino di pronti contro termine "remoto"
  • apporta una modifica a un repo locale fittizio
  • commettere cambiamento fittizio repo locale
  • cambiamento spinta per finto repo remoto

C'è un modo più semplice per testare questo? Idealmente sarebbe simile:

  • cambiamento make (s) al post-ricevere in un repo fittizio
  • problema comando "magico" per testare post-ricezione

Forse posso "ristampa" una spinta precedente o il repo remoto si comporta come se avesse appena ricevuto una spinta con un hash specifico?

risposta

13

Scrivi un hook che registra solo i suoi argomenti/l'ambiente e lo archivia in un file. Quindi puoi semplicemente ri-invocare il vero hook a tuo piacimento con lo stesso ambiente/argomenti e agirà come se tu abbia appena emesso la stessa identica spinta.

+0

Questo è quello che ho fatto, ma invece ispezionando manualmente (riecheggiando) le variabili rilevanti. – Errol

+9

come sarebbe un gancio simile a un "dumper"? –

+4

@JonWatson, ho appena usato 'echo $ @; echo; pwd; eco; set' – Lucas

6

Rispondere a questa domanda di quattro anni.

Se vuoi testare gancio in ambiente locale, io do i comandi di dettaglio per dare seguito, usare post-receive come campione:

$ mkdir /tmp/hook_test 
$ cd /tmp/hook_test 

# set local git repo, where you put hooks in it. 
$ git clone --bare https://github.com/git/git.git 

# set develop environment which is cloned from the new created repo. 
$ git clone git.git repo 

# copy and rename the hook you need test to "post-receive" 
$ cd git.git/hooks 
$ cp ~/post-receive-test post-receive 

# suppose the hook script is bash script. 
# edit "post-receive" and add "set -x" to second line in it to active debug 

$ cd /tmp/hook_test/repo 
# emulate a hook trigger, do some changes, "git add" and "git commit" it 

$ git push 

# Now you should see the script "post-receive" runs automatically with debug details. 

Si dovrebbe essere liberi di correre git push, che gli aggiornamenti sono solo spinto al repo locale /tmp/hook_test/git.git