Question 3: Bash/Perl scripting [10]

(i) Write either a bash script (git-create.sh) or a perl script (git-create.pl) that allows the user to set up a new git repository as follows:
  1. The user supplies the script with command line arguments for the name of the new repository they wish to create and the (existing) directory in which they wish to create it.
  2. The script then follows this sequence:
    1. it issues a 'cd' command into the existing directory, exiting if it cannot do so
    2. it creates a directory for the repository, exiting if it cannot do so
    3. it issues a 'cd' command into the repository directory, exiting if it cannot do so
    4. it runs the git command to initialize the new repository, exiting if it cannot do so
    5. it displays a message indicating the creation has been completed successfully

(ii) Write either a bash script (git-copyN.sh) or a perl script (git-copyN.pl) that allows the user to obtain copies of all files changed in the last N commits to a git repository as follows:

  1. The user is expected to be in the git repository when they run the script, and must provide the script with command line arguments specifying the value for N (the number of commits) and the directory they wish to copy the changed files to.
  2. The user supplies, as command line arguments, the number of commits they want considered and the directory in which to place the copied files, e.g.
    git-copyN.sh 5 changeCollection
  3. The script makes use of the following git command to obtain a list of changed files:
    git diff-tree master~N master --name-only -r
    where N should be the appropriate command line argument
  4. Using the list obtained above, the script copies each file in the list to the target directory, exiting if it cannot
  5. The script then displays a message to indicate the copying is completed