Starting from:

$24.99

COMP9044 Assignment 1- girt, Girt Solution

This assignment aims to give you practice in Shell programming generally a clear concrete understanding of Git's core semantics
Your task in this assignment is to implement Girt, a subset of the version control system Git.
Git is a very complex program which has many individual commands. You will implement only a few of the most important commands. You will also be given a number of simplifying assumptions, which make your task easier.
Girt is a contraction of git restricted subset You must implement Girt in Shell.
Interestingly, early versions of Git made heavy use of Shell and Perl. Reference implementation
Many aspects of this assignment are not fully specified in this document; instead, you must match the behaviour of a reference implementation.
For example, your script girt-add should match the behaviour of 2041 girt-add exactly, including producing the same error messages.
Provision of a reference implementation is a common method to provide or define an operational specification, and it's something you will likely need to do after you leave UNSW.
Discovering and matching the reference implementation's behaviour is deliberately part of the assignment.
While the code in the reference implementation is fairly straight forward, reverse-engineering its behaviour is obviously not so simple, and is a nice example of how coming to grips with the precise semantics of an apparently obvious task can still be challenging.
Girt Commands Subset 0
Subset 0 commands must be implemented in POSIX-compatible Shell. See the Permitted Languages section for more information.
girt-init
The girt-init command creates an empty Girt repository.
girt-init should create a directory named .girt, which it will use to store the repository. It should produce an error message if this directory already exists.
You should match this, and other error messages exactly. For example:
$ ls -d .girt ls: cannot access .girt: No such file or directory
$ ./girt-init
Initialized empty girt repository in .girt
$ ls -d .girt .girt
$ ./girt-init girt-init: error: .girt already exists
You do not have to use a particular representation to store the repository.
You do not have to create the same files or directories inside .girt as the reference implementation. You can create whatever files or directories inside .girt you wish.
Do not store information outside .girt girt-add filenames...
The girt-add command adds the contents of one or more files to the “index”.
Files are added to the repository in a two step process. The first step is adding them to the index.
You will need to store files in the index somehow in the .girt sub-directory. For example, you might choose store them in a subdirectory of .girt.
Only ordinary files in the current directory can be added. You can assume filenames start with an alphanumeric character ([a-zA-Z09]) and will only contain alpha-numeric characters, plus '.', '-' and '_' characters.
The girt-add command, and other Girt commands, will not be given pathnames with slashes. girt-commit -m message
The girt-commit command saves a copy of all files in the index to the repository.
A message describing the commit must be included as part of the commit command.
Girt commits are numbered sequentially: they are not hashes, like Git. You must match the numbering scheme.
You can assume the commit message is ASCII, does not contain new-line characters, and does not start with a '-' character. girt-log
The girt-log command prints a line for every commit made to the repository: each line should contain the commit number, and the commit message.
girt-show [commit]:filename
The girt-show should print the contents of the specified filename as of the specified commit. If commit is omitted, the contents of the file in the index should be printed.
You can assume the commit if specified will be a non-negative integer.
For example:
$ ./girt-init
Initialized empty girt repository in .girt
$ echo line 1 > a
$ echo hello world >b
$ ./girt-add a b
$ ./girt-commit -m 'first commit'
Committed as commit 0
$ echo line 2 >>a
$ ./girt-add a
$ ./girt-commit -m 'second commit'
Committed as commit 1
$ ./girt-log
1 second commit
0 first commit
$ echo line 3 >>a $ ./girt-add a
$ echo line 4 >>a $ ./girt-show 0:a line 1
$ ./girt-show 1:a line 1
Subset 1
Subset 1 is more difficult. You will need spend some time understanding the semantics (meaning) of these operations, by running the reference implementation, or researching the equivalent Git operations.
Note the assessment scheme recognises this difficulty.
Subset 1 commands must be implemented in POSIX-compatible Shell. See the Permitted Languages section for more information. girt-commit [-a] -m message
girt-commit can have a -a option, which causes all files already in the index to have their contents from the current directory added to the index before the commit. girt-rm [--force] [--cached] filenames...
girt-rm removes a file from the index, or from the current directory and the index.
If the --cached option is specified, the file is removed only from the index, and not from the current directory.
The --force option overrides this, and will carry out the removal even if the user will lose work. girt-status
girt-status shows the status of files in the current directory, the index, and the repository.
$ ./girt-init
Initialized empty girt repository in .girt
$ touch a b c d e f g h
$ ./girt-add a b c d e f
$ ./girt-commit -m 'first commit'
Committed as commit 0
$ echo hello >a
$ echo hello >b
$ echo hello >c
$ ./girt-add a b
$ echo world >a
$ rm d
$ ./girt-rm e
$ ./girt-add g $ ./girt-status a - file changed, different changes staged for commit b - file changed, changes staged for commit c - file changed, changes not staged for commit d - file deleted e - deleted f - same as repo
Subset 2
Subset 2 is extremely difficult. You will need spend considerable time understanding the semantics of these operations, by running the reference implementation, and/or researching the equivalent Git operations.
Note the assessment scheme recognises this difficulty.
Subset 2 commands must be implemented in POSIX-compatible Shell. See the Permitted Languages section for more information. girt-branch [-d] [branch-name]
girt-branch either creates a branch, deletes a branch, or lists current branch names. girt-checkout branch-name
girt-checkout switches branches.
Note that, unlike Git, you can not specify a commit or a file: you can only specify a branch. girt-merge (branch-name|commit) -m message
girt-merge adds the changes that have been made to the specified branch or commit to the index, and commits them.
$ ./girt-init
Initialized empty girt repository in .girt
$ seq 1 7 >7.txt
$ ./girt-add 7.txt
$ ./girt-commit -m commit-1
Committed as commit 0 $ ./girt-branch b1
$ ./girt-checkout b1
Switched to branch 'b1'
$ perl -pi -e 's/2/42/' 7.txt
$ cat 7.txt
1
42
3
4
5
6
7
$ ./girt-commit -a -m commit-2
Committed as commit 1
$ ./girt-checkout master
If a file has been changed in both branches girt-merge produces an error message.
Note: if a file has been changed in both branches git examines which lines have been changed and combines the changes if possible. Girt doe not do this, for example:
$ ./girt-init
Initialized empty girt repository in .girt
$ seq 1 7 >7.txt
$ ./girt-add 7.txt
$ ./girt-commit -m commit-1
Committed as commit 0 $ ./girt-branch b1
$ ./girt-checkout b1
Switched to branch 'b1'
$ perl -pi -e 's/2/42/' 7.txt
$ cat 7.txt
1
42
3
4
5
6
7
$ ./girt-commit -a -m commit-2
Committed as commit 1
$ ./girt-checkout master
Diary
19/06/19 16 00 17 30 coding implemented basic commit functionality
20/06/19 20 00 10 30 debugging found bug in command-line arguments
Include these notes in the files you submit as an ASCII file named diary.txt.
Testing
Autotests
As usual, some autotests will be available:
$ 2041 autotest girt girt-* ...
You can also run only tests for a particular subset or an individual test:
$ 2041 autotest girt subset1 girt-* ...
$ 2041 autotest girt subset1_13 girt-* ...
If you are using extra Shell files, include them on the autotest command line.
Autotest and automarking will run your scripts with a current working directory different to the directory containing the script. The directory containing your submission will be in $PATH.
You will need to do most of the testing yourself.
Test Scripts
You should submit ten Shell scripts, named test00.sh to test09.sh, which run girt commands that test an aspect of Girt.
The test??.sh scripts do not have to be examples that your program implements successfully.
The test scripts should show how you've thought about testing carefully.
You are only expected to write test scripts testing parts of Girt you have attempted to implement. For example, if you have not attempted subset 2 you are not expected to write test scripts testing girt-merge .
Permitted Languages
Your programs must be written entirely in POSIX-compatible shell.
Your programs will be run with dash, in /bin/dash. You can assume anything that works with the version of /bin/dash on CSE systems is POSIX compatible.
Start your programs with:
#!/bin/dash
If you want to run these scripts on your own machine — for example, one running macOS — which has dash installed somewhere other than /bin, use:
#!/usr/bin/env dash
You are permitted to use any feature /bin/dash provides.
On CSE systems, /bin/sh is the Bash (Bourne-again shell) shell: /bin/sh is a symlink to /bin/bash. Bash implements many nonPOSIX extensions, including regular expressions and arrays. These will not work with /bin/dash, and you are not permitted to use these for the assignment.
You are not permitted to use Perl, Python or any language other than POSIX-compatible shell.
You are permitted to use only these external programs:
basename bunzip2 bzcat bzip2 cat
diff
dirname du echo egrep env expand expr false fgrep find fold getopt grep gunzip
gzip head hostname less ln ls lzcat lzma md5sum
mkdir mktemp more mv
patch
printf
pwd
readlink realpath
rev rm
rmdir sed seq sha1sum sha256sum sha512sum sleep sort stat strings
tac
tail tar tee test time top touch
tr
true
uname
unxz unzip wc wget which who
xargs xz xzcat yes zcat
uncompress unexpand uniq unlzma

