git Syndicate content

warning: Creating default object from empty value in /www/htdocs/w0065fc9/milianw/modules/taxonomy/ on line 33.

» A git hook to prevent pushes with untracked source files

Fri, 08/08/2014 - 13:40

Hey all,

do you know this: You work on something locally in git, ensure everything compiles and the tests pass, then commit and hit git push.What could possibly go wrong at that point, eh? Well, far too often I forgot to git add some new source file. Best-case I’ll notice this directly, worst-case I’ll see my CI complaining. But, like yesterday in kdev-clang, I might be afk at that point and someone else will have to revert my change and I’ll have to fix it up the day after, polluting the git history while at it…

Thanks to some simple shell scripting and the powerful git hook architecture, it is pretty simple to protect oneself against such issues:

  1. #!/bin/sh
  3. #
  4. # A hook script to verify that a push is not done with untracked source file
  5. #
  6. # To use it, either symlink this script to $your-git-clone/.git/hooks/pre-push
  7. # or include it in your existing pre-push script.
  8. #
  10. # Perl-style regular expression which limits the files we interpret as source files.
  11. # The default pattern here excludes CMakeLists.txt files and any .h/.cpp/.cmake files.
  12. # Extend/adapt this to your needs. Alternatively, set the pattern in your repo via:
  13. # git config hooks.prepush.sourcepattern "$your-pattern"
  14. pattern=$(git config --get hooks.prepush.sourcepattern)
  15. if [ -z "$pattern" ]; then
  16. pattern="(?:(?:^|/)CMakeLists\.txt|\.h|\.cpp|\.cmake)$"
  17. fi
  19. files=$(git status -u --porcelain --no-column | sed "s/^?? //" | grep -P "$pattern")
  20. if [ -z "$files" ]; then
  21. exit 0
  22. fi
  24. echo
  25. echo "ERROR: Preventing push with untracked source files:"
  26. echo
  27. echo "$files" | sed "s/^/ /"
  28. echo
  29. echo "Either include these files in your commits, add them to .gitignore"
  30. echo "or stash them with git stash -u."
  31. echo
  32. exit 1

Note: The last version of the above code can be found on GitHub: pre-push-check-untracked

When you then try to push with some untracked source files, i.e. files matched by the regex pattern which can be configured via git config hooks.prepush.sourcepattern, you’ll see output like this:

  1. # to show the current status, note the untracked bar file which is not included as a source file
  2. $ git status
  3. On branch master
  4. Your branch is up-to-date with 'origin/master'.
  6. Untracked files:
  7. (use "git add <file>..." to include in what will be committed)
  9. CMakeLists.txt
  10. bar
  11. foo/
  13. nothing added to commit but untracked files present (use "git add" to track)
  15. # now try to push something
  17. $ git push
  19. ERROR: Preventing push with untracked source files:
  21. CMakeLists.txt
  22. foo/asdf.h
  24. Either include these files in your commits, add them to .gitignore
  25. or stash them with git stash -u.
  27. error: failed to push some refs to '/tmp/repo'

Happy hacking!

» Git commit message highlighting in nano

Sat, 11/24/2012 - 16:07

For those who use nano as their CLI editor of choice: Here’s a syntax highlighting file for Git commit messages which also supports the special KDE commit hook keywords.

  1. ## syntax highlighting for git commit messages of KDE projects
  2. syntax "patch" ".git/COMMIT_EDITMSG$"
  4. # overlong lines
  5. color brightred "^.{70,}.+$"
  7. # KDE commit hook keywords, see:
  9. color yellow "(SVN_SILENT|GIT_SILENT|SVN_MERGE)"
  11. # comment
  12. color blue "^#.*$"
  14. # special comment lines
  15. color green "^# Changes to be committed:"
  16. color red "^# Changes not staged for commit:"
  17. color brightblue "^# Untracked files:"
  18. color brightblue "^# On branch .+$"
  19. color brightblue "^# Your branch is ahead of .+$"
  21. # diff files
  22. # meh - cannot match against \t ... should be: ^#\t.*$
  23. color cyan "^#[^ a-zA-Z0-9][^ ].*$"

Just put this file as gitcommit.nanorc or similar somewhere on your disk and load it from your .nanorc or even /etc/nanorc like this:

  1. include "/path/to/gitcommit.nanorc"
Screenshot of highlighted git commit message
Screenshot of highlighted git commit message

» KDevelop 4.0.2 and KDevelop 4.1 Beta 1 released

Sun, 09/05/2010 - 19:13

Good news everyone, this time in a double feature!

I’m happy to announce the availability of two new additions to the KDevelop release family:

KDevelop 4.0.2 stable release

Lets begin with the boring part: We have released KDevelop 4.0.2, together with KDevplatform and the PHP plugins. You can find the sources here:

This is a bugfix only release and everyone is urged to upgrade as soon as possible. Users should wait for their distributions to provide packages for them. The tarballs contain changelogs if you are interested what happened since 4.0.1. Or read them online:

Note: This is (most probably) the last release in the 4.0 branch. We don’t have enough manpower to handle more than one stable branch. Which makes me come to the second part of this mail:

KDevelop 4.1 Beta 1 experimental release

We are very happy to publish KDevelop 4.1 Beta 1, which will be the branch we are concentrating on in the next time. You can find the sources here:

This is a preview release. We are gratefully welcoming any testers and feedback to polish it further for the final 4.1 release which will probably happen around mid October. Please put the reports on the usual places, e.g. If you are interested in the (quite long) list of changes, look into the tarballs again for an extensive git changelog. If you just want a few highlights: Git Support Plugin, External Script Plugin, general polishing, CPP support improvements, lots of bug fixes, UI polishing, performance improvements, … you name it :)

For the fun of it, here the list of commits changes for 4.1 (imo far too big to show anything useful):

Thanks as always to the KDevelop team for making this possible and to the users for giving us valuable feedback.


PS: Sorry that I forgot to announce this yesterday or even Friday, as I initially planned. Well, weekends are such a nice time to go outside and enjoy life :)

» KDevelop Webdev plugins merged into Quanta GIT

Sun, 06/13/2010 - 17:18

Quick note:

I’ve just merged all webdevelopment related plugins except PHP & PHP-Docs into Quanta git. You can get them all in one place now by cloning Quanta:

Since I also moved all halfworking plugins to UNPORTED (they don’t get installed), you should be fine by just installing all of Quanta to get the plugins. If you only want one of them, going into it’s subfolder and building it standalone should hopefully still work though.

In other notes: Thanks to Ruan Styrdom for starting work on a PHP formatter plugin for KDevelop. It uses phpStylist and it’s already somewhat working. Awesome :)

/me is off to more GSOC hacking, bye