Saltstack gitfs - how to retrieve git commit hash? - salt-stack

Gitfs (dulwich) is configured as fileserver-backend in our saltstack with only one gitfs_remotes. I want to be able to retrieve the current git commit hash from the Gitfs when I run salt on the master so I can keep a log of which git commit is run on a minion at what time. salt.loaded.int.pillar.git_pillar seems to have that information, but not sure how I can get it from my salt python script. Appreciate your help!

There is a hash stored in /var/cache/salt/master/gitfs/remote_map.txt. Git checkout from Gitfs can be found under /var/cache/salt/master/gitfs/{hash}/.git directory. Once in that directory, git commit hash can be easily found using "git rev-parse --verify HEAD".

Related

How do I restore phabricator if I deleted the files but the database is still intact?

So, I did a stupid rm -rf on the folder where the complete phabricator folder was present.
The whole phabricator database is still intact though.
I cloned the required repos on the same old location:
somewhere/ $ git clone https://github.com/phacility/libphutil.git
somewhere/ $ git clone https://github.com/phacility/arcanist.git
somewhere/ $ git clone https://github.com/phacility/phabricator.git
Apache was already configured during previous install.
I then ran:
./bin/storage upgrade
After which I went to the address which pointed to phabricator folder. Now I get the following error:
1146: Table 'phabricator_user.user_cache' doesn't exist
How do I resolve it? Or in general, what's the best way to reinstall phabricator using the old database?
Thanks
Well, if you still have the database, make a mysqldump from the data (export the db data - you should have this by default - a cron job, running a backup script on another backup machine/usb/hard/cloud)
Do a fresh reinstall on phabricator(EVEN on whole LAMP).
Import the previous backup.sql you did.
After setting the user/passwd/host/port/ in the "path_to_phab/conf/local/local.json" via the command line or simply editing the file, try to run the
./bin/storage upgrade
This should work fine if you have the storage engine set to mysql db (not-recommended). If you have a different storage engine (like hdd) try to restore data reproducing the path to where you have data in phab`s fresh installation conf files along with mysql import.

Unix File Permissions issue with Jenkins CI and Github

I am in the process of installing Jenkins to push changes made to a Github repo to a "live" repo on my server.
I have installed Jenkins on my Ubuntu server and using its web interface I have installed the Github, Git and Github API plugins. I've also created a build task in Jenkins which runs some shell commands when Github detects that a push has been made to its repo.
The commands are running but I seem to be hitting a permissions issue. I get the following error in the Jenkins Console:
+ git pull origin master
error: cannot open .git/FETCH_HEAD: Permission denied
Build step 'Execute shell' marked build as failure
Finished: FAILURE
The parent directory for the site (and all its subdirectories) is owned by a user "james" who belongs to a group "sudo". Jenkins has its own user "jenkins" who I have since added to the group "sudo". As "jenkins" and "james" are both "sudo" members and the group has permission to write, I am unsure why this error would be occuring?
Adding a user to the group sudo does not make that user member of the same group as the one protecting the .git folder.
It just allows jenkins or james to be added to the sudoers, and executing commands (specified in said sudoers) as root.
You need to check which group is protecting .git, or if it is the root group, modify the jenkins script in order to sudo git pull origin master.
The OP James Howell confirms in the comments:
I ended up changing the group owner of the directory to "jenkins" of which the jenkins user is already a member.

Pushing files to a BitBucket repo doesn't work

I'm new to git and would like to get started using bitbucket.org as a place to create a private repository. This can then be uploaded to the staging server using a service like ftploy.com as I understand.
I am following a tutorial on WPBeginner.com to set up a staging environment for my WordPress local website which I am developing. I set up git on the mac, ran git init on the theme folder and then added all the files using git add .
After that I made a first commit using git commit -m "message here" So far the process appeared to work. No feedback in the terminal though? I then added the line
git remote add origin https://bitbucketusername#bitbucket.org/bitbucketusername/repositoryname.git
Replacing bitbucketusername with mine and repository name with mine. Attempting to push the files to the bitbucket repository resulted in this error however:
error: --all can't be combined with refspecs
usage: git push [<options>] [<repository> [<refspec>...]]
-v, --verbose be more verbose
-q, --quiet be more quiet
--repo <repository> repository
--all push all refs
--mirror mirror all refs
--delete delete refs
--tags push tags (can't be used with --all or --mirror)
-n, --dry-run dry run
--porcelain machine-readable output
-f, --force force updates
--force-with-lease[=<refname>:<expect>]
require old value of ref to be at this value
--recurse-submodules[=<check>]
control recursive pushing of submodules
--thin use thin pack
--receive-pack <receive-pack>
receive pack program
--exec <receive-pack>
receive pack program
-u, --set-upstream set upstream for git pull/status
--progress force progress reporting
--prune prune locally removed refs
--no-verify bypass pre-push hook
--follow-tags push missing but relevant tags
If you have any thoughts on why this may be the case I would appreciate it
You should provide us the command you used to do your git push, but my guess is you did something like this:
git push --all origin master
As git is telling you, this can't be used that way. Here you are asking git to push everything to origin but then you specify a branch (the <refspec>), so it is confusing.
Either push all like this:
git push --all origin
or just your master branch like this:
git push origin master

How to Upgrade and Deploy WordPress Install as a Git Submodule?

I am using a WordPress directory struture similar to Mark Jaquith's WordPress Skeleton, which has WordPress in a separate directory from the content as a submodule:
/content
/wp
/local-config.php
/wp-config.php
/index.php
I also use git and post-receive hooks to push my code changes up to my live server. It all works great except for when I try to upgrade WordPress and push that up to the live server.
This is how I setup the repo on my local machine and the remote server:
Local Machine
cd /www
git init .
git submodule add git://github.com/WordPress/WordPress.git wp
git commit -m "Add Wordpress submodule."
cd wp
git checkout 3.5
After checking out the tag, I get a warning from git about being in a 'detached HEAD' state. Since I don't plan on making any commits to WordPress, I don't think that should be an issue.
cd ..
git commit -am "Checkout Wordpress 3.5"
Remote Server
git init --bare
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/home/public git checkout -f
chmod +x hooks/post-receive
git remote add web ssh://user#server/home/private/code/wordpress.git
git push web +master:refs/heads/master
I get this error:
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://userserver/home/private/code/wordpress.git'
After some googling, it looks like I can use this command to sync up the master branch up to the server (I have no idea how this works)
git push web +master:refs/heads/master
This doesn't help me though because I don't want to track master, I want to track a release tag, 3.5. Some more googling got me to this command:
git push web +3.5~0:refs/heads/master
To upgrade the submodule, I do this:
cd wp
git fetch && git fetch --tags
git checkout 3.5.1
git push web +3.5.1~0:refs/heads/master
Am I doing this correctly? All the tutorials I see for this just have git push web and they're done. Most don't even cover upgrading the submodule. This does work but I don't feel comfortable using this weird push syntax if I don't have to.
How do I push this detached HEAD state up to the server correctly?
I've also tried this using a branch with git checkout -b mywp 3.5 but when it comes time to upgrade, I don't know how to bring in the new 3.5.1 tag into my mywp branch.
Asked this on WP Answers, but it might be more appropriate here.
On the remote server try:
git submodule update --init --recursive
This will update all your submodules recursively
You can also issue:
git fetch --tags
This will update your local tags fetching updated list from the central remote repo.

How to clone the latest stable branch to a dir via github?

I want to clone the latest stable version of WordPress from Github, via a shell script. It is simple to get the unstable master branch:
git clone git://github.com/WordPress/WordPress.git
But how can I get the highest numbered stable release via a script, not manually checking out the code. E.g., using deployment shell script or deployment tool such as Fabric.
Edit: I clarified the text to better indicate the intent that I meant how to do this from a script, not manually.
Clone from git and change to the WordPress directory
git clone git://github.com/WordPress/WordPress.git
cd WordPress
Then list out the branches..
git branch -r
This gives something like...
origin/1.5-branch
origin/2.0-branch
...
origin/3.4-branch
origin/HEAD -> origin/master
origin/master
Check out the branch you want...
git checkout 3.4-branch
Branch 3.4-branch set up to track remote branch 3.4-branch from origin.
Switched to a new branch '3.4-branch'
Here's what I actually ended up doing, which is included in a Fabric fabfile I have on Github:
git clone git://github.com/WordPress/WordPress.git .
git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
It clones the repo like normal, then does some shell magic to find the latest tagged version of WordPress (Which is where the stable branches live.)
Can you try a git checkout master ?
git branch -r will show you all the remote branches
git checkout --track <local_branch> <remote>/<remote_branch> will setup a local branch that is tracking the remote branch in order to push or get new updates.
you can use this command after git clone
git checkout stable

Resources