denshoproject / ddr-local

Web UI used for interacting with DDR collections and entities on a local machine.
Other
3 stars 0 forks source link

Git error "pathspec 'master' did not match" during collection clone #333

Open gjost opened 9 months ago

gjost commented 9 months ago

[Revised: For recent problems creating collections using the web UI see #335]

I tried cloning a new collection using ddr2 clone and got this:

(cmdln) ddr@densho101dev:/var/www/media/ddr$ ddr2 clone /var/www/media/ddr/ddr-testing-40414
Traceback (most recent call last):
  File "/opt/ddr-cmdln/venv/cmdln/bin/ddr2", line 33, in <module>
    sys.exit(load_entry_point('ddr-cmdln==5.8.1', 'console_scripts', 'ddr2')())
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/click-8.1.7-py3.9.egg/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/click-8.1.7-py3.9.egg/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/click-8.1.7-py3.9.egg/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/click-8.1.7-py3.9.egg/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/click-8.1.7-py3.9.egg/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/ddr_cmdln-5.8.1-py3.9.egg/DDR/cli/ddr.py", line 135, in clone
    exit,msg = commands.clone(
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/ddr_cmdln-5.8.1-py3.9.egg/DDR/commands.py", line 50, in wrapper
    return f(*args, **kwargs)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/ddr_cmdln-5.8.1-py3.9.egg/DDR/commands.py", line 32, in wrapper
    return f(*args, **kwargs)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/ddr_cmdln-5.8.1-py3.9.egg/DDR/commands.py", line 187, in clone
    repo.git.checkout('master')
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/git/cmd.py", line 739, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/git/cmd.py", line 1315, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/opt/ddr-cmdln/venv/cmdln/lib/python3.9/site-packages/git/cmd.py", line 1110, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git checkout master
  stderr: 'error: pathspec 'master' did not match any file(s) known to git'
GeoffFroh commented 9 months ago

Is the default first branch now called, main?

gjost commented 9 months ago

Git not prints this when you clone a repository from mits:

(cmdln) ddr@densho101dev:/var/www/media/ddr$ git clone git@mits.densho.org:ddr-testing-40415.git
Cloning into 'ddr-testing-40415'...
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty Git repository in /home/git/repositories/ddr-testing-40415.git/
warning: You appear to have cloned an empty repository.
gjost commented 9 months ago

Note that this is what you get if you use Git and not our ddr clone command.

gjost commented 9 months ago

FWIW I ran git config --global init.defaultBranch master as ddr and got the same git.exc.GitCommandError. Looks like maybe something else?

gjost commented 9 months ago

It appears that the master branch cannot be switched to until you add at least one file and do an initial commit. The ddr2 clone command fails to do this, resulting in a repo with a git-annex branch but no master.

Turns out ddr2 clone is not used in the normal workflow, so should probably be deprecated.

gjost commented 9 months ago

From research and testing it seems that you cannot switch away from a branch and come back unless there is at least one commit. For example: you clone a repo, the default master branch is created, and you immediately create and switch to a git-annex branch, but now you cannot switch back to master because there is nothing to switch back to. DDR.commands.clone does exactly this.

DDR.commands.create does the same, but it creates collection.json and others along the way, creating that first commit.

An easy fix would be to make ddr2 clone use DDR.commands.create instead of .clone.

It seems the archivists don't really use ddr2 clone so this may all be academic.

gjost commented 9 months ago

ddr2 clone is intended for cloning existing collection repositories -- it says so right in the help!

What we really need is a check on the front end that stops if a collection doesn't exist yet.

gjost commented 9 months ago

Added guardrails to ddr clone.

ddr-cmdln commit cfc6e19: DDR.commands.clone now checks with Gitolite to see if repository exists on mits; raises an Exception if it doesn't. This mirrors what DDR.commands.create already does. DDR.commands.create is modified so both functions act similarly.