subuser-security / subuser

Run programs on linux with selectively restricted permissions.
http://subuser.org
GNU Lesser General Public License v3.0
890 stars 65 forks source link

Add "-dirty" postfix to version string for uncommitted changes #342

Closed DEVoytas closed 6 years ago

DEVoytas commented 6 years ago

This is inspired by Linux kernel: https://github.com/torvalds/linux/blob/b244131/scripts/setlocalversion#L76

It may be useful for multiple reasons, for example:

This is how it works:

$ git status
On branch mark-uncommitted-changes-in-version
Your branch is up to date with 'origin/mark-uncommitted-changes-in-version'.

nothing to commit, working tree clean
$ subuser version | head -1
Subuser version: 0.6.2-dev-825feeb812e3f75dccb6ecc339f8c68541269fe6

$ echo "" >> logic/subuserlib/version.py
$ git status
On branch mark-uncommitted-changes-in-version
Your branch is up to date with 'origin/mark-uncommitted-changes-in-version'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   logic/subuserlib/version.py

no changes added to commit (use "git add" and/or "git commit -a")
$ subuser version | head -1
Subuser version: 0.6.2-dev-825feeb812e3f75dccb6ecc339f8c68541269fe6-dirty
$ git checkout logic/subuserlib/version.py
$ subuser version | head -1
Subuser version: 0.6.2-dev-825feeb812e3f75dccb6ecc339f8c68541269fe6
timthelion commented 6 years ago

I'm a bit disturbed by the fact that the version command still works after you run:

echo "" >> logic/subuserlib/version.py
DEVoytas commented 6 years ago

@timthelion why so? This is just adding empty line at the end of the file, so should not break anything ever. Just a random change to demonstrate version string changes :) Could well be any other change in any other tracked file. You can verify by yourself that echo "" >> logic/subuserlib/version.py does not prevent version command from working by checking out master, running above echo command and then issuing subuser version command.

timthelion commented 6 years ago

Aha, I made a reading comprehension error and read that as being echo "" > logic/subuserlib/version.py. My bad.