Codea-SCM: basic source control for your projects

@Briarfox, sorry didn’t mean to ignore your post - I’ve been trying to restore my iPad the last couple of days, which suffered a botched backup/restore job. (Not fun)

Nice idea with CodeaProjects - I’ll comment in your new thread.

Just a quick note to say that I upgraded Codea-scm-app by having the it pull the latest version from BitBucket, as suggested by @juce and @joelhoro , and it went very smoothly! Now that I’ve got the app watching its own source, future upgrades will just be a matter of pressing “pull”. In case I haven’t already made it clear, I am very impressed with Codea SCM!

@yojimbo2000, thanks. Always nice to know that people find your software useful.

I made a small update today. Just a couple days ago i discovered a cool little feature in Codea - “Set Icon” button - where you can make a screenshot and then assign it as an icon to your project. Very neat and simple. Internally, this is stored as Icon.png.

So i added support for project icon to Codea-SCM. If you have codea-scm app source controlling itself, it shoud be just a simple pull to update.

This is very impressive and very meta also. Just coding my first app and was manually copying it using the aircode or dropbox export. This is the easiest way to do version control.

A very useful software for version control in Codea!

But I have a problem in using it, when I use https://codea-scm.aws.mapote.com as web service server, it is ok. When I use my host(install the code-scm web service on a debian system) as web service server, it always response:“commit error = [[ *** Please tell me who you are. run git config --global user.email… to set your account`s default identity. Omit --glo …”.

I try to modify the code in code-scm/app, but it does not work, code like bellow:

-- add two command function in /codea-scm/app/git.lua  
function git.config_email(remote, u, wd)
    local pdir = wd or dir_for_remote(u.username, remote)
    local cmd = string.format(
        "cd '%s/%s' && git config  --global user.email 'hifreeblues@hotmail.com'", config.work_home, pdir)
    local code, out, err = shell.execute(cmd)
    return code, (out ~= "" and out or nil), err
end

function git.config_name(remote, u, wd)
    local pdir = wd or dir_for_remote(u.username, remote)
    local cmd = string.format(
        "cd '%s/%s' && git config --global user.name 'HexFire'", config.work_home, pdir)
    local code, out, err = shell.execute(cmd)
    return code, (out ~= "" and out or nil), err
end

