2011-04-12 6 views
23

क्या पावरशेल स्क्रिप्ट को गिट हुक के रूप में चलाने के लिए संभव है?गिट हुक के रूप में पावरशेल स्क्रिप्ट चलाना

मैं पावरशेल प्रॉम्प्ट में गिट चला रहा हूं, जो कोई फर्क नहीं पड़ता है, लेकिन मुझे उन्हें काम करने के लिए प्रतीत नहीं होता है, क्योंकि हुक का विस्तार किए बिना नाम दिया जाता है, और पावरशेल को (एएफएआईके) की आवश्यकता होती है .ps1 विस्तार। मुझे यकीन नहीं है कि यह मुद्दा है, या कुछ और।

धन्यवाद, एरिक

+0

नहीं यह स्क्रिप्ट (उस बात के लिए या किसी अन्य स्क्रिप्ट, अपने विस्तार की परवाह किए बिना) powershell स्क्रिप्ट आह्वान बनाने के लिए संभव है? – holygeek

+1

क्या आप गिट हुक के बारे में कुछ और जानकारी दे सकते हैं। – JPBlanc

+0

@ जेपीब्लैंक: ['गिटूक' मैनपेज।] (Http://www.kernel.org/pub/software/scm/git/docs/githooks.html) मुझे नहीं पता कि विंडोज के लिए अलग-अलग दस्तावेज उपलब्ध हैं या नहीं संस्करण (रों)। – intuited

उत्तर

5

मैं क्या ही एकमात्र विकल्प इकट्ठा से Git के डिजाइन यहाँ की वजह से PowerShell बुला एक bash स्क्रिप्ट होगा। दुर्भाग्यपूर्ण, लेकिन फिर, गिट ने गैर-लिनक्स संगतता पर कोई विचार नहीं किया।

+0

यह उत्तर लगता है। क्या यह दयालु है - हम सभी बैश प्रेमी नहीं हैं, और खिड़कियों पर बैश हमेशा दूसरी जगह होगी। धन्यवाद। –

+0

यदि गिट ने मनमाने ढंग से प्लेटफार्मों के लिए स्क्रिप्टिंग समर्थित किया है, तो उन हुक के लिए कॉन्फ़िगरेशन फ़ाइलों को वास्तव में बैश स्क्रिप्ट बूटस्ट्रैप्स से कितना अलग दिखाई देगा? – brianary

5

मैं अपने आप को इस की तलाश में गया है, और मैंने पाया निम्नलिखित:

Git Powershell पूर्व प्रतिबद्ध हुक (Source)

## Editor's note: Link is dead as of 2014-5-2. If you have a copy, please add it. 

पीएचपी सिंटेक्स जांच Git के लिए में पूर्व के लिए प्रतिबद्ध PowerShell (Soure)

############################################################################## 
# 
# PHP Syntax Check for Git pre-commit hook for Windows PowerShell 
# 
# Author: Vojtech Kusy <[email protected]> 
# 
############################################################################### 

### INSTRUCTIONS ### 

# Place the code to file "pre-commit" (no extension) and add it to the one of 
# the following locations: 
# 1) Repository hooks folder - C:\Path\To\Repository\.git\hooks 
# 2) User profile template - C:\Users\<USER>\.git\templates\hooks 
# 3) Global shared templates - C:\Program Files (x86)\Git\share\git-core\templates\hooks 
# 
# The hooks from user profile or from shared templates are copied from there 
# each time you create or clone new repository. 

### SETTINGS ### 

# Path to the php.exe 
$php_exe = "C:\Program Files (x86)\Zend\ZendServer\bin\php.exe"; 
# Extensions of the PHP files 
$php_ext = "php|engine|theme|install|inc|module|test" 
# Flag, if set to 1 git will unstage all files with errors, se to 0 to disable 
$unstage_on_error = 0; 

### FUNCTIONS ### 

function php_syntax_check { 
    param([string]$php_bin, [string]$extensions, [int]$reset) 

    $err_counter = 0; 

    write-host "Pre-commit PHP syntax check:" -foregroundcolor "white" 

    git diff-index --name-only --cached HEAD -- | foreach {    
     if ($_ -match ".*\.($extensions)$") { 
      $file = $matches[0]; 
      $errors = & $php_bin -l $file   
      if ($errors -match "No syntax errors detected in $file") { 
       write-host $file ": OK" -foregroundcolor "green" 
      } 
      else {    
       write-host $file ":" $errors -foregroundcolor "red" 
       if ($reset) { 
        git reset -q HEAD $file 
        write-host "Unstaging" $file "..." -foregroundcolor "magenta" 
       } 
       $err_counter++ 
      } 
     } 
    } 

    if ($err_counter -gt 0) { 
     exit 1 
    }  
} 

### MAIN ### 

php_syntax_check $php_exe $php_ext $unstage_on_error 

कोड पूर्व-प्रतिबद्ध हुक के लिए है, लेकिन आप इसे बहुत कुछ करने के लिए संशोधित कर सकते हैं। आपको क्या करने की ज़रूरत है मदद करनी चाहिए!

+0

पहला वाला मेरे लिए काम नहीं करता है। पावरहेल स्क्रिप्ट के सापेक्ष पथ सही ढंग से हल नहीं होता है। –

15

हुक फ़ोल्डर में प्री-प्रतिबद्ध करने के लिए pre-commit.sample का नाम बदलें। फिर उसी फ़ोल्डर में pre-commit.ps1 powerhell स्क्रिप्ट फ़ाइल बनाएं।

#!/bin/sh 
c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -Command -File '.git\hooks\pre-commit.ps1' 
+2

मुझे लगता है कि इस कमांड लाइन में सिंटैक्स गलत है - कमांड यह एक इनलाइन पावरहेल कमांड की उम्मीद कर रहा है लेकिन आप एक फाइल भी निर्दिष्ट कर रहे हैं। यह एक त्रुटि फेंक देगा -फाइल को cmdlet, फ़ंक्शन या स्क्रिप्ट फ़ाइल के नाम के रूप में पहचाना नहीं जा रहा है। – leinad13

+0

देखें [नीचे मेरा जवाब] (http://stackoverflow.com/a/39796096/1225497) अगर आपको "#! पहचान नहीं है ..." या "शब्द -फाइल पहचान नहीं है ..." । – Taran

2

Kim Ki Won के जवाब से ऊपर मेरे लिए काम नहीं किया है, लेकिन यह upvotes है तो मैं यह कुछ लोगों के लिए काम करता है मान लेंगे।

मुझे bin/श छोड़ने के लिए किया गया था और बजाय -File का उपयोग कर क्रियान्वित करने, सीधे कमांड को क्रियान्वित क्या काम किया:।

c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -Command .\.git\hooks\pre-commit.ps1 
+1

यह मेरे लिए भी काम करता है, धन्यवाद! – David

0

यह विंडोज पर अपने Git हुक में स्थित है \ Git \ हुक।

बाद अद्यतन

#!/bin/sh 
c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy Bypass -Command '.\post-update.ps1' 

Powershell परियोजना रूट फ़ोल्डर (जहां शुरू में Git init चलाने) में स्थित स्क्रिप्ट। पावरहेल एक और भंडार में जाता है और उस भंडार को अद्यतन करते हुए खींचता है।

बाद update.ps1

Set-Location "E:\Websites\my_site_test" 
$env:GIT_DIR = 'E:\Websites\my_site_test\.git'; 
$env:GIT_EXEC_PATH= 'C:\Program Files (x86)\Git/libexec/git-core'; 
git pull 
संबंधित मुद्दे