Andr3as / Codiad-CodeGit

Git integration for Codiad
MIT License
26 stars 15 forks source link

Unable to commit #7

Closed schoeller closed 10 years ago

schoeller commented 10 years ago

Hi all,

thanks at first for this plugin to Codiad. I just started installing Codiad on shared hosting looking for an IDE which may permit to do basic web development via a git repository. I installed the plugin and verified permissions. Then I manually initiated a git repo in a folder, added a file and changed the content. The diff is accordingly to the changes made. When wanting to commit I receive the error "Failed commit!". I searched for the string and found something under the commit section. If I understand correctly the command

$git->commit(getWorkspacePath($_GET['path']), $_POST['message']);

leads to an error. The variables should be set, since I don't get errors while generating e.g. diff. So I reviewed the commit in class.git.php. Apparently a git command is being assembled there and executed. When going to the terminal within Codiad I get

git status
// On branch master
//
// Initial commit
//
// Untracked files:
//   (use "git add <file>..." to include in what will be committed)
//
//  test.txt
nothing added to commit but untracked files present (use "git add" to track)

So I do

git add test.txt

and then

git commit -m "empty"

and receive the message

// On branch master
// Changed but not updated:
//   (use "git add <file>..." to update what will be committed)
//   (use "git checkout -- <file>..." to discard changes in working directory)
//
//  modified:   test.txt
//
no changes added to commit (use "git add" and/or "git commit -a")

Any hints on what I could be doing wrong? I added the git command to Codiad via the config.php line

putenv("PATH=" .$_ENV["PATH"]. ':/usr/bin');

since it was not accessible in the standard php environment.

Best wishes

Sebastian

schoeller commented 10 years ago

When doing the same thing from phpshell (git commit ...) it works.

schoeller commented 10 years ago

I have simulated git init, git add, git commit within the terminal and it works.

Andr3as commented 10 years ago

Which user do you used to test it? CodeGit the user of php for every action, so if he has no write permission on the repo git commit will fail.

schoeller commented 10 years ago

When running terminal I get

uid=1000(web1) gid=1002(web1) groups=33(www-data),1002(web1)

I suppose it must the same user as CodeGit. The directory it is attempting to write to reads as follows:

drwx---rw- 3 1000 1002 4096 Jul 22 15:10 .
drwxr-xr-x 4 1000 1002 4096 Jul 22 01:27 ..
drwx---rw- 8 1000 1002 4096 Jul 22 15:11 .git
-rw----rw- 1 1000 1002    3 Jul 22 02:29 test.txt

or within .git

drwx---rw-  8 1000 1002 4096 Jul 22 15:11 .
drwx---rw-  3 1000 1002 4096 Jul 22 15:10 ..
-rw----rw-  1 1000 1002    4 Jul 22 15:11 COMMIT_EDITMSG
-rw----rw-  1 1000 1002   23 Jul 22 01:27 HEAD
drwx---rw-  2 1000 1002 4096 Jul 22 01:27 branches
-rw-------  1 1000 1002  156 Jul 22 15:11 config
-rw----rw-  1 1000 1002   73 Jul 22 01:27 description
drwx---rw-  2 1000 1002 4096 Jul 22 01:27 hooks
-rw----rw-  1 1000 1002  104 Jul 22 02:16 index
drwx---rw-  2 1000 1002 4096 Jul 22 01:27 info
drwx---rw-  3 1000 1002 4096 Jul 22 02:02 logs
drwx---rw- 10 1000 1002 4096 Jul 22 02:16 objects
drwx---rw-  4 1000 1002 4096 Jul 22 01:27 refs

Also there is no problem while running git init. This is something which I could not understand. I thought that all would be executed as user web1.

Andr3as commented 10 years ago

No, I guess web1(1000) is your user and web1(1002) your group. Php is executed as www-data, so it has no permissions to browse .git. My suggestion is to change the group of .git to www-data and change the permissions f.e. to 775.

