{"thread":{"id":"52408","subject":"How to determine age of HEAD commit","startedAt":"2019-12-08T12:09:20Z","lastAt":"2019-12-08T15:05:47Z","messageCount":3,"participants":["Philip Oakley","Roger Gammans"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"387715","messageId":"956e2efe-3426-f61e-7686-5416b51931b9@iee.email","threadId":"52408","inReplyTo":null,"subject":"How to determine age of HEAD commit","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2019-12-08T12:09:14Z","receivedAt":"2019-12-08T12:09:20Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"The Visual Studio git solution uses the vcpkg manager for dependencies, \nvia a cloned git repo.\n\nTo avoid repeated probing for updates when compiling, I considered \nholding of on 'git pull' for the repo for say 24 hours (daily update). \nHowever I'm not aware of a git command that returns the numeric value of \nthe agedness of a given local commit (typically HEAD).\n\nIs there a command that does return the numeric agedness of a commit \n(e.g. now - commit_date, in seconds)?\n-- \nPhilip\n\n"},{"id":"387716","messageId":"0a578dce37e8802b2022df80c336f61a264a33e3.camel@gammascience.co.uk","threadId":"52408","inReplyTo":"956e2efe-3426-f61e-7686-5416b51931b9@iee.email","subject":"Re: How to determine age of HEAD commit","fromName":"Roger Gammans","fromEmail":"rgammans@gammascience.co.uk","sentAt":"2019-12-08T14:07:15Z","receivedAt":"2019-12-08T14:26:27Z","isPatch":false,"sender":{"key":"rgammans@gammascience.co.uk","avatar":null},"body":"On Sun, 2019-12-08 at 12:09 +0000, Philip Oakley wrote:\n> Is there a command that does return the numeric agedness of a commit \n> (e.g. now - commit_date, in seconds)?\n\nHi\n\nI don't know a specific command for the age. But `git cat-file commit\nHEAD`, will give you the commit's timestamps in seconds from the the\nepoch. (Plus some timezone info).\n\nI can construct a bash script, shown below (warning: only had the most \nrudimentary testing), which turns that into an age. For your use case\nyou might be better getting yesterdays unix-timestamp from date, if GNU\ndate is available, and directly comparing it to the commit timestamp.\n\n------\n#!/bin/bash\n\nnow=$(date +\"%s\")\ncommit=$(git cat-file commit HEAD | grep committer)\ncommit=${commit##*>}\ncommit=${commit%%+*}\necho $(( $now-$commit ))\n#--------------\n\n-- \nRoger Gammans <rgammans@gammascience.co.uk>\n\n"},{"id":"387717","messageId":"74d4a783-6196-08ce-b600-2eb2cacecac7@iee.email","threadId":"52408","inReplyTo":"0a578dce37e8802b2022df80c336f61a264a33e3.camel@gammascience.co.uk","subject":"Re: How to determine age of HEAD commit","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.email","sentAt":"2019-12-08T15:05:44Z","receivedAt":"2019-12-08T15:05:47Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"Hi Roger,\n\nOn 08/12/2019 14:07, Roger Gammans wrote:\n> On Sun, 2019-12-08 at 12:09 +0000, Philip Oakley wrote:\n>> Is there a command that does return the numeric agedness of a commit\n>> (e.g. now - commit_date, in seconds)?\n> Hi\n>\n> I don't know a specific command for the age. But `git cat-file commit\n> HEAD`, will give you the commit's timestamps in seconds from the the\n> epoch. (Plus some timezone info).\n>\n> I can construct a bash script, shown below (warning: only had the most\n> rudimentary testing), which turns that into an age. For your use case\n> you might be better getting yesterdays unix-timestamp from date, if GNU\n> date is available, and directly comparing it to the commit timestamp.\n>\n> ------\n> #!/bin/bash\n>\n> now=$(date +\"%s\")\n> commit=$(git cat-file commit HEAD | grep committer)\n> commit=${commit##*>}\n> commit=${commit%%+*}\n> echo $(( $now-$commit ))\n> #--------------\n>\nThanks,\nThat has spurred me into looking at a few other ideas.\nUnfortunately the script needs to run inside a DOS batch file as part of \na Visual Studio pre-build step, hence the desire for a direct command.\n\nThat said I have now found, with a bit of rooting around, that\n\n    `git log -1 --format=format:\"%ct\" HEAD`\n\ndoes appear to give the right form of answer. Just need to see if I can \nfit it into the DOS pre-build script now ;-)\nThere may be extra tweaks needed.. (a merged pull has the pull date, but \na fast forward pull has the original date)\n\nPhilip\n\nPhilip\n"}]}