Only a few of the programs in the above list are likely to be useful for the assignment.
Note you are permitted to use built-in shell features including: cd, exit, for, if, read, shift and while.
If you wish to use an external program which is not in the above list, please ask in the class forum for it to be added.
Like all good programmers, you should make as few assumptions as possible.
You can assume girt commands are always run in the same directory as the repository, and only files from that directory are added to the repository.
You can assume the directory in which girt commands are run will not contain sub-directories apart from .girt.
You can assume where a branch name is expected a string will be supplied starting with an alphanumeric character ([a-zA-Z0-9]), and only containing alphanumeric characters plus '-' and '_'. In additon a branch name will not be supplied which is entirely numeric. This allows brnach names to be distinguished from commits when merging.
You can assume where a filenames is expected a string will be supplied starting with an alphanumeric character ([a-zA-Z0-9]) and only containing alpha-numeric characters, plus '.', '-' and '_' characters.
You can assume where a commit number is expected a string will be supplied which is a non-negative integer with no leading zeros. It will not contain white space or any other charcters except digits.
You can assume that girt-add, girt-show, and girt-rm will be given just a filename, not pathnames with slashes.
You do not have to consider file permissions or other file metadata. For example, you do not have to ensure files created by a checkout command have the same permissions as when they were added.
You do not have to handle concurrency. You can assume only one instance of any girt command is running at any time.
You can assume that only the arguments described above are supplied to girt commands. You do not have to handle other arguments.
You should match the output streams used by the reference implementations. It writes error messages to stderr: so should you.
You should match the exit status used by the reference implementation. It exits with status 1 after an error: so should you.
You can assume the directory containing your scripts is in $PATH.
You can not assume the directory containing your scripts is the same as the repo.
Your scripts are always run in the directory containing the repository.
. library_functions.sh will source the shell commands in . library_functions.sh even though it is another directory, because the directory has been added to $PATH.
Note running . ./library_functions.sh will break during autotests and automarking. There can be subtle problem related to directories, ask for help in the forum.
You can assume arguments will be in the position and order shown in the usage message from the reference implementation. Other orders and positions will not be tested. For example, here is the usage message for girt-rm:
$ 2041 girt-rm
usage: girt-rm [--force] [--cached] <filenames>
So, you assume that if the --force or --cached options are present, they come before all filenames, and if they are both present the --force option will come first.
Girt error messages include the program name. It is recommended you use $0 however it also acceptable to hard-code the program name. The automarking and style marking will accept both.
Do not use the modification time of a file to determine whether it has changed. You must use the file contents. Change Log
Version 0.1 Initial release
Version 0.1 Clarified that testscripts only needed for subset attempted