-- call these two command in /codea-scm/app/commit_and_push.lua
function post()
    local fmt = string.match(ngx.var.uri, '.*[.](%w+)$')

    -- get request body
    ngx.req.read_body()
    local body_data = ngx.req.get_body_data()
    if body_data == nil then
        local filename = ngx.req.get_body_file()
        if filename then
            local inf = io.open(filename)
            body_data = inf:read('*all')
            inf:close()
            util.debug(config.debug and "read from file")
        else
            util.json_error(500, "PROBLEM! did not receive image data")
        end
    else
        util.debug(config.debug and "read from memory")
    end
    util.debug(config.debug and "body data len: " .. #(tostring(body_data)))

    -- verify correctness of body 
    local doc = (fmt == 'lua') and serializer.decode(body_data) or cjson.decode(body_data)
    local remote = doc.remote
    local tabs, plist, icon, comment = doc.tabs, doc.plist, doc.icon, doc.comment

    if not remote or not tabs then
        util.json_error(400, "You must specify remote and tabs")
    end

    -- get user details and authenticate the user
    local u,err,code = user.get_user()
    if not u then
        util.json_error(code or 500, string.format(
            "User-check ERROR. Details: %s", err))
    end

    -- prep files table
    local files = { ["Info.plist"] = plist, ["Icon.png"] = util.hexDecode(icon) }
    for tab_name, tab_content in pairs(tabs) do
        files[string.format('tabs/%s.lua', tab_name)] = tab_content
    end

    u.pk = doc.pk
    git.session(util.new_uuid(),
        function(wd)
            -- clone repo and
            git.clone_and_checkout(remote, u, "master", wd)

            -- replace files in work directory
            git.replace_files(remote, u, files, wd)

            -- config
            git.config_email(remote, u, wd)
            git.config_name(remote, u, wd)

            -- commit and push
            comment = comment or string.format('checkpoint commit on behalf of %s', u.name or u.username)
            local t = git.commit_and_push(remote, u, comment, wd)

            if fmt == 'lua' then
                ngx.header.content_type = 'text/plain'
                ngx.print(serializer.encode(t))
            else
                ngx.header.content_type = 'application/json'
                ngx.print(cjson.encode(t))
            end
        end,
        function(err)
            util.json_error(500, "PROBLEM: " .. tostring(err))
        end)
end

@binaryblues have you tried direct messaging @juce ?

@yojimbo2000 Thanks for your suggestion, I will do that.

@juce Can you give some advices about how to modify the code? thanks.

I mean by using the inbox link at the top of the page (in case you haven’t used that yet). It depends on how people have their membership set up of course, but the default seems to be that if you are DMed, you get an email notification, so it can be useful if someone’s been away from the board for a while.

@yojimbo2000 Thank you? I have sent a message to @juce

@binaryblues, i believe this happens because of git’s distinction between “author” and “committer”. Perhaps, you have a newer git version that is more strict about this, than the one i have installed on my codea-scm server.

In any case, i just pushed a change that should fix this. See here:

https://bitbucket.org/juce/codea-scm/commits/bf9d7c448acc24098

So, if you take the latest source (or just incorporate this change) - it should solve the problem. Let me know if it works for you.

And i should add: thanks for finding this issue! :slight_smile:

@juce It is OK now! I can use the local git repo! Thanks a lot!

On my local host, two files need to be modified, Because the user nobody can not write to the repo, I use the user git nor nobody, so there is a directory for git : /home/git/

1 Add a file ssh_config In /home/git/.ssh/, the content is:

	StrictHostKeyChecking no

2 Modify /home/git/.gitconfig, append 2 lines:

[receive]
	DenyCurrentBranch = ignore

Now, we can use Codea-SCM on both local host repo and internet repo! Enjoy it!

I was wondering if there was a way to also commit your assists up to GitHub?
For a project, you can add an asset right into the project, and not in your Documents or DropBox folder. I can see them in the directory with all my Lua files.

How could I get them pushed up to and pulled down from GitHub with this?
Thanks

@MrCoxall you might want to look at an app called Working Copy, it’s a full iOS git client with excellent built-in support for BitBucket and GitHub. When Codea 2.3.2 eventually comes out (Apple always give code executing apps like Codea a super-long review, so hard to say when it will drop), it will have a very nice zipped project export option. This puts the Lua files, app icon, info.plist and assets in the project folder into a single zip file for export. This works very well with Working Copy, which has excellent support for zip folders. You can choose to unzip the folder as a new repository, or unzip it as a folder in an existing repository (I recommend the latter option). From there, you can commit changes, and push to whatever remote you like. You can even use this method to update the repo, pushing new changes to it (with one caveat: if you rename a tab, or delete a tab, the old tab will persist in the repo, and you have to delete the file by hand. Not that big a deal). I highly recommend Working Copy for anyone developing even slightly complex projects on iOS.

I assume the “Open In” functionality that is in Textastic is not going to be built into the new Codea update. I watch the following video and it looks like a really smooth process.
https://www.youtube.com/watch?v=RB1Blvi7K9I

Codea does already have the Open In dialogue, for Xcode project export, and soon for the zipped project export I mentioned above. And the Working Copy panel that opens in Codea allows you to choose the repository or create a new one, so you can do a lot without leaving Codea. Actually, if you’re impatient for 2.3.2 and want a preview of the zipped project export, you could do an Xcode export, and then delete all of the files (runtime etc) except for the .codea project folder and the assets folders (don’t delete anything though if you are eventually heading for Xcode, in which case this is a great way to start the Xcode repo). The only difference is that assets will be in an assets folder instead of in the .codea folder.

We’ve been using codea-scm and we love it !
Right now, the https://codea-scm.aws.mapote.com/ seems down, so we can not submit our code to bitbucket …

Should be working again. (Unplanned server reboot was to blame)

Is the Codea-SCM server down again?
The code is not working for me and I can’t even get to the website.
(https://codea-scm.aws.mapote.com)

Anyone else having this problem?

My hoster rebooted the server again. Sorry about the disruption, everything should be back to normal now.

I have now added the boot-time script that starts the service automatically when the machine is rebooted, so there should be no more long outages. ( Tested it with a couple of reboots - it seems to work well )

Just managed a commit to github via your scm! How may I support this project? Thanks!

R