Or you initiate you repo directly with CodeGit instead over a terminal. Then www-data owns .git and has all permissions by default.

schoeller commented 10 years ago

I initiate a repo with CodeGit and it gives me

drwx------ 3 1000 1002 4096 Jul 22 15:51 .
drwxr-xr-x 5 1000 1002 4096 Jul 22 15:50 ..
drwx------ 7 1000 1002 4096 Jul 22 15:51 .git

So the user/group is indeed still 1000.1002 when created. Then I add a file test.txt and check with CodeGit module on the right side. When reloading information the file is marked as untracked but also the branch information is not available. I would expect master here. Anyhow as a test I gave 777 permissions to a folder which contained a repo initialised via CodeGit and tried to commit, but all in vain.

Andr3as commented 10 years ago

Which git version do you use?

schoeller commented 10 years ago

Within Codiad-Terminal I get git version 1.7.2.5

Andr3as commented 10 years ago

Told you git who you are? If not, use the settings of CodeGit to do this.

schoeller commented 10 years ago

I simulated on a virtualbox which has the apache running as the same user who own files below workspace. After setting Username and Email I have no trouble anymore using CodeGit. I will have to contact the hoster in order to explain the problem. It must be related to permission issues as you said earlier. I suppose they have security patches in place which run io-operations different from either user web1 or www-data. I have no explanation otherwise.

A still bizarre behaviour though is that when I remove the .git directory the within CodeGit-UI I get an overview of the git further up in the file system hierarchy (see screenshot)

fireshot screen capture 035 - codiad - ide_ingenieure-ohne-grenzen_org

Andr3as commented 10 years ago

I thought that first too, that it has to be an permission issue, but I set up a new system and tried to commit a file, I got an error too. I wrote a test file to get the direct output of git and got as error this:

*\ Please tell me who you are.

Run

git config --global user.email "you@example.com" git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'http@archiso.(none)')

So I think it's easier than we thought.

schoeller commented 10 years ago

The issue is not solved so far. It works flawlessly with git version 1.7.10.4 on my virtualbox, but the hosted version is still not working with the plugin. Is it possible that the command returned are analysed and that there have been changes in output or also that the command syntax formulated is only compatible with a git version upwards? I do not have the same problems while working over the terminal.

schoeller commented 10 years ago