Testing
When you think your program is working, you can use autotest to run some simple automated tests:
$ 2041 autotest girt
2041 autotest will not test everything. Always do your own testing.
Submission
When you are finished working on the assignment, you must submit your work by running give:
$ give cs2041 ass1_girt girt-* diary.txt test??.sh [any-other-files]
You can run give multiple times.
Only your last submission will be marked.
You can check your latest submission on CSE servers with:
$ COMP(2041|9044) classrun -check ass1_girt
You can check the files you have submitted here.
This assignment will contribute 15 marks to your final COMP(2041|9044) mark
15% of the marks for assignment 1 will come from hand-marking. These marks will be awarded on the basis of clarity, commenting, elegance and style: in other words, you will be assessed on how easy it is for a human to read and understand your program.
5% of the marks for assignment 1 will be based on the test suite you submit.
80% of the marks for assignment 1 will come from the performance of your code on a large series of tests.
HD (85+) All subsets working; code is beautiful; great test suite and diary
DN (75+) Subset 1 working; good clear code; good test suite and diary
CR (65+) Subset 0 working; good clear code; good test suite and diary
PS (55+) Subset 0 passing some tests; code is reasonably readable; reasonable test suite and diary
PS (50+) Good progress on assignment, but not passing autotests
0% knowingly providing your work to anyone and it is subsequently submitted (by anyone).
0 FL for submitting any other person's work; this includes joint work.
COMP(2041|9044)

academic submitting another person's work without their consent; misconduct paying another person to do work for you.
Intermediate Versions of Work
You are required to submit intermediate versions of your assignment.
Every time you work on the assignment and make some progress you should copy your work to your CSE account and submit it using the give command below. It is fine if intermediate versions do not compile or otherwise fail submission tests. Only the final submitted version of your assignment will be marked.
All these intermediate versions of your work will be placed in a Git repository and made available to you via a web interface at https://gitlab.cse.unsw.edu.au/z5555555/21T1-comp2041-ass1_girt (replacing z5555555 with your own zID). This will allow you to retrieve earlier versions of your code if needed.
Attribution of Work
This is an individual assignment.
The work you submit must be entirely your own work, apart from any exceptions explicitly included in the assignment specification above. Submission of work partially or completely derived from any other person or jointly written with any other person is not permitted.
Assignment submissions will be examined, both automatically and manually, for such submissions.

Change Log
For all enquiries, please email the class account at cs2041@cse.unsw.edu.au
CRICOS Provider 00098G

More products