Skip to content

Commit

Permalink
If there is just one repository, always use it as defaultRepository
Browse files Browse the repository at this point in the history
Beyond making "branches" and filter part of "home" pages more convenient to
use for newly setup single repository Critic instances, this also makes
behavior consistent with what "Config" displays for such an instance.
Although the user had no preference recorded for a newly installed
instance, the "Config" page was populating the defaultRepository dropdown
with a single item representing the only existing repository so for the
user it looked like they had the "Config" properly setup. Just hitting
"Save" without changing anything did indeed set the only repository as
defaultRepository, but such a click should not be necessary ofc.
  • Loading branch information
mo committed Nov 25, 2012
1 parent 4f935e7 commit 6956b10
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dbutils.py
Expand Up @@ -249,7 +249,17 @@ def setPreference(self, db, item, value):
cursor.execute("INSERT INTO userpreferences (uid, item, string) VALUES (%s, %s, %s)", [self.id, item, str(value)])

def getDefaultRepository(self, db):
return gitutils.Repository.fromName(db, self.getPreference(db, "defaultRepository"))
default_repo = self.getPreference(db, "defaultRepository")
if not default_repo:
cursor = db.cursor()
cursor.execute("SELECT COUNT(*) FROM repositories")

repo_count = cursor.fetchone()[0]
if repo_count == 1:
cursor.execute("SELECT name FROM repositories")
default_repo = cursor.fetchone()[0]

return gitutils.Repository.fromName(db, default_repo)

def getResource(self, db, name):
if name in self.__resources:
Expand Down

0 comments on commit 6956b10

Please sign in to comment.