Trying to narrow down the problem I altered executeCommand in class.git.php to:

        private function executeCommand($cmd) {
            $cmd = escapeshellcmd($cmd);
            error_log($cmd, 0);
            exec($cmd. ' 2>&1', $array, $result);
            error_log($array, 0);
            error_log($result, 0);

this gives me in the log-file

[Wed Jul 23 23:00:33 2014] [error] [client 197.155.146.87] git config user.name "121", referer: 
[Wed Jul 23 23:00:33 2014] [error] [client 197.155.146.87] 0, referer: 
[Wed Jul 23 23:00:33 2014] [error] [client 197.155.146.87] git config user.email foo@bar.com, referer: 
[Wed Jul 23 23:00:33 2014] [error] [client 197.155.146.87] 0, referer: 
[Wed Jul 23 23:00:33 2014] [error] [client 197.155.146.87] git commit -m "1", referer:
[Wed Jul 23 23:00:33 2014] [error] [client 197.155.146.87] 1,
schoeller commented 10 years ago

Next I am setting up a function I found on the web for testing purposes

function execOutput($command) {
$output = array($command);
exec($command.' 2>&1', $output);
return implode("\n", $output);
}

echo execOutput('/usr/bin/id');
exit;

gives me

/usr/bin/id uid=1000(web1) gid=1002(web1) groups=33(www-data),1002(web1)

When executing

git commit -m "2"

I receive

git commit -m "2" sh: git: not found

and when executing

/usr/bin/git commit -m "2"

I receive

/usr/bin/git commit -m "2" # On branch master # # Initial commit # # Untracked files: # (use "git add ..." to include in what will be committed) # # test.php # test.txt nothing added to commit but untracked files present (use "git add" to track)

So the files are not tracked before commiting, which means git add is not working for some reason.

Andr3as commented 10 years ago

If git commit fails with git: not found, so will git add fail with git: not found too. Could you replace git add with /usr/bin/git add?

schoeller commented 10 years ago

As can be seen on the screenshot above the default behaviour of the installation is not correct. I try to dig into the code. As far as I understand the Staus screenshot is generated by javascript mainly. I generate two empty projects on my local install and the remote and execute the URL http://machinename/plugins/Codiad-CodeGit-master/controller.php?action=status&path=empty. I get different results in the form of:

local:

{"status":"success","data":{"branch":"master","added":[],"deleted":["LICENSE","class.git.php","controller.php","dialog.php","init.js","plugin.json","screen.css","screen.png","shell.sh","templates\/branch.html","templates\/clone.html","templates\/commit.html","templates\/diff.html","templates\/log.html","templates\/login.html","templates\/newBranch.html","templates\/newRemote.html","templates\/overview.html","templates\/push.html","templates\/remote.html","templates\/renameRemote.html","templates\/settings.html","test.txt"],"modified":[".gitignore","README.md","config.php"],"renamed":[],"untracked":["1","1c","34","4a","4b","5c","5d","8a","8c","AUTHORS.txt","CONTRIBUTING.md","CodeGit","Codiad-CodeGit-master","Codiad-Terminal-master","Codiad-ToDo-master","INSTALL.txt","LICENSE.txt","ace-editor","active","autocomplete","branches","cache","common.php","components\/","composer.json","config","config.example.php","css","d8","default","e6","editor","ee","emulator","f5","favicon.ico","fb","fileext_textmode","filemanager","finder","fonts","heads","hooks","images","index.php","info","install","js\/","keybindings","languages\/","lib\/","logs","market","objects","pack","plugins\/","poller","project","refs","repo","style_guide.php","tags","templates","test","themes\/","update","upload_scripts","user","worker_manager"]}}

remote:

{"status":"success","data":{"branch":"","added":[],"deleted":[],"modified":[".gitignore","AUTHORS.txt","CONTRIBUTING.md","INSTALL.txt","LICENSE.txt","README.md","components\/active\/controller.php","components\/active\/dialog.php","components\/active\/init.js","components\/autocomplete\/init.js","components\/editor\/ace-editor\/ace.js","components\/editor\/ace-editor\/ext-static_highlight.js","components\/editor\/ace-editor\/ext-textarea.js","components\/editor\/ace-editor\/keybinding-emacs.js","components\/editor\/ace-editor\/keybinding-vim.js","components\/editor\/ace-editor\/mode-asciidoc.js","components\/editor\/ace-editor\/mode-c9search.js","components\/editor\/ace-editor\/mode-c_cpp.js","components\/editor\/ace-editor\/mode-clojure.js","components\/editor\/ace-editor\/mode-coffee.js","components\/editor\/ace-editor\/mode-coldfusion.js","components\/editor\/ace-editor\/mode-csharp.js","components\/editor\/ace-editor\/mode-css.js","components\/editor\/ace-editor\/mode-diff.js","components\/editor\/ace-editor\/mode-glsl.js","components\/editor\/ace-editor\/mode-golang.js","components\/editor\/ace-editor\/mode-groovy.js","components\/editor\/ace-editor\/mode-haxe.js","components\/editor\/ace-editor\/mode-html.js","components\/editor\/ace-editor\/mode-jade.js","components\/editor\/ace-editor\/mode-java.js","components\/editor\/ace-editor\/mode-javascript.js","components\/editor\/ace-editor\/mode-json.js","components\/editor\/ace-editor\/mode-jsp.js","components\/editor\/ace-editor\/mode-jsx.js","components\/editor\/ace-editor\/mode-latex.js","components\/editor\/ace-editor\/mode-less.js","components\/editor\/ace-editor\/mode-liquid.js","components\/editor\/ace-editor\/mode-lua.js","components\/editor\/ace-editor\/mode-luapage.js","components\/editor\/ace-editor\/mode-markdown.js","components\/editor\/ace-editor\/mode-ocaml.js","components\/editor\/ace-editor\/mode-perl.js","components\/editor\/ace-editor\/mode-pgsql.js","components\/editor\/ace-editor\/mode-php.js","components\/editor\/ace-editor\/mode-powershell.js","components\/editor\/ace-editor\/mode-python.js","components\/editor\/ace-editor\/mode-ruby.js","components\/editor\/ace-editor\/mode-scad.js","components\/editor\/ace-editor\/mode-scala.js","components\/editor\/ace-editor\/mode-scss.js","components\/editor\/ace-editor\/mode-sh.js","components\/editor\/ace-editor\/mode-sql.js","components\/editor\/ace-editor\/mode-svg.js","components\/editor\/ace-editor\/mode-tcl.js","components\/editor\/ace-editor\/mode-text.js","components\/editor\/ace-editor\/mode-textile.js","components\/editor\/ace-editor\/mode-typescript.js","components\/editor\/ace-editor\/mode-xml.js","components\/editor\/ace-editor\/mode-xquery.js","components\/editor\/ace-editor\/mode-yaml.js","components\/editor\/ace-editor\/theme-ambiance.js","components\/editor\/ace-editor\/theme-chrome.js","components\/editor\/ace-editor\/theme-clouds.js","components\/editor\/ace-editor\/theme-clouds_midnight.js","components\/editor\/ace-editor\/theme-cobalt.js","components\/editor\/ace-editor\/theme-crimson_editor.js","components\/editor\/ace-editor\/theme-dawn.js","components\/editor\/ace-editor\/theme-dreamweaver.js","components\/editor\/ace-editor\/theme-eclipse.js","components\/editor\/ace-editor\/theme-github.js","components\/editor\/ace-editor\/theme-idle_fingers.js","components\/editor\/ace-editor\/theme-kr.js","components\/editor\/ace-editor\/theme-merbivore.js","components\/editor\/ace-editor\/theme-merbivore_soft.js","components\/editor\/ace-editor\/theme-mono_industrial.js","components\/editor\/ace-editor\/theme-monokai.js","components\/editor\/ace-editor\/theme-pastel_on_dark.js","components\/editor\/ace-editor\/theme-solarized_dark.js","components\/editor\/ace-editor\/theme-solarized_light.js","components\/editor\/ace-editor\/theme-textmate.js","components\/editor\/ace-editor\/theme-tomorrow.js","components\/editor\/ace-editor\/theme-tomorrow_night.js","components\/editor\/ace-editor\/theme-tomorrow_night_blue.js","components\/editor\/ace-editor\/theme-tomorrow_night_bright.js","components\/editor\/ace-editor\/theme-tomorrow_night_eighties.js","components\/editor\/ace-editor\/theme-twilight.js","components\/editor\/ace-editor\/theme-vibrant_ink.js","components\/editor\/ace-editor\/theme-xcode.js","components\/editor\/ace-editor\/worker-coffee.js","components\/editor\/ace-editor\/worker-css.js","components\/editor\/ace-editor\/worker-javascript.js","components\/editor\/ace-editor\/worker-json.js","components\/editor\/ace-editor\/worker-xquery.js","components\/editor\/dialog.php","components\/editor\/init.js","components\/filemanager\/class.filemanager.php","components\/filemanager\/context_menu.json","components\/filemanager\/controller.php","components\/filemanager\/dialog.php","components\/filemanager\/dialog_upload.php","components\/filemanager\/download.php","components\/filemanager\/init.js","components\/filemanager\/upload_scripts\/jquery.fileupload.js","components\/filemanager\/upload_scripts\/jquery.iframe-transport.js","components\/filemanager\/upload_scripts\/jquery.ui.widget.js","components\/keybindings\/init.js","components\/poller\/init.js","components\/project\/class.project.php","components\/project\/controller.php","components\/project\/dialog.php","components\/project\/init.js","components\/right_bar.json","components\/update\/init.js","components\/user\/class.user.php","components\/user\/controller.php","components\/user\/dialog.php","components\/user\/init.js","favicon.ico","index.php","js\/jquery-1.7.2.min.js","js\/jquery-ui-1.8.23.custom.min.js","js\/jquery.css3.min.js","js\/jquery.easing.js","js\/jquery.hoverIntent.min.js","js\/jsend.js","js\/localstorage.js","js\/message.js","js\/modal.js","js\/sidebars.js","js\/system.js","languages\/cn.php","style_guide.php","workspace\/README"],"renamed":[],"untracked":[".htaccess"]}}

Obviously the path used is different between local and remote install. I will have to find out why. I sounds though like a configuration issue.

Andr3as commented 10 years ago

Your path argument (path=empty) is wrong. It has to be either a relative path from /workspace to your git repo in your project or an absolute path to your git repo in your project.

Another question: Is your git repo in the repo folder or in a subfolder (refering your screenshot)? You call CodeGit over the right sidebar? Could you call it next time over the context menu of the folder which contains your git repo?

schoeller commented 10 years ago

I tried to follow up on the javascript code in init.js, but I am unfortunately not capable of.

Concerning your first point. The path = repo is called empty, since it is an empty folder within workspace/.

Referring to your second point repo has been generated by

  1. creating a project called repo
  2. adding a file called test.txt amonst other
  3. opening CodeGit status dialog from the right panel

Then I effectively see the git repo from the installation root as may be seen in the screenshot above. Then I continue as follows

  1. initialise git repo via right-click over the project folder on the left and calling Git init.
  2. calling rescan via right click over the project folder
  3. opening CodeGit status dialog from the right panel

Then I see the following screenshot from right panel and left panel being identical:

fireshot screen capture 036 - codiad - ide_ingenieure-ohne-grenzen_org

  1. When deleting the .git folder and rescanning I get the same screenshot as posted 2 days ago

My hoster takes his time getting back to me. I checked the environmental variables from web server environment from a php-script via

print "getenv is: ".getenv("PATH")."<br/>";
print "env is: ".$_ENV["PATH"]."<br/>";
putenv("PATH=" .$_ENV["PATH"]. ':/usr/bin');
$_ENV["PATH"]=$_ENV["PATH"] . ':/usr/bin';
print "getenv is: ".getenv("PATH")."<br/>";
print "env is: ".$_ENV["PATH"]."<br/>";
phpinfo(INFO_ENVIRONMENT);

So the installation should have /usr/bin/git available, since I added

putenv("PATH=" .$_ENV["PATH"]. ':/usr/bin');
$_ENV["PATH"]=$_ENV["PATH"] . ':/usr/bin';

to the config.php file. I can execute it from Codiad's terminal normally. I have checked for file permissions which seem to be ok. As a prove I see that git init works from CodeGit interface but git commit does not. I will ask my hoster to upgrade the git installation.

schoeller commented 10 years ago

My hoster has no updated git to version 1.7.10.4. Now the behaviour has changed slightly. On the command line I am able to do the usual git init/add/commit. When trying that from the CodeGit UI the step add/commit fails still. When adding though a file by hand via git add I am able to commit successfully via the CodeGit UI. When I modify the file once more and try to commit it fails again. When I do again add the file manually via git add I can again commit via the CodeGit UI. Could this be related to behavioural changes from the git command?

Andr3as commented 10 years ago

I use git version 1.7.10.4 too, and have no problems.

Did you added your code to the config.php of Codiad or the config.php of CodeGit?

schoeller commented 10 years ago

config.php of Codiad in order to be able to reach git for the default installation

Andr3as commented 10 years ago

Could you add your code to the config.php of CodeGit too and retest it?

Andr3as commented 10 years ago

Closed due inactivity