make: my own simple repository

1

I have got an account on a server at my university. I want to share a program code with another student. I thought I should put it on my github account. Unfortunately, I cannot because the code is part of a contest.

I decided to make a Makefile so that we could easily upload and download files. After a while I finally understood that is not enough. Then I implemented patch system so that only changes are stored. There should be no problem with small simultaneous changes.

The Makefile almost do the job but there are some details I can't solve. The Makefile

all: download
PHONY: all, download, upload, getFiles

.ONESHELL:
getFiles:
    rm ../.tmp -r
    mkdir ../.tmp
    @(ssh $(user)@host "tar c *") | tar xv -C ../.tmp 

download: getFiles
    @diff -u ../.tmp . | patch -p1
    rm ../.tmp -r

upload: getFiles
    @diff -uN ../.tmp . | (ssh $(user)@host "patch -p1")
    rm ../.tmp -r

I removed all data from host. Now I want to upload but tar stops program because there are no files to download in order to find out changes.

Moreover, I cannot make my mind in the case: should I use -N in diff or not? Simply, I do not know how it behaves when I delete a file.

There is another problem: when something goes wrong the .tmp directory is not removed. The directory should be removed every time. Next action always download current "repository" status.

I fully recognize the fact it is not a repository, but I cannot set up a server program on the remote host and I think the Makefile will do the job for me.

Any hints will be appreciated.

lord.didger

Posted 2011-12-09T19:11:40.477

Reputation: 153

Have you considered sending patches by email? – Daniel Beck – 2011-12-09T19:27:24.840

No. I think using makefile is much more convenient. – lord.didger – 2011-12-09T19:50:40.383

@lord.didger: Daniel meant "have you considered using git-format-patch / git-send-mail" ... and that in combination with commit-hooks. – akira – 2011-12-09T19:54:59.000

1Why not using a Git repository over SSH? – cYrus – 2011-12-09T19:57:21.237

1git over email? that would be the best option. Unfortunately, I have very basic knowledge of git. Getting know how to fire git over email will take some time. @cYrus: Git over ssh? what you mean? – lord.didger – 2011-12-09T20:02:07.410

@lord.didger: Server side: git init --bare project.git; client side: git clone ssh://you@your_host:project.git. – cYrus – 2011-12-09T20:06:48.597

Git over email is indeed possible; http://book.git-scm.com/5_git_and_email.html. Git was built with that in mind. However Git over SSH really is a good idea http://fclose.com/b/linux/366/set-up-git-server-through-ssh-connection/. Also, peek at this: http://book.git-scm.com/3_distributed_workflows.html

– Tyler Szabo – 2011-12-09T20:07:10.803

Nice. I will surely try it but not now. Now I have no time - have to write some code. Checkout my question :) – lord.didger – 2011-12-09T20:14:09.587

Answers

1

I have finally managed to fix the Makefile. I think it works fine. Obviously it is not a professional repository but it does the job. The Makefile:

-include name

all: download
PHONY: all, download, upload, getFiles

DIFFFLAGS = -uNr

.ONESHELL:
getFiles:
    rm .tmp -r
    mkdir .tmp
    (ssh $(user)@$(HOST) "tar c ") | tar xv -C .tmp

download: getFiles
        diff $(DIFFFLAGS) program .tmp/roboty | patch -p1 -d program

upload: getFiles
    diff $(DIFFFLAGS) .tmp/roboty program | (ssh $(user)@$(HOST) "umask 070 && patch -p1")

patch-extern:
    diff $(DIFFFLAGS) program program-workplace | patch -p1 -d program

patch-local:
    diff $(DIFFFLAGS) program program-workplace | patch -p1 -dR program-workplace

backup:
    tar cf backup.tar program-workplace

.ONESHELL:
clear:
    rm `find program-workplace/ -name "*~"`
    rm `find program-workplace/ -name "*.class"`

lord.didger

Posted 2011-12-09T19:11:40.477

Reputation: 153