| View previous topic :: View next topic |
| Author |
Message |
3PO l33t


Joined: 26 Nov 2006 Posts: 867 Location: Schwabenländle
|
Posted: Sat Feb 11, 2012 9:23 am Post subject: Frage zu git in einem Shellscrpit |
|
|
Hallo Zusammen,
ich will in einem Script folgende Bedingung einbauen:
- Mache "git pull"
- Wenn es etwas Neues gibt, dann mache "make clean all"
Ich habe das jetzt so gelöst:
| Code: | | [ ! "$(git pull |grep 'Already up-to-date.')" ] && make clean all |
Funktionieren tut das Ganze ja soweit, aber da gibt es doch sicherlich elegantere Lösungen? |
|
| Back to top |
|
 |
firefly Advocate

Joined: 31 Oct 2002 Posts: 3999
|
Posted: Sat Feb 11, 2012 10:43 am Post subject: |
|
|
eventuell liefert git verschiedene return werte je nachdem ob was getan wurde oder nicht.
das ganze kannst du wie folgt ausprobieren:
| Code: | | <git-command> ; echo $? |
$? enthält den return wert des letzten kommandos. _________________ Ein Ring, sie zu knechten, sie alle zu finden,
Ins Dunkel zu treiben und ewig zu binden
Im Lande Mordor, wo die Schatten drohn. |
|
| Back to top |
|
 |
3PO l33t


Joined: 26 Nov 2006 Posts: 867 Location: Schwabenländle
|
Posted: Sat Feb 11, 2012 1:28 pm Post subject: |
|
|
Nun, genau um das "<git-command>" geht es ja. Leider ist "git help" diesbezüglich nicht sehr aufschlussreich.  |
|
| Back to top |
|
 |
mv Advocate


Joined: 20 Apr 2005 Posts: 3226
|
Posted: Sat Feb 11, 2012 2:12 pm Post subject: |
|
|
M.W. ist | Code: | | git status --porcelain | das einzige Git-Kommando, das in garantierter Weise eine parse-bare Ausgabe für Scripts generiert. Ob da die Information dabei steht, die Du willst, weiß ich aber nicht. |
|
| Back to top |
|
 |
3PO l33t


Joined: 26 Nov 2006 Posts: 867 Location: Schwabenländle
|
Posted: Sat Feb 11, 2012 2:31 pm Post subject: |
|
|
Leider zeigt das nicht an, ob beim "git pull" etwas geändert wurde.  |
|
| Back to top |
|
 |
ScytheMan l33t


Joined: 30 Nov 2005 Posts: 605
|
Posted: Sat Feb 11, 2012 3:31 pm Post subject: |
|
|
du könntest einen client side git hook basteln.
im client repository muss das unter .git/hooks/
leider weiß ich nicht welches hook-file du dafür verwenden musst, aber "man githooks" dürfte weiterhelfen.
post-merge dürfte wohl passen.
Last edited by ScytheMan on Sat Feb 11, 2012 4:43 pm; edited 1 time in total |
|
| Back to top |
|
 |
manuels Advocate


Joined: 22 Nov 2003 Posts: 2139 Location: Europe
|
|
| Back to top |
|
 |
3PO l33t


Joined: 26 Nov 2006 Posts: 867 Location: Schwabenländle
|
Posted: Sat Feb 11, 2012 5:55 pm Post subject: |
|
|
THX @ manuels,
ich werde es mal so probieren.
| Code: | cd $GIT_DIR
original_head=$(git rev-parse HEAD) || exit
git pull || exit
updated_head=$(git rev-parse HEAD) || exit
[ $original_head != $updated_head ] && make clean all |
|
|
| Back to top |
|
 |
cryptosteve l33t


Joined: 04 Jan 2004 Posts: 930 Location: Buchholz/GER
|
Posted: Mon Feb 13, 2012 3:14 pm Post subject: |
|
|
Ich fand die Ausgangslösung - gemessen an den sonstigen Möglichkeiten - gar nicht so übel.  _________________ - born to create drama -
cryptosteve - gpg: 0x9B6C7E15
CS Virtual Travel Bug: VF6G5D |
|
| Back to top |
|
 |
|