It's so simple: I am trying to use gitversion to manage semver and I am getting completely different behavior on the same repo/branch/commit between windows and mac. I am hoping someone can explain because I can't manage a version bump without it.
mac:
cbongiorno at 5cg4461z2l in ~/dev/adaptors on master [$]
$ git log -1 --pretty=oneline
e7592b7703792069e4f1a69317ef50fa1deae2eb (HEAD -> master, origin/master) PE20-165 - fix the command, again!
cbongiorno at 5cg4461z2l in ~/dev/adaptors on master [$]
$ gitversion /version
5.1.3+Branch.master.Sha.bef8ebc0b62b3ddd0cdafe09b66d68bbfcaf90d5
cbongiorno at 5cg4461z2l in ~/dev/adaptors on master [$]
$ git rev-parse --abbrev-ref HEAD
master
cbongiorno at 5cg4461z2l in ~/dev/adaptors on master [$]
$ gitversion
{
"Major":0,
"Minor":2,
"Patch":1,
"PreReleaseTag":"",
"PreReleaseTagWithDash":"",
"PreReleaseLabel":"",
"PreReleaseNumber":"",
"WeightedPreReleaseNumber":"",
"BuildMetaData":19,
"BuildMetaDataPadded":"0019",
"FullBuildMetaData":"19.Branch.master.Sha.e7592b7703792069e4f1a69317ef50fa1deae2eb",
"MajorMinorPatch":"0.2.1",
"SemVer":"0.2.1",
"LegacySemVer":"0.2.1",
"LegacySemVerPadded":"0.2.1",
"AssemblySemVer":"0.2.1.0",
"AssemblySemFileVer":"0.2.1.0",
"FullSemVer":"0.2.1+19",
"InformationalVersion":"0.2.1+19.Branch.master.Sha.e7592b7703792069e4f1a69317ef50fa1deae2eb",
"BranchName":"master",
"Sha":"e7592b7703792069e4f1a69317ef50fa1deae2eb",
"ShortSha":"e7592b7",
"NuGetVersionV2":"0.2.1",
"NuGetVersion":"0.2.1",
"NuGetPreReleaseTagV2":"",
"NuGetPreReleaseTag":"",
"VersionSourceSha":"800649c8102414d2513a19253ff2a4caadafb2ab",
"CommitsSinceVersionSource":19,
"CommitsSinceVersionSourcePadded":"0019",
"CommitDate":"2020-02-20"
}
Windows:
PS C:\Users\cbongiorno> cd E:\SysData\Jenkins\workspace\chb0_chb0mb_master
PS E:\SysData\Jenkins\workspace\chb0_chb0mb_master> git log -1 --pretty=oneline
e7592b7703792069e4f1a69317ef50fa1deae2eb (HEAD -> master, tag: 0.1.0, origin/master) PE20-165 - fix the command, again!
PS E:\SysData\Jenkins\workspace\chb0_chb0mb_master> gitversion /version
5.1.3+Branch.master.Sha.bef8ebc0b62b3ddd0cdafe09b66d68bbfcaf90d5
PS E:\SysData\Jenkins\workspace\chb0_chb0mb_master> gitversion
{
"Major":0,
"Minor":1,
"Patch":0,
"PreReleaseTag":"",
"PreReleaseTagWithDash":"",
"PreReleaseLabel":"",
"PreReleaseNumber":"",
"WeightedPreReleaseNumber":"",
"BuildMetaData":"",
"BuildMetaDataPadded":"",
"FullBuildMetaData":"Branch.master.Sha.e7592b7703792069e4f1a69317ef50fa1deae2eb",
"MajorMinorPatch":"0.1.0",
"SemVer":"0.1.0",
"LegacySemVer":"0.1.0",
"LegacySemVerPadded":"0.1.0",
"AssemblySemVer":"0.1.0.0",
"AssemblySemFileVer":"0.1.0.0",
"FullSemVer":"0.1.0",
"InformationalVersion":"0.1.0+Branch.master.Sha.e7592b7703792069e4f1a69317ef50fa1deae2eb",
"BranchName":"master",
"Sha":"e7592b7703792069e4f1a69317ef50fa1deae2eb",
"ShortSha":"e7592b7",
"NuGetVersionV2":"0.1.0",
"NuGetVersion":"0.1.0",
"NuGetPreReleaseTagV2":"",
"NuGetPreReleaseTag":"",
"VersionSourceSha":"e7592b7703792069e4f1a69317ef50fa1deae2eb",
"CommitsSinceVersionSource":92,
"CommitsSinceVersionSourcePadded":"0092",
"CommitDate":"2020-02-20"
}
PS E:\SysData\Jenkins\workspace\chb0_chb0mb_master> git rev-parse --abbrev-ref HEAD
master
The version numbers are totally different even though I am dealing with the same repo/commit. This HAS to be a bug.
Can anyone explain this?
Related
I am trying to get the current branch name from where I am pushing the code to the branch in the remote server .
Example: My local branch name is s095_Development and I am pushing the code from my local to master .
I want to get the local branch name in my pre-receive hook.
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
current_branch=$(git rev-parse --abbrev-ref HEAD | cut -d'_' -f1 | cut -d'/' -f3 )
current_branch=$(git name-rev --name-only HEAD | cut -d'_' -f1 | cut -d'/' -f3 )
I have used all the above but nothing seems to work for me - I am not able to get the current branch name.
Use the following command in the directory where your project is.
git branch
When using git push, it pushes to that branch but in the remote server. Thus, if you are currently in master, you'll be pushing to remotes/origin/master.
This is working for me using PHP executing a pre-receive hook on server
#!/usr/bin/php
<?php
$stdin = trim(fgets(STDIN));
$branchName = end(explode('/', end(explode(' ', $stdin))));
I'm trying to build an embedded system with yocto poky. My layers are:
BBLAYERS ?= " \
/home/dev/microzed/meta \
/home/dev/microzed/meta-yocto \
/home/dev/microzed/meta-yocto-bsp \
/home/dev/microzed/meta-xilinx \
/home/dev/microzed/meta-mono \
"
with git clones:
git clone -b master git://git.yoctoproject.org/poky.git ~/microzed
git clone -b master git://git.yoctoproject.org/meta-xilinx ~/microzed/meta-xilinx
git clone -b master git://git.yoctoproject.org/meta-mono ~/microzed/meta-mono
with bitbake core-image-minimal it all compiles and runs - but no mono.
So if I try to bitbake mono: bitbake core-image-mono it fails with the error:
ERROR: Required build target 'core-image-mono' has no buildable
providers. Missing or unbuildable dependency chain was:
['core-image-mono', 'mono-helloworld', 'mono', 'libgdiplus', 'giflib']
not sure how to resolve this. I don't actually need libgdiplus either... :/ in previous versions it was easy to remove, but the current master seems to have the dependency in quite a few places.
Requires meta-oe
git clone -b master git://git.openembedded.org/meta-openembedded ~/microzed/meta-openembedded
plus the layer:
/home/dev/microzed/meta-openembedded/meta-oe \
you can compile console-only build with:
bitbake core-image-mono-console
I have created spec/lint/rubocop_spec.rb which runs Rubocop style checker on the files changed between current branch and master. This works when I test locally but not when the test run on the build server Circle.ci.
I suspect it is because only the branch in question is downloaded, so it does not find any differences between master. Is there a better way than git co master && git pull origin master?
Can I query the Github API perhaps to get the files changed listed?
require 'spec_helper'
describe 'Check that the files we have changed have correct syntax' do
before do
current_sha = `git rev-parse --verify HEAD`.strip!
files = `git diff master #{current_sha} --name-only | grep .rb`
files.tr!("\n", ' ')
#report = 'nada'
if files.present?
puts "Changed files: #{files}"
#report = `rubocop #{files}`
puts "Report: #{#report}"
end
end
it { #report.match('Offenses').should_not be true }
end
You don't have to use github api, or even ruby (unless you want to wrap the responses) you can just run:
git fetch && git diff-tree -r --no-commit-id --name-only master#\{u\} head | xargs ls -1 2>/dev/null | xargs rubocop --force-exclusion
see http://www.red56.uk/2017/03/26/running-rubocop-on-changed-files/ for longer write-up of this
I fixed it by querying api.github.com.
This will run rubocop on all files that has been changed between current_sha and the master branch.
require 'spec_helper'
describe 'Check that the files we have changed have correct syntax' do
before do
current_sha = `git rev-parse --verify HEAD`.strip!
token = 'YOUR GITHUB TOKEN'
url = 'https://api.github.com/repos/orwapp/orwapp/compare/' \
"master...#{current_sha}?access_token=#{token}"
files = `curl -i #{url} | grep filename | cut -f2 -d: | grep \.rb | tr '"', '\ '`
files.tr!("\n", ' ')
#report = 'nada'
if files.present?
puts "Changed files: #{files}"
#report = `rubocop #{files}`
puts "Report: #{#report}"
end
end
it { expect(#report.match('Offenses')).to be_falsey }
end
I found https://github.com/m4i/rubocop-git which works very well. However it works on your git diff (optionally with --cached) so it does not allow you to compare branches.
I don't have high enough reputation to comment on an answer, so I am posting an answer to add a refinement I found useful:
git fetch && git diff-tree -r --no-commit-id --name-only master#\{u\} HEAD | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop --force-exclusion
The addition of --force-exclusion makes RuboCop respect the Exclude declarations in its config file (here using the default ./.rubocop.yml). You put those declarations in for a reason, right?! ;)
Here's another alternative that compares the current branch to origin/master (should work with any repo hosting - just tried it on circleci with a bitbucket repo). It also passes a .rubocop.yml config file option (you can remove that part if you don't need it).
require 'spec_helper'
RSpec.describe 'Check that the files we have changed have correct syntax' do
before do
current_sha = 'origin/master..HEAD'
#files = `git diff-tree --no-commit-id --name-only -r #{current_sha} | grep .rb`
#files.tr!("\n", ' ')
end
it 'runs rubocop on changed ruby files' do
if #files.empty?
puts "Linting not performed. No ruby files changed."
else
puts "Running rubocop for changed files: #{#files}"
result = system "bundle exec rubocop --config .rubocop.yml --fail-level warn #{#files}"
expect(result).to be(true)
end
end
end
Original gist here: https://gist.github.com/djburdick/5104d15f612c15dde65f#gistcomment-2029606
One simpler solution:
git diff origin/master --name-only | xargs rubocop --force-exclusion
Explanation: I rarely have master up to date locally, but doing git fetch updates origin/master so I want to diff against that. I can't get the other proposed solutions with diff-tree and origin/master to work.
Maybe you could leverage CircleCI’s dynamic configuration feature.
There is a specific guide on how to execute specific workflows or steps based on which files are modified (https://circleci.com/docs/using-dynamic-configuration/#execute-specific-workflows-or-steps-based-on-which-files-are-modified).
I am trying to set up a job in Jenkins using this p4 plugin. I successfully installed the plugin and set up the p4 configuration to point to my company's p4 executable.
Now the actual failure happens when I build the project. I am seeing the following:
Started by user anonymous
Building remotely on scspr0011492003.gdl.englab.netapp.com (scspr0011492003) in workspace /tmp/workspace/TestP4
Using remote perforce client: test--2000486220
[TestP4] $ /usr/software/rats/bin/p4 workspace -o test--2000486220
Last build changeset: 2464123
[TestP4] $ /usr/software/rats/bin/p4 changes -s submitted -m 1 //test--2000486220/...
[TestP4] $ /usr/software/rats/bin/p4 -s changes -s submitted //test--2000486220/...#2464124,#2515192
[TestP4] $ /usr/software/rats/bin/p4 describe -s 2515192
[TestP4] $ /usr/software/rats/bin/p4 -G where //...
[TestP4] $ /usr/software/rats/bin/p4 -s users alirezam
[TestP4] $ /usr/software/rats/bin/p4 user -o alirezam
Sync'ing workspace to changelist 2515192.
[TestP4] $ /usr/software/rats/bin/p4 -s sync //test--2000486220/...#2515192
Sync complete, took 1755 ms
[TestP4] $ /usr/software/rats/bin/p4 -xe /tmp/hudson6814857322401659205.sh
(b4p4: for help on the 'b4p4' wrapper, use 'p4 b4p4help'; p4 -V for version)
Perforce client error:
open for read: e: No such file or directory
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I am not sure what -xe is in p4 and not sure why it's failing. Can someone help? Thank you.
The issue here appears to be a combination of things. Wrong p4 command syntax and a possible non-valid file name.
The ‘-x’ global option in Perforce is for feeding a list of files as arguments to a command. For example, see the reference here:
http://www.perforce.com/perforce/doc.current/manuals/cmdref/global.options.html
I see a couple of things wrong with this command:
/usr/software/rats/bin/p4 -xe /tmp/hudson6814857322401659205.sh
1] Unless the ‘e’ is a file or file list it is not passing anything in
2] On that line, there is no Perforce command used with the global option -x. For example, a command such as ‘edit’ or ‘add’.
Should this line instead be perhaps like this?:
/usr/software/rats/bin/p4 -x /tmp/hudson6814857322401659205.sh edit
You could also try something like this here:
echo /tmp/hudson6814857322401659205.sh|p4 -x - edit
to see if you get the same error of “Perforce client error:
open for read: e: No such file or directory”? That error indicates that it might be returning something that is not a valid filename.
I've made something wrong to my own git repository argh :/
Before I had 3 branches: master, layout and masscreate (all from me).
But now, I don't know what I've done wrong, my git master is the master of the rails repository?!?
When I switch to my master branch and make a git status, it shows me:
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 25732 and 239 different commit(s) each, respectively.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# ... some changes from my own code
I don't know whats happening if I commit now?!
I use GitX and it never showed me the rails branches.. But now there are beside my own branches, all the rails branches.. :/
EDIT:
git reflog --all shows me
a979775 refs/heads/masscreate#{0}: commit: Updated bitcoin client, removed unnecessary files, added mass create feature, updated gems
d2e2fb8 refs/heads/masscreate#{1}: commit: First commit
74fbbca refs/heads/3-1-stable#{0}: fetch --force --quiet --tags git://github.com/rails/rails.git refs/heads/*:refs/heads/*: storing head
4a065d5 refs/heads/master#{0}: fetch --force --quiet --tags git://github.com/rails/rails.git refs/heads/*:refs/heads/*: forced-update
5419222 refs/heads/layout#{0}: commit: First layout commit - not working
c42120e refs/heads/masscreate#{2}: branch: Created from master
11b0804 refs/heads/layout#{1}: commit: Test commit (with logo)
954297b refs/heads/layout#{2}: branch: Created from master
fd67735 refs/heads/3-0-stable#{0}: fetch --force --quiet --tags git://github.com/rails/rails.git refs/heads/*:refs/heads/*: storing head
afd7140 refs/heads/serializers#{0}: fetch --force --quiet --tags git://github.com/rails/rails.git refs/heads/*:refs/heads/*: storing head
ba70812 be6527f 7bf12a1 05386ce 471e1f1 7f60202 f40bbc9 57a01f3 162e13d 3c6cbad f8beca0 4f2c238 cf4d166 14e2fe2 fc9b521 aa11f73 9257a21 c6d13b6 d9d1bb2 db8db4a 188d21c 0ad5040 87
633a569 a19ee5c 66c3e31 f9b642c 09ad48f 4f15f39 b45dfc7 3480d97 fb4747b e0c03f8 e0774e4 refs/heads/2-3-stable#{0}: fetch --force --quiet --tags git://github.com/rails/rails.git r
dea5a10 c238ba0 11dafea bb99aa1 2330c0c ae69c4c 29d0ce0 4b4e67f f3f5a8f ebf0cc4 927d3c2 d8c6bab 0c3bdc0 4eac844 dbd72be 282ee95 92d3b51 073d9ff 9e9b127 388f09c 0ab65e8 458128d 35
ad16115 5e61d0b 15e2b58 refs/heads/3-0-9#{0}: fetch --force --quiet --tags git://github.com/rails/rails.git refs/heads/*:refs/heads/*: storing head
014008d d2b1340 7b04e50 a7039df 677df61 7f96566 b4b27a3 40dd641 95905c5 1f813d9 055a88d fa55293 f6fe174 b869b8c 71d7610 991e388 6cfd1c7 9267a43 190101e 8624996 5daef25 aeb7beb e5
d846f4b 6766caf e149861 f5f020b b7ea35d f8f00cc 2cbd024 da5122e 296ca01 ea8b05c 54f5fb5 96711aa a995911 654514a 69b25eb 8d758d8 645f138 a2a3413 377b15a b3b747d 1f02e3e 75fb26a f8
79abb70 1c079c5 f0c09f7 99cfdba d387a59 656e7b0 1d864e8 b102e60 d485633 177666e f236dbf 17c9efb c77bdc0 f505565 89252c4 da1ee0e 83f257f 872a9c1 3cbfc8c 5a6927e b648286 d79e284 65
e019587 0acc6bd 92537b8 c6c46e1 280a870 51f5209 af41d55 3b0f917 07fde1a 3e33592 3937296 389d15e 7a152ab 944b4d5 4f04452 9556e9c 9dfc215 49e7555 bb626e7 0675047 d0635b6 b14b058 ce
e9020b4 1c4db4d 18dde7b e6bc818 cb9e501 d907f3c 30264bb d7a5638 a9b4b5d 92e6255 3575782 ac07da8 f323a8f 284ca81 454ec93 b356172 16e5d15 4ac7196 3e24e9e 4c323bc 9bf5cdd bd3cdee a0
ee0b92e 631e23e cd44023 51414a0 1df3b65 9643243 ac86923 ea25224 08ef06d 2b4de66 4f7bdc8 e62b576 d9870d9 52f09ea 05bcb8c d55406d 5f1ea2a 30bba95 1193709 9f773d6 60da34b 933adce 0d
c6cb5a5 refs/heads/2-2-stable#{0}: fetch --force --quiet --tags git://github.com/rails/rails.git refs/heads/*:refs/heads/*: storing head
bcbff10 7a3f05f d152171 c4458b3 8aedd72 b7594a0 f1a15c2 115eedb ef79b91 bf24fe8 3ef6937 52c4755 8f88a28 9d87f41 421e06f 77e1a99 15e7134 3c6c240 100ab5b 1a05125 bbcdc86 a9163b5 d2
f5ed5c3 96183e0 5a898e1 11508db 002985f 25acd19 7963c30 bc821a5 22782e2 3fb493c 01ab6f9 aa508c9 37d7802 c7aea81 11558a1 72545da a2c52f1 43215de 959f857 f07cbec ab1a661 9c53e82 f3
588ac71 0a41ece c6db348 dbe0802 fca617a c40856c 23303d6 017840b a0ca3d1 23f6e51 ea2ad26 92f4cca dd55830 c017041 7ce1539 82a58ab 90176a6 c924068 bee4147 4b21dfe c11ba42 21063e5 22
5bf3294 8a09ea6 7f7480f 3cb5375 aa31a25 bfbdeea c6843e2 7d04a4b a7988fc 75b32a6 070c242 075f8b7 547199e 54250a5 52e526a f6d7a4d 201f373 8cc7463 5360014 227e1ca aeaa468 9e6e648 01
74206ae 774f596 5b1f4c5 ec017e1 5d979de e535b45 3570f3e 3568c5c ddadcc7 5de2e0d 24610c9 08fb1c4 0706bdc 5d7ad7b 22b020d 2de3646 f45714b 8e7a64d a447f76 6949d6f 0428917 6e4e95b 79
095cf91 a32eeeb 38d65b0 fb74a1b 26306f9 896475c 0489f0c 670281c af5b12c e1b1096 2ea1d68 4f37b97 91f65b7 7a48cd6 8a2cfe9 aeab739 47aebac b7c1fbc 1a0f822 314e18a 2ae84e0 c531bd6 ab
21c75e5 cae1d96 db4f421 8bbabd4 f254616 23e58a0 5457770 1a59aa5 4a643f6 25e139e e7ebd65 3025ff2 2920bd2 4e3ecec 1d5ea18 86cb0a6 4ff26f5 191ffc9 3028ca5 f3fd2b1 c55120c 6f0b012 c7
First, if you're concerned about losing any uncommitted work, save it somewhere else.
The git reflog command is a history of the changes made to the current branch head:
git reflog
will show, in reverse chronological order (newest at the top), every time the current branch head changed to a new commit id. From this list, you can choose which one you want, and use git reset --hard abc123 to reset the current branch head to that commit.
You can read more about the reflog at reflog, your safety net.
I found now a solution:
checked out the last working copy from github (here named as
backup)
compared the backup with a directory comparing tool
removed all references to the rails repository I found and set the .git/refs/head/master commit-hash to my last commit hash
And now it works again..
